@@ -19,12 +19,17 @@ limitations under the License. */
19
19
#include < thread> // NOLINT
20
20
#include < vector>
21
21
22
+ #include " gflags/gflags.h"
23
+
22
24
#include " paddle/fluid/operators/detail/macros.h"
23
25
24
26
#include " paddle/fluid/operators/distributed/request_handler_impl.h"
25
27
#include " paddle/fluid/operators/listen_and_serv_op.h"
26
28
#include " paddle/fluid/platform/profiler.h"
27
29
30
+ DEFINE_int32 (listen_and_serv_profile_period, 0 ,
31
+ " the period of listen_and_serv to do profile" );
32
+
28
33
namespace paddle {
29
34
namespace operators {
30
35
@@ -122,7 +127,18 @@ void ListenAndServOp::RunSyncLoop(
122
127
std::shared_ptr<framework::ExecutorPrepareContext>(nullptr ));
123
128
124
129
rpc_service_->ResetBarrierCounter ();
130
+
131
+ int32_t profile_step = 0 ;
125
132
while (true ) {
133
+ PADDLE_ENFORCE_LE (profile_step, FLAGS_listen_and_serv_profile_period,
134
+ " profile_step should not be larger then "
135
+ " FLAGS_listen_and_serv_profile_period" );
136
+ if (FLAGS_listen_and_serv_profile_period > 0 ) {
137
+ if (profile_step == 0 ) {
138
+ auto pf_state = paddle::platform::ProfilerState::kCPU ;
139
+ paddle::platform::EnableProfiler (pf_state);
140
+ }
141
+ }
126
142
// Get from multiple trainers, we don't care about the order in which
127
143
// the gradients arrives, just add suffix 0~n and merge the gradient.
128
144
rpc_service_->SetCond (distributed::kRequestSend );
@@ -164,6 +180,15 @@ void ListenAndServOp::RunSyncLoop(
164
180
// reset received sparse vars to avoid reuse it in the next mini-batch
165
181
dynamic_cast <distributed::RequestSendHandler *>(request_send_handler_.get ())
166
182
->ResetSparseVarRecorder ();
183
+ if (FLAGS_listen_and_serv_profile_period > 0 ) {
184
+ if (profile_step == FLAGS_listen_and_serv_profile_period) {
185
+ paddle::platform::DisableProfiler (
186
+ paddle::platform::EventSortingKey::kTotal , " /dev/null" );
187
+ profile_step = 0 ;
188
+ } else {
189
+ profile_step++;
190
+ }
191
+ }
167
192
} // while(true)
168
193
}
169
194
0 commit comments