| 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 "CAnalyseReasonerManager.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Manager { |
| 31 |
|
| 32 |
|
| 33 |
CAnalyseReasonerManager::CAnalyseReasonerManager(CWatchDog *threadWatchDog) : CReasonerManagerThread(threadWatchDog) { |
| 34 |
mWatchDog = threadWatchDog; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
CAnalyseReasonerManager::~CAnalyseReasonerManager() { |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
void CAnalyseReasonerManager::logQueryProgressUpdates() { |
| 44 |
bool activeCalculation = false; |
| 45 |
CConcurrentTaskCalculationEnvironment* calcEnv = dynamic_cast<CConcurrentTaskCalculationEnvironment*>(mCalculationManager->getCalculationContext()); |
| 46 |
if (calcEnv) { |
| 47 |
|
| 48 |
double approxRemainingTasksCount = calcEnv->getCalculationApproximatedRemainingTasksCount(); |
| 49 |
cint64 computedTasksCount = calcEnv->getCalculationStatisticTasksProcessedCount(); |
| 50 |
double computedTime = calcEnv->getCalculationComputionTime()/(double)mWorkControllerCount; |
| 51 |
if (approxRemainingTasksCount >= 1 && computedTasksCount >= 1 && computedTime >= 1) { |
| 52 |
|
| 53 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Calculation progress:"),this); |
| 54 |
|
| 55 |
QHash<QString,cint64>* mCalcStatHash = mCalculationManager->getCalculationStatistics(); |
| 56 |
if (mCalcStatHash) { |
| 57 |
QString compTime = getLoggingCalculationStatisticsTimeSizeString(mCalcStatHash->value("calculation-computing-time")/(double)mWorkControllerCount); |
| 58 |
QString memCons = getLoggingCalculationStatisticsMemorySizeString(mCalcStatHash->value("calculation-memory-consumption")); |
| 59 |
QString statString = QString("Up to now calculation computing time: %1, calculation memory consumption: %2") |
| 60 |
.arg(compTime) |
| 61 |
.arg(memCons); |
| 62 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",statString,this); |
| 63 |
delete mCalcStatHash; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
double timePerTask = (double)computedTime/(double)computedTasksCount; |
| 68 |
double approxRemainingTime = approxRemainingTasksCount*timePerTask; |
| 69 |
QString approxRemainingTimeString; |
| 70 |
if (approxRemainingTime > 0) { |
| 71 |
approxRemainingTimeString = getLoggingCalculationStatisticsTimeSizeString(approxRemainingTime); |
| 72 |
} else { |
| 73 |
approxRemainingTimeString = QString("very very long"); |
| 74 |
} |
| 75 |
double progress = computedTasksCount/(approxRemainingTasksCount+computedTasksCount)*100.; |
| 76 |
|
| 77 |
QString statString1 = QString("Processed tasks: %1, approximated remaining tasks: %2") |
| 78 |
.arg(computedTasksCount) |
| 79 |
.arg(approxRemainingTasksCount); |
| 80 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",statString1,this); |
| 81 |
QString statString2 = QString("Approximated remaining calculation time: %1, approximated calculation progress: %2 %\r\n") |
| 82 |
.arg(approxRemainingTimeString) |
| 83 |
.arg(progress); |
| 84 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",statString2,this); |
| 85 |
|
| 86 |
activeCalculation = true; |
| 87 |
|
| 88 |
} |
| 89 |
} |
| 90 |
if (classificationMan) { |
| 91 |
CClassificationProgress* classifProgress = classificationMan->getClassificationProgress(); |
| 92 |
if (classifProgress) { |
| 93 |
if (classifProgress->getTestedSatisfiable() != classifProgress->getTotalSatisfiable() || classifProgress->getTestedSubsumptions() != classifProgress->getTotalSubsumptions()) { |
| 94 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Classification progress:"),this); |
| 95 |
|
| 96 |
QString remainingTimeString = getLoggingCalculationStatisticsTimeSizeString(classifProgress->getRemainingMilliSeconds()); |
| 97 |
QString statString1 = QString("Finished satisfiable tests: %1, approximated remaining satisfiable tests: %2") |
| 98 |
.arg(classifProgress->getTestedSatisfiable()) |
| 99 |
.arg(classifProgress->getTotalSatisfiable()-classifProgress->getTestedSatisfiable()); |
| 100 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",statString1,this); |
| 101 |
|
| 102 |
if (classifProgress->getTotalSubsumptions() >= 0) { |
| 103 |
QString statString2 = QString("Tested subsumptions: %1, approximated remaining subsumptions to test: %2") |
| 104 |
.arg(classifProgress->getTestedSubsumptions()) |
| 105 |
.arg(classifProgress->getTotalSubsumptions()-classifProgress->getTestedSubsumptions()); |
| 106 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",statString2,this); |
| 107 |
} |
| 108 |
|
| 109 |
QString statString3 = QString("Approximated remaining classification time: %1, approximated classification progress: %2 %\r\n") |
| 110 |
.arg(remainingTimeString) |
| 111 |
.arg(classifProgress->getProgessPercent()); |
| 112 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",statString3,this); |
| 113 |
|
| 114 |
activeCalculation = true; |
| 115 |
} |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
if (mRealizationManager) { |
| 120 |
CRealizationProgress* realProgress = mRealizationManager->getRealizationProgress(); |
| 121 |
if (realProgress) { |
| 122 |
if (realProgress->getTestedClasses() != realProgress->getTotalClasses()) { |
| 123 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",logTr("Realization progress:"),this); |
| 124 |
|
| 125 |
QString remainingTimeString = getLoggingCalculationStatisticsTimeSizeString(realProgress->getRemainingMilliSeconds()); |
| 126 |
QString statString1 = QString("Tested instantiations: %1, approximated remaining instantiations to test: %2") |
| 127 |
.arg(realProgress->getTestedClasses()) |
| 128 |
.arg(realProgress->getTotalClasses()-realProgress->getTestedClasses()); |
| 129 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",statString1,this); |
| 130 |
|
| 131 |
QString statString3 = QString("Approximated remaining realization time: %1, approximated realization progress: %2 %\r\n") |
| 132 |
.arg(remainingTimeString) |
| 133 |
.arg(realProgress->getProgessPercent()); |
| 134 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",statString3,this); |
| 135 |
|
| 136 |
activeCalculation = true; |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
if (mAnswererManager) { |
| 142 |
CAnsweringProgress* answeringProgress = mAnswererManager->getAnsweringProgress(); |
| 143 |
if (answeringProgress) { |
| 144 |
if (answeringProgress->getTestedInstances() != answeringProgress->getTotalInstances()) { |
| 145 |
LOG(INFO, "::Konclude::Reasoner::Kernel::ReasonerManager", logTr("Answering progress:"), this); |
| 146 |
|
| 147 |
QString remainingTimeString = getLoggingCalculationStatisticsTimeSizeString(answeringProgress->getRemainingMilliSeconds()); |
| 148 |
QString statString1 = QString("Tested instantiations: %1, approximated remaining instantiations to test: %2") |
| 149 |
.arg(answeringProgress->getTestedInstances()) |
| 150 |
.arg(answeringProgress->getTotalInstances() - answeringProgress->getTestedInstances()); |
| 151 |
LOG(INFO, "::Konclude::Reasoner::Kernel::ReasonerManager", statString1, this); |
| 152 |
|
| 153 |
QString statString3 = QString("Approximated remaining answering time: %1, approximated answering progress: %2 %\r\n") |
| 154 |
.arg(remainingTimeString) |
| 155 |
.arg(answeringProgress->getProgessPercent()); |
| 156 |
LOG(INFO, "::Konclude::Reasoner::Kernel::ReasonerManager", statString3, this); |
| 157 |
|
| 158 |
activeCalculation = true; |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
if (activeCalculation) { |
| 164 |
|
| 165 |
if (mSatExpCache) { |
| 166 |
CCacheStatistics* cacheStats = mSatExpCache->getCacheStatistics(); |
| 167 |
QString statString3 = QString("Satisfiable-Expander-Cache statistics: %1 cache entries, %2 memory consumption") |
| 168 |
.arg(cacheStats->getCacheEntriesCount()) |
| 169 |
.arg(getLoggingCalculationStatisticsMemorySizeString(cacheStats->getMemoryConsumption())); |
| 170 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",statString3,this); |
| 171 |
|
| 172 |
} |
| 173 |
if (unsatCache) { |
| 174 |
CCacheStatistics* cacheStats = unsatCache->getCacheStatistics(); |
| 175 |
QString statString3 = QString("Unsatisfiable-Cache statistics: %1 cache entries, %2 memory consumption\r\n") |
| 176 |
.arg(cacheStats->getCacheEntriesCount()) |
| 177 |
.arg(getLoggingCalculationStatisticsMemorySizeString(cacheStats->getMemoryConsumption())); |
| 178 |
LOG(INFO,"::Konclude::Reasoner::Kernel::ReasonerManager",statString3,this); |
| 179 |
|
| 180 |
} |
| 181 |
|
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
double CAnalyseReasonerManager::getQueryProgress() { |
| 188 |
double progressPercent = 100; |
| 189 |
//double allTotalWork = 0; |
| 190 |
//double allClosedWork = 0; |
| 191 |
//CConcurrentWorkCalculationEnvironment *conCalcContext = dynamic_cast<CConcurrentWorkCalculationEnvironment *>(mCalculationManager->getCalculationContext()); |
| 192 |
//CWorkRegistry *registry = conCalcContext->getWorkRegistry(); |
| 193 |
//workSyncMutex.lock(); |
| 194 |
//QList<CQuery *> queryList = mCalculatingQuerySet.values(); |
| 195 |
//workSyncMutex.unlock(); |
| 196 |
//foreach (CQuery *query, queryList) { |
| 197 |
// CWorkProvidedQuery *workQuery = dynamic_cast<CWorkProvidedQuery *>(query); |
| 198 |
// if (workQuery) { |
| 199 |
// double totWorkCount = 0; |
| 200 |
// double closWorkCount = 0; |
| 201 |
// QLinkedList<CWork *> workList = workQuery->getWorkList(); |
| 202 |
// foreach (CWork *work, workList) { |
| 203 |
// CWorkLock *workLock = registry->getWorkLock(work); |
| 204 |
// if (workLock) { |
| 205 |
// CCalcBoxProcessWork *calcWork = dynamic_cast<CCalcBoxProcessWork *>(work); |
| 206 |
// if (calcWork) { |
| 207 |
// closWorkCount += calcWork->getApproximatedClosedWorkCount(); |
| 208 |
// totWorkCount += calcWork->getApproximatedTotalWorkCount(); |
| 209 |
// } |
| 210 |
// workLock->releaseLock(); |
| 211 |
// delete workLock; |
| 212 |
// } |
| 213 |
// } |
| 214 |
// allTotalWork += totWorkCount; |
| 215 |
// allClosedWork += closWorkCount; |
| 216 |
// } |
| 217 |
//} |
| 218 |
//if (allTotalWork > 0) { |
| 219 |
// progressPercent = allClosedWork / allTotalWork * 100.; |
| 220 |
//} |
| 221 |
return progressPercent; |
| 222 |
} |
| 223 |
|
| 224 |
double CAnalyseReasonerManager::getQueryTotalWorkCount() { |
| 225 |
double allTotalWork = 0; |
| 226 |
//double allClosedWork = 0; |
| 227 |
//CConcurrentWorkCalculationEnvironment *conCalcContext = dynamic_cast<CConcurrentWorkCalculationEnvironment *>(mCalculationManager->getCalculationContext()); |
| 228 |
//CWorkRegistry *registry = conCalcContext->getWorkRegistry(); |
| 229 |
//workSyncMutex.lock(); |
| 230 |
//QList<CQuery *> queryList = mCalculatingQuerySet.values(); |
| 231 |
//workSyncMutex.unlock(); |
| 232 |
//foreach (CQuery *query, queryList) { |
| 233 |
// CWorkProvidedQuery *workQuery = dynamic_cast<CWorkProvidedQuery *>(query); |
| 234 |
// if (workQuery) { |
| 235 |
// double totWorkCount = 0; |
| 236 |
// double closWorkCount = 0; |
| 237 |
// QLinkedList<CWork *> workList = workQuery->getWorkList(); |
| 238 |
// foreach (CWork *work, workList) { |
| 239 |
// CWorkLock *workLock = registry->getWorkLock(work); |
| 240 |
// if (workLock) { |
| 241 |
// CCalcBoxProcessWork *calcWork = dynamic_cast<CCalcBoxProcessWork *>(work); |
| 242 |
// if (calcWork) { |
| 243 |
// closWorkCount += calcWork->getApproximatedClosedWorkCount(); |
| 244 |
// totWorkCount += calcWork->getApproximatedTotalWorkCount(); |
| 245 |
// } |
| 246 |
// workLock->releaseLock(); |
| 247 |
// delete workLock; |
| 248 |
// } |
| 249 |
// } |
| 250 |
// allTotalWork += totWorkCount; |
| 251 |
// allClosedWork += closWorkCount; |
| 252 |
// } |
| 253 |
//} |
| 254 |
return allTotalWork; |
| 255 |
} |
| 256 |
|
| 257 |
double CAnalyseReasonerManager::getQueryCalculatedWorkCount() { |
| 258 |
double allTotalWork = 0; |
| 259 |
double allClosedWork = 0; |
| 260 |
//CConcurrentWorkCalculationEnvironment *conCalcContext = dynamic_cast<CConcurrentWorkCalculationEnvironment *>(mCalculationManager->getCalculationContext()); |
| 261 |
//CWorkRegistry *registry = conCalcContext->getWorkRegistry(); |
| 262 |
//workSyncMutex.lock(); |
| 263 |
//QList<CQuery *> queryList = mCalculatingQuerySet.values(); |
| 264 |
//workSyncMutex.unlock(); |
| 265 |
//foreach (CQuery *query, queryList) { |
| 266 |
// CWorkProvidedQuery *workQuery = dynamic_cast<CWorkProvidedQuery *>(query); |
| 267 |
// if (workQuery) { |
| 268 |
// double totWorkCount = 0; |
| 269 |
// double closWorkCount = 0; |
| 270 |
// QLinkedList<CWork *> workList = workQuery->getWorkList(); |
| 271 |
// foreach (CWork *work, workList) { |
| 272 |
// CWorkLock *workLock = registry->getWorkLock(work); |
| 273 |
// if (workLock) { |
| 274 |
// CCalcBoxProcessWork *calcWork = dynamic_cast<CCalcBoxProcessWork *>(work); |
| 275 |
// if (calcWork) { |
| 276 |
// closWorkCount += calcWork->getApproximatedClosedWorkCount(); |
| 277 |
// totWorkCount += calcWork->getApproximatedTotalWorkCount(); |
| 278 |
// } |
| 279 |
// workLock->releaseLock(); |
| 280 |
// delete workLock; |
| 281 |
// } |
| 282 |
// } |
| 283 |
// allTotalWork += totWorkCount; |
| 284 |
// allClosedWork += closWorkCount; |
| 285 |
// } |
| 286 |
//} |
| 287 |
return allClosedWork; |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
}; // end namespace Manager |
| 293 |
|
| 294 |
}; // end namespace Kernel |
| 295 |
|
| 296 |
}; // end namespace Reasoner |
| 297 |
|
| 298 |
}; // end namespace Konclude |