@@ -25,6 +25,10 @@ limitations under the License. */
25
25
#include " paddle/fluid/operators/listen_and_serv_op.h"
26
26
#include " paddle/fluid/platform/profiler.h"
27
27
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
+
28
32
namespace paddle {
29
33
namespace operators {
30
34
@@ -122,7 +126,13 @@ void ListenAndServOp::RunSyncLoop(
122
126
std::shared_ptr<framework::ExecutorPrepareContext>(nullptr ));
123
127
124
128
rpc_service_->ResetBarrierCounter ();
129
+
130
+ int32_t profile_step = 0 ;
125
131
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
+ }
126
136
// Get from multiple trainers, we don't care about the order in which
127
137
// the gradients arrives, just add suffix 0~n and merge the gradient.
128
138
rpc_service_->SetCond (distributed::kRequestSend );
@@ -164,6 +174,14 @@ void ListenAndServOp::RunSyncLoop(
164
174
// reset received sparse vars to avoid reuse it in the next mini-batch
165
175
dynamic_cast <distributed::RequestSendHandler *>(request_send_handler_.get ())
166
176
->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
+ }
167
185
} // while(true)
168
186
}
169
187
0 commit comments