From e6df6dc808314bac332368675c87af97313fef91 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 19 Aug 2015 19:54:24 +0200 Subject: GenericResourceBenchmark Will eventually replace most parts of DummyResourceBenchmark --- tests/CMakeLists.txt | 1 + tests/genericresourcebenchmark.cpp | 151 +++++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 tests/genericresourcebenchmark.cpp (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 542b4ed..1c75e96 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -30,6 +30,7 @@ endmacro(auto_tests) manual_tests ( storagebenchmark dummyresourcebenchmark + genericresourcebenchmark ) auto_tests ( diff --git a/tests/genericresourcebenchmark.cpp b/tests/genericresourcebenchmark.cpp new file mode 100644 index 0000000..01dc95d --- /dev/null +++ b/tests/genericresourcebenchmark.cpp @@ -0,0 +1,151 @@ +#include + +#include + +#include "event_generated.h" +#include "entity_generated.h" +#include "metadata_generated.h" +#include "createentity_generated.h" +#include "commands.h" +#include "entitybuffer.h" +#include "pipeline.h" +#include "genericresource.h" +#include "definitions.h" +#include "domainadaptor.h" +#include + +class TestResource : public Akonadi2::GenericResource +{ +public: + TestResource(const QByteArray &instanceIdentifier, QSharedPointer pipeline) + : Akonadi2::GenericResource(instanceIdentifier, pipeline) + { + } + + KAsync::Job synchronizeWithSource() Q_DECL_OVERRIDE + { + return KAsync::null(); + } +}; + +class TestEventAdaptorFactory : public DomainTypeAdaptorFactory +{ +public: + TestEventAdaptorFactory() + : DomainTypeAdaptorFactory() + { + } + + virtual ~TestEventAdaptorFactory() {}; +}; + + +static void removeFromDisk(const QString &name) +{ + Akonadi2::Storage store(Akonadi2::storageLocation(), name, Akonadi2::Storage::ReadWrite); + store.removeFromDisk(); +} + +static QByteArray createEntityBuffer() +{ + flatbuffers::FlatBufferBuilder eventFbb; + eventFbb.Clear(); + { + auto summary = eventFbb.CreateString("summary"); + Akonadi2::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); + eventBuilder.add_summary(summary); + auto eventLocation = eventBuilder.Finish(); + Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); + } + + flatbuffers::FlatBufferBuilder localFbb; + { + auto uid = localFbb.CreateString("testuid"); + auto localBuilder = Akonadi2::ApplicationDomain::Buffer::EventBuilder(localFbb); + localBuilder.add_uid(uid); + auto location = localBuilder.Finish(); + Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); + } + + flatbuffers::FlatBufferBuilder entityFbb; + Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); + + flatbuffers::FlatBufferBuilder fbb; + auto type = fbb.CreateString(Akonadi2::ApplicationDomain::getTypeName().toStdString().data()); + auto delta = fbb.CreateVector(entityFbb.GetBufferPointer(), entityFbb.GetSize()); + Akonadi2::Commands::CreateEntityBuilder builder(fbb); + builder.add_domainType(type); + builder.add_delta(delta); + auto location = builder.Finish(); + Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); + + return QByteArray(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize()); +} + +class GenericResourceBenchmark : public QObject +{ + Q_OBJECT +private Q_SLOTS: + + void init() + { + removeFromDisk("org.kde.test.instance1"); + removeFromDisk("org.kde.test.instance1.userqueue"); + removeFromDisk("org.kde.test.instance1.synchronizerqueue"); + Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Warning); + qDebug(); + qDebug() << "-----------------------------------------"; + qDebug(); + } + + + void testWriteInProcess() + { + int num = 50000; + + auto pipeline = QSharedPointer::create("org.kde.test.instance1"); + TestResource resource("org.kde.test.instance1", pipeline); + + auto command = createEntityBuffer(); + + QTime time; + time.start(); + + for (int i = 0; i < num; i++) { + resource.processCommand(Akonadi2::Commands::CreateEntityCommand, command); + } + auto appendTime = time.elapsed(); + + //Wait until all messages have been processed + resource.processAllMessages().exec().waitForFinished(); + + auto allProcessedTime = time.elapsed(); + + std::cout << "Append to messagequeue " << appendTime << " /sec " << num*1000/appendTime << std::endl; + std::cout << "All processed: " << allProcessedTime << " /sec " << num*1000/allProcessedTime << std::endl; + } + + void testCreateCommand() + { + Akonadi2::ApplicationDomain::Event event; + + QBENCHMARK { + auto mFactory = new TestEventAdaptorFactory; + static flatbuffers::FlatBufferBuilder entityFbb; + entityFbb.Clear(); + mFactory->createBuffer(event, entityFbb); + + static flatbuffers::FlatBufferBuilder fbb; + fbb.Clear(); + //This is the resource buffer type and not the domain type + auto type = fbb.CreateString("event"); + // auto delta = fbb.CreateVector(entityFbb.GetBufferPointer(), entityFbb.GetSize()); + auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); + auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta); + Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); + } + } +}; + +QTEST_MAIN(GenericResourceBenchmark) +#include "genericresourcebenchmark.moc" -- cgit v1.2.3