Debian Codegraph @

Source/Test/CConcurrentThroughputTestTaskTester.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "CConcurrentThroughputTestTaskTester.h"
22
23
24 namespace Konclude {
25
26 namespace Test {
27
28
29
30 CConcurrentThroughputTestTaskTester::CConcurrentThroughputTestTaskTester() {
31 mHandleAlg = new CThroughputTestTaskHandleAlgorithm();
32 }
33
34
35 CConcurrentThroughputTestTaskTester::~CConcurrentThroughputTestTaskTester() {
36 }
37
38
39 void CConcurrentThroughputTestTaskTester::generateTestingStructure(cint64 maxBranchDepth, cint64 branchingFactor) {
40 mMaxBranchDepth = maxBranchDepth;
41 mBranchingFactor = branchingFactor;
42 mThreadTestCount = 1;
43 mThreadMaxTestCount = 8;
44 mScaleReferenceTime = 0;
45 mLastEventProcessed = 0;
46 mLastTaskProcessed = 0;
47 mTotalTestTasks = qPow(mBranchingFactor,mMaxBranchDepth+1);
48 mProcessUnit = new CSingleThreadTaskProcessorUnit(mHandleAlg);
49 mProcessUnit->startProcessing();
50 mCompletorUnit = new CTaskProcessorCompletorThread(mHandleAlg);
51 mSchedulerUnit = new CTaskProcessorSchedulerThread(mHandleAlg,mCompletorUnit);
52 mCompletorUnit->installScheduler(mSchedulerUnit);
53 mSchedulerUnit->installScheduler(mSchedulerUnit);
54 mCompletorUnit->startProcessing();
55 mSchedulerUnit->startProcessing();
56 }
57
58 void CConcurrentThroughputTestTaskTester::startTesting() {
59 CThroughputTestTask* rootTask = CObjectMemoryPoolAllocator<CThroughputTestTask>::allocateAndConstructWithMemroyPool();
60 rootTask->initTestTask(mMaxBranchDepth,mBranchingFactor);
61 rootTask->addCallbackLinker(this);
62 mMeasurementTimer.start();
63 CTaskEventCommunicator::postSendTaskScheduleEvent(mProcessUnit->getEventHandler(),rootTask,nullptr);
64 }
65
66 void CConcurrentThroughputTestTaskTester::stopTesting() {
67 }
68
69 void CConcurrentThroughputTestTaskTester::destroyTestingStructure() {
70 mProcessUnit->stopProcessing();
71 mProcessUnit->stopThread();
72 delete mProcessUnit;
73 }
74
75
76 cint64 CConcurrentThroughputTestTaskTester::getTaskProcessedCount() {
77 cint64 totalProcessedCount = mProcessUnit->getTaskProcessingStatistics()->getStatisticTasksProcessedCount();
78 return totalProcessedCount;
79 }
80
81
82
83 void CConcurrentThroughputTestTaskTester::doCallback() {
84 cint64 elapsedTime = mMeasurementTimer.elapsed();
85 if (mThreadTestCount == 1) {
86 mScaleReferenceTime = elapsedTime;
87 }
88 if (mScaleReferenceTime == 0) {
89 mScaleReferenceTime = 1;
90 }
91 cint64 eventProcessedCount = 0;
92 cint64 taskProcessedCount = 0;
93 if (mThreadTestCount == 1) {
94 eventProcessedCount += mProcessUnit->getTaskProcessingStatistics()->getStatisticEventsProcessedCount();
95 taskProcessedCount += mProcessUnit->getTaskProcessingStatistics()->getStatisticTasksProcessedCount();
96 } else {
97 eventProcessedCount += mSchedulerUnit->getTaskProcessingStatistics()->getStatisticEventsProcessedCount();
98 eventProcessedCount += mCompletorUnit->getTaskProcessingStatistics()->getStatisticEventsProcessedCount();
99 taskProcessedCount += mSchedulerUnit->getTaskProcessingStatistics()->getStatisticTasksProcessedCount();
100 taskProcessedCount += mCompletorUnit->getTaskProcessingStatistics()->getStatisticTasksProcessedCount();
101 foreach (CTaskProcessorThread* taskProcUnit, mProcessorUnitList) {
102 eventProcessedCount += taskProcUnit->getTaskProcessingStatistics()->getStatisticEventsProcessedCount();
103 taskProcessedCount += taskProcUnit->getTaskProcessingStatistics()->getStatisticTasksProcessedCount();
104 }
105 cint64 tmpEventProcessedCount = eventProcessedCount;
106 eventProcessedCount = tmpEventProcessedCount - mLastEventProcessed;
107 mLastEventProcessed = tmpEventProcessedCount;
108 cint64 tmpTaskProcessedCount = taskProcessedCount;
109 taskProcessedCount = tmpTaskProcessedCount - mLastTaskProcessed;
110 mLastTaskProcessed = tmpTaskProcessedCount;
111 }
112 cout<<mThreadTestCount<<" Threads: \t"<<taskProcessedCount<<" processed Test-Tasks, \t"<<eventProcessedCount<<" processed Events, \t"<<elapsedTime<<" ms, \t"<<(double)mScaleReferenceTime/(double)elapsedTime<<" x\n";
113 mMeasurementTimer.restart();
114 if (++mThreadTestCount <= mThreadMaxTestCount) {
115 if (mThreadTestCount != 2) {
116 // add task processor
117 CTaskProcessorThread* taskProcessor = new CTaskProcessorThread(mHandleAlg,mCompletorUnit);
118 mProcessorUnitList.append(taskProcessor);
119 taskProcessor->installScheduler(mSchedulerUnit);
120 taskProcessor->startProcessing();
121 }
122
123 CThroughputTestTask* rootTask = CObjectMemoryPoolAllocator<CThroughputTestTask>::allocateAndConstructWithMemroyPool();
124 rootTask->initTestTask(mMaxBranchDepth,mBranchingFactor);
125 rootTask->addCallbackLinker(this);
126 CTaskEventCommunicator::postSendTaskScheduleEvent(mSchedulerUnit->getEventHandler(),rootTask,nullptr);
127 }
128 }
129
130
131 }; // end namespace Test
132
133 }; // end namespace Konclude