Recursively print the report of a given node of the profiler tree
| 274 | |
| 275 | // Recursively print the report of a given node of the profiler tree |
| 276 | void Profiler::printRecursiveNodeReport(ProfileNodeIterator* iterator, |
| 277 | int spacing, |
| 278 | std::ostream& outputStream) { |
| 279 | iterator->first(); |
| 280 | |
| 281 | // If we are at the end of a branch in the profiler tree |
| 282 | if (iterator->isEnd()) { |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | std::chrono::duration<double, std::milli> parentTime = iterator->isRoot() ? getElapsedTimeSinceStart() : |
| 287 | iterator->getCurrentParentTotalTime(); |
| 288 | std::chrono::duration<double, std::milli> accumulatedTime = std::chrono::duration<double, std::milli>::zero(); |
| 289 | uint nbFrames = Profiler::getNbFrames(); |
| 290 | for (int i=0; i<spacing; i++) outputStream << " "; |
| 291 | outputStream << "---------------" << std::endl; |
| 292 | for (int i=0; i<spacing; i++) outputStream << " "; |
| 293 | outputStream << "| Profiling : " << iterator->getCurrentParentName() << |
| 294 | " (total running time : " << parentTime.count() << " ms) ---" << std::endl; |
| 295 | |
| 296 | // Recurse over the children of the current node |
| 297 | int nbChildren = 0; |
| 298 | for (int i=0; !iterator->isEnd(); i++, iterator->next()) { |
| 299 | nbChildren++; |
| 300 | std::chrono::duration<double, std::milli> currentTotalTime = iterator->getCurrentTotalTime(); |
| 301 | accumulatedTime += currentTotalTime; |
| 302 | long double fraction = parentTime.count() > std::numeric_limits<long double>::epsilon() ? |
| 303 | (currentTotalTime.count() / parentTime.count()) * 100.0L : 0.0L; |
| 304 | for (int j=0; j<spacing; j++) outputStream << " "; |
| 305 | outputStream << "| " << i << " -- " << iterator->getCurrentName() << " : " << |
| 306 | fraction << " % | " << (currentTotalTime.count() / (long double) (nbFrames)) << |
| 307 | " ms/frame (" << iterator->getCurrentNbTotalCalls() << " calls)" << |
| 308 | std::endl; |
| 309 | } |
| 310 | |
| 311 | if (parentTime < accumulatedTime) { |
| 312 | outputStream << "Something is wrong !" << std::endl; |
| 313 | } |
| 314 | for (int i=0; i<spacing; i++) outputStream << " "; |
| 315 | long double percentage = parentTime.count() > std::numeric_limits<long double>::epsilon() ? |
| 316 | ((parentTime - accumulatedTime) / parentTime) * 100.0L : 0.0L; |
| 317 | std::chrono::duration<double, std::milli> difference = parentTime - accumulatedTime; |
| 318 | outputStream << "| Unaccounted : " << difference.count() << " ms (" << percentage << " %)" << std::endl; |
| 319 | |
| 320 | for (int i=0; i<nbChildren; i++){ |
| 321 | iterator->enterChild(i); |
| 322 | printRecursiveNodeReport(iterator, spacing + 3, outputStream); |
| 323 | iterator->enterParent(); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | #endif |
nothing calls this directly
no test coverage detected