Skip to content

Commit f14e579

Browse files
committed
clean up
1 parent cb01c59 commit f14e579

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

paddle/fluid/platform/profiler.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ void EnableProfiler(ProfilerState state) {
235235
return;
236236
}
237237
g_state = state;
238-
{ should_send_profile_state = true; }
238+
should_send_profile_state = true;
239239
GetDeviceTracer()->Enable();
240240
#ifdef PADDLE_WITH_CUDA
241241
if (g_state == ProfilerState::kCUDA) {
@@ -460,7 +460,7 @@ void DisableProfiler(EventSortingKey sorted_key,
460460
tracer->GenProfile(profile_path);
461461
}
462462
g_state = ProfilerState::kDisabled;
463-
{ should_send_profile_state = true; }
463+
should_send_profile_state = true;
464464
}
465465

466466
bool IsProfileEnabled() { return g_state != ProfilerState::kDisabled; }

paddle/fluid/pybind/pybind.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ All parameter, weight, gradient are variables in Paddle.
492492

493493
m.def("enable_profiler", platform::EnableProfiler);
494494
m.def("disable_profiler", platform::DisableProfiler);
495+
m.def("is_profiler_enabled", platform::IsProfileEnabled);
495496
m.def("reset_profiler", platform::ResetProfiler);
496497

497498
// -- python binds for parallel executor.

python/paddle/fluid/profiler.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ def reset_profiler():
7676

7777

7878
def start_profiler(state):
79+
"""Enable the profiler.
80+
81+
Args:
82+
state (string) : The profiling state, which should be 'CPU', 'GPU'
83+
or 'All'. 'CPU' means only profile CPU. 'GPU' means profiling
84+
GPU as well. 'All' also generates timeline.
85+
"""
86+
if core.is_profiler_enabled():
87+
return
7988
if state not in ['CPU', 'GPU', "All"]:
8089
raise ValueError("The state must be 'CPU' or 'GPU' or 'All'.")
8190
if state == "GPU":
@@ -88,6 +97,23 @@ def start_profiler(state):
8897

8998

9099
def stop_profiler(sorted_key=None, profile_path='/tmp/profile'):
100+
"""Stop the profiler.
101+
102+
Args:
103+
sorted_key (string) : If None, the profiling results will be printed
104+
in the order of first end time of events. Otherwise, the profiling
105+
results will be sorted by the this flag. This flag should be one
106+
of 'calls', 'total', 'max', 'min' or 'ave'.
107+
The `calls` means sorting by the number of calls.
108+
The `total` means sorting by the total execution time.
109+
The `max` means sorting by the maximum execution time.
110+
The `min` means sorting by the minimum execution time.
111+
The `ave` means sorting by the average execution time.
112+
profile_path (string) : If state == 'All', it will write a profile
113+
proto output file.
114+
"""
115+
if not core.is_profiler_enabled():
116+
return
91117
sorted_key = 'default' if sorted_key is None else sorted_key
92118
if sorted_key not in ['default', 'calls', 'total', 'max', 'min', 'ave']:
93119
raise ValueError("The sorted_key must be None or in 'calls', 'total', "

0 commit comments

Comments
 (0)