12 uint64_t totalTime = 0;
13 for (
auto& iter : records) {
14 stats.
push(ScopeStatistics{ iter.first, iter.second.duration, 0, iter.second.cpuUsage });
15 totalTime += iter.second.duration;
17 for (
auto& s : stats) {
18 s.relativeTime = float(s.totalTime) / float(totalTime);
20 std::sort(stats.begin(), stats.end(), [](ScopeStatistics& s1, ScopeStatistics& s2) {
21 return s1.totalTime > s2.totalTime;
26 void Profiler::printStatistics(
ILogger& logger)
const {
28 for (ScopeStatistics& s : stats) {
30 ss << std::setw(45) << std::left << s.name <<
" | " << std::setw(10) << std::right << s.totalTime
31 <<
"mus | rel: " << std::setw(8) << std::right << std::setprecision(3) << std::fixed
32 << 100._f * s.relativeTime <<
"% | cpu: " << std::setw(8) << std::right << std::setprecision(3)
33 << std::fixed << 100._f * s.cpuUsage <<
"%";
34 logger.
write(ss.str());
Logging routines of the run.
#define NAMESPACE_SPH_END
Tool to measure time spent in functions and profile the code.
Generic dynamically allocated resizable storage.
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
Wrapper of pointer that deletes the resource from destructor.
Interface providing generic (text, human readable) output of the program.
void write(TArgs &&... args)
Creates and logs a message by concatenating arguments.