From f14e579cc37f5128b3e675c3aa05a1f3658ecef3 Mon Sep 17 00:00:00 2001 From: Xin Pan Date: Wed, 30 May 2018 19:52:23 +0800 Subject: [PATCH] clean up --- paddle/fluid/platform/profiler.cc | 4 ++-- paddle/fluid/pybind/pybind.cc | 1 + python/paddle/fluid/profiler.py | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/platform/profiler.cc b/paddle/fluid/platform/profiler.cc index 04f450aa3..3d8d64e4c 100644 --- a/paddle/fluid/platform/profiler.cc +++ b/paddle/fluid/platform/profiler.cc @@ -235,7 +235,7 @@ void EnableProfiler(ProfilerState state) { return; } g_state = state; - { should_send_profile_state = true; } + should_send_profile_state = true; GetDeviceTracer()->Enable(); #ifdef PADDLE_WITH_CUDA if (g_state == ProfilerState::kCUDA) { @@ -460,7 +460,7 @@ void DisableProfiler(EventSortingKey sorted_key, tracer->GenProfile(profile_path); } g_state = ProfilerState::kDisabled; - { should_send_profile_state = true; } + should_send_profile_state = true; } bool IsProfileEnabled() { return g_state != ProfilerState::kDisabled; } diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index 50a1c0725..767c38833 100644 --- a/paddle/fluid/pybind/pybind.cc +++ b/paddle/fluid/pybind/pybind.cc @@ -492,6 +492,7 @@ All parameter, weight, gradient are variables in Paddle. m.def("enable_profiler", platform::EnableProfiler); m.def("disable_profiler", platform::DisableProfiler); + m.def("is_profiler_enabled", platform::IsProfileEnabled); m.def("reset_profiler", platform::ResetProfiler); // -- python binds for parallel executor. diff --git a/python/paddle/fluid/profiler.py b/python/paddle/fluid/profiler.py index 2e87cab88..e2bd1d4c9 100644 --- a/python/paddle/fluid/profiler.py +++ b/python/paddle/fluid/profiler.py @@ -76,6 +76,15 @@ def reset_profiler(): def start_profiler(state): + """Enable the profiler. + + Args: + state (string) : The profiling state, which should be 'CPU', 'GPU' + or 'All'. 'CPU' means only profile CPU. 'GPU' means profiling + GPU as well. 'All' also generates timeline. + """ + if core.is_profiler_enabled(): + return if state not in ['CPU', 'GPU', "All"]: raise ValueError("The state must be 'CPU' or 'GPU' or 'All'.") if state == "GPU": @@ -88,6 +97,23 @@ def start_profiler(state): def stop_profiler(sorted_key=None, profile_path='/tmp/profile'): + """Stop the profiler. + + Args: + sorted_key (string) : If None, the profiling results will be printed + in the order of first end time of events. Otherwise, the profiling + results will be sorted by the this flag. This flag should be one + of 'calls', 'total', 'max', 'min' or 'ave'. + The `calls` means sorting by the number of calls. + The `total` means sorting by the total execution time. + The `max` means sorting by the maximum execution time. + The `min` means sorting by the minimum execution time. + The `ave` means sorting by the average execution time. + profile_path (string) : If state == 'All', it will write a profile + proto output file. + """ + if not core.is_profiler_enabled(): + return sorted_key = 'default' if sorted_key is None else sorted_key if sorted_key not in ['default', 'calls', 'total', 'max', 'min', 'ave']: raise ValueError("The sorted_key must be None or in 'calls', 'total', " -- GitLab