From 1ee2a9a4246a6c6c64400f30dc677ed2218746c2 Mon Sep 17 00:00:00 2001 From: wangchaochaohu Date: Tue, 31 Mar 2020 12:39:35 +0800 Subject: [PATCH] Profiler refine (#23294) * refine output of profiler for child event --- paddle/fluid/platform/profiler_helper.h | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/paddle/fluid/platform/profiler_helper.h b/paddle/fluid/platform/profiler_helper.h index f890e40e41d..41d5180ffaf 100644 --- a/paddle/fluid/platform/profiler_helper.h +++ b/paddle/fluid/platform/profiler_helper.h @@ -493,11 +493,13 @@ void PrintOverHead(const OverHead &overhead, const size_t data_width) { } // Print results -void PrintProfiler(const std::vector> &events_table, - const std::multimap &child_map, - const OverHead &overhead, const std::string &sorted_domain, - const size_t name_width, const size_t data_width, - bool merge_thread, int print_depth) { +void PrintProfiler( + const std::vector> &events_table, + const std::multimap &child_map, + std::function sorted_func, + EventSortingKey sorted_by, const OverHead &overhead, + const std::string &sorted_domain, const size_t name_width, + const size_t data_width, bool merge_thread, int print_depth) { if (print_depth == 0) { // Output header information std::cout << "\n------------------------->" @@ -556,6 +558,10 @@ void PrintProfiler(const std::vector> &events_table, table.push_back(it->second); } } + + if (sorted_by != EventSortingKey::kDefault) { + std::sort(table.begin(), table.end(), sorted_func); + } if (!table.empty()) child_table.push_back(table); auto name_len = event_item.name.length(); @@ -591,8 +597,9 @@ void PrintProfiler(const std::vector> &events_table, << std::setw(data_width) << event_item.ave_time << std::setw(data_width) << event_item.ratio << std::endl; - PrintProfiler(child_table, child_map, overhead, sorted_domain, name_width, - data_width, merge_thread, print_depth + 1); + PrintProfiler(child_table, child_map, sorted_func, sorted_by, overhead, + sorted_domain, name_width, data_width, merge_thread, + print_depth + 1); } } } @@ -711,8 +718,8 @@ void ParseEvents(const std::vector> &events, sorted_by, &max_name_width, &overhead, merge_thread); // Print report - PrintProfiler(events_table, child_map, overhead, sorted_domain, - max_name_width + 8, 12, merge_thread, 0); + PrintProfiler(events_table, child_map, sorted_func, sorted_by, overhead, + sorted_domain, max_name_width + 8, 12, merge_thread, 0); } } // namespace platform -- GitLab