diff --git a/algo/base/util/TimingsFormat.cxx b/algo/base/util/TimingsFormat.cxx index f7e81949acad562fae92c0ff7901d56fd76524e4..a6798f45005fef5cc78f88dcfaddd156947c287a 100644 --- a/algo/base/util/TimingsFormat.cxx +++ b/algo/base/util/TimingsFormat.cxx @@ -21,7 +21,11 @@ namespace cbm::algo fSS = std::stringstream(); } - void Title(std::string_view title) { fSS << fmt::format("{:<{}}\n", title, fAlign); } + void Title(std::string_view title) + { + Indent(); + fSS << fmt::format("{:<{}}\n", title, fAlign); + } std::string Finalize() { return fSS.str(); } @@ -35,13 +39,20 @@ namespace cbm::algo Measurement("Memset", t.memset(), t.throughput_memset()); NewLine(); + // Merge subtimers with identical names + // Useful eg in unpacking, where unpacker might be called multiple times per TS + std::unordered_map<std::string, xpu::timings> subtimers; for (xpu::timings& st : t.children()) { - if (st.kernels().empty()) { - Measurement(st.name(), st.wall(), st.throughput()); + subtimers[std::string(st.name())].merge(st); + } + + for (auto& [name, st] : subtimers) { + if (st.kernels().empty() && st.children().empty()) { + Measurement(name, st.wall(), st.throughput()); NewLine(); } else { - Title(st.name()); + Title(name); Fmt(st); NewLine(); } @@ -52,8 +63,10 @@ namespace cbm::algo NewLine(); } - Measurement("Kernel time", t.kernel_time(), t.throughput_kernels()); - NewLine(); + if (!t.kernels().empty()) { + Measurement("Kernel time", t.kernel_time(), t.throughput_kernels()); + NewLine(); + } Measurement("Wall time", t.wall(), t.throughput()); fIndent -= 2; } @@ -88,7 +101,7 @@ namespace cbm::algo private: void Measurement(std::string_view name, f64 time, f64 throughput) { - fSS << std::setw(fIndent) << std::setfill(' ') << std::right << ""; + Indent(); fSS << std::setw(fAlign) << std::setfill(' ') << std::left << fmt::format("{}:", name); Real(time, 10, 3, "ms"); if (std::isnormal(throughput)) { @@ -113,6 +126,8 @@ namespace cbm::algo } } + void Indent() { fSS << std::setw(fIndent) << std::setfill(' ') << std::left << ""; } + size_t fAlign = 0; size_t fIndent = 0; std::stringstream fSS;