Skip to content

Commit 0b861bb

Browse files
committed
add profiler for listen_and_serv op
1 parent 7ae73e3 commit 0b861bb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

paddle/fluid/operators/listen_and_serv_op.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ limitations under the License. */
2525
#include "paddle/fluid/operators/listen_and_serv_op.h"
2626
#include "paddle/fluid/platform/profiler.h"
2727

28+
DECLARE_int32(listen_and_serv_profile_period);
29+
DEFINE_int32(listen_and_serv_profile_period, 0,
30+
"the period of listen_and_serv to do profile");
31+
2832
namespace paddle {
2933
namespace operators {
3034

@@ -122,7 +126,13 @@ void ListenAndServOp::RunSyncLoop(
122126
std::shared_ptr<framework::ExecutorPrepareContext>(nullptr));
123127

124128
rpc_service_->ResetBarrierCounter();
129+
130+
int32_t profile_step = 0;
125131
while (true) {
132+
if (FLAGS_listen_and_serv_profile_period > 0 && profile_step == 0) {
133+
auto pf_state = paddle::platform::ProfilerState::kCPU;
134+
paddle::platform::EnableProfiler(pf_state);
135+
}
126136
// Get from multiple trainers, we don't care about the order in which
127137
// the gradients arrives, just add suffix 0~n and merge the gradient.
128138
rpc_service_->SetCond(distributed::kRequestSend);
@@ -164,6 +174,14 @@ void ListenAndServOp::RunSyncLoop(
164174
// reset received sparse vars to avoid reuse it in the next mini-batch
165175
dynamic_cast<distributed::RequestSendHandler *>(request_send_handler_.get())
166176
->ResetSparseVarRecorder();
177+
if (FLAGS_listen_and_serv_profile_period > 0 &&
178+
profile_step == FLAGS_listen_and_serv_profile_period) {
179+
paddle::platform::DisableProfiler(
180+
paddle::platform::EventSortingKey::kTotal, "/dev/null");
181+
profile_step = 0;
182+
} else {
183+
profile_step++;
184+
}
167185
} // while(true)
168186
}
169187

0 commit comments

Comments
 (0)