From 7a4f3be9f3f44781f789b60620a77f3857a6cd15 Mon Sep 17 00:00:00 2001 From: Yibing Liu Date: Sat, 6 Jan 2018 06:14:48 +0000 Subject: [PATCH] Fix profiler place bug --- paddle/platform/profiler.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/paddle/platform/profiler.cc b/paddle/platform/profiler.cc index abb1e6a89..239df2312 100644 --- a/paddle/platform/profiler.cc +++ b/paddle/platform/profiler.cc @@ -181,6 +181,7 @@ std::vector> DisableProfiler() { void ParseEvents(std::vector>& events, EventSortingKey sorted_by) { + if (g_profiler_place == "") return; std::vector> events_table; size_t max_name_width = 0; for (size_t i = 0; i < events.size(); i++) { @@ -199,7 +200,7 @@ void ParseEvents(std::vector>& events, } if (rit != pushed_events.rend()) { - double event_time = (g_state == ProfilerState::kCUDA) + double event_time = (g_profiler_place == "CUDA") ? rit->CudaElapsedMs(events[i][j]) : rit->CpuElapsedMs(events[i][j]); std::string event_name = @@ -224,7 +225,7 @@ void ParseEvents(std::vector>& events, std::max(event_time, event_items[index].max_time); } - // remove the start marker from the list + // remove the push marker from the list pushed_events.erase((++rit).base()); } else { LOG(WARNING) << "Cannot find the push marker of event \'" @@ -257,13 +258,11 @@ void ParseEvents(std::vector>& events, } events_table.push_back(event_items); - // To check whether there are events with `push` but without `pop` + // log warning if there are events with `push` but without `pop` std::list::reverse_iterator rit = pushed_events.rbegin(); while (rit != pushed_events.rend()) { - if (rit->kind() == "push") { - LOG(WARNING) << "Cannot find the pop marker of event \'" << rit->name() - << "\', which will be ignored in profiling report."; - } + LOG(WARNING) << "Cannot find the pop marker of event \'" << rit->name() + << "\', which will be ignored in profiling report."; ++rit; } } @@ -275,7 +274,6 @@ void ParseEvents(std::vector>& events, void PrintProfilingReport(std::vector>& events_table, EventSortingKey sorted_by, const size_t name_width, const size_t data_width) { - if (g_profiler_place == "") return; // Output header information std::cout << "\n------------------------->" << " Profiling Report " -- GitLab