Skip to content

Commit 690625f

Browse files
authored
Merge pull request #12456 from jacquesqiao/add-profiler-to-pserver
Add profiler to pserver
2 parents 6d3da45 + 7e46a8d commit 690625f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

paddle/fluid/operators/listen_and_serv_op.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ limitations under the License. */
1919
#include <thread> // NOLINT
2020
#include <vector>
2121

22+
#include "gflags/gflags.h"
23+
2224
#include "paddle/fluid/operators/detail/macros.h"
2325

2426
#include "paddle/fluid/operators/distributed/request_handler_impl.h"
2527
#include "paddle/fluid/operators/listen_and_serv_op.h"
2628
#include "paddle/fluid/platform/profiler.h"
2729

30+
DEFINE_int32(listen_and_serv_profile_period, 0,
31+
"the period of listen_and_serv to do profile");
32+
2833
namespace paddle {
2934
namespace operators {
3035

@@ -122,7 +127,18 @@ void ListenAndServOp::RunSyncLoop(
122127
std::shared_ptr<framework::ExecutorPrepareContext>(nullptr));
123128

124129
rpc_service_->ResetBarrierCounter();
130+
131+
int32_t profile_step = 0;
125132
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+
}
126142
// Get from multiple trainers, we don't care about the order in which
127143
// the gradients arrives, just add suffix 0~n and merge the gradient.
128144
rpc_service_->SetCond(distributed::kRequestSend);
@@ -164,6 +180,15 @@ void ListenAndServOp::RunSyncLoop(
164180
// reset received sparse vars to avoid reuse it in the next mini-batch
165181
dynamic_cast<distributed::RequestSendHandler *>(request_send_handler_.get())
166182
->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+
}
167192
} // while(true)
168193
}
169194

python/paddle/fluid/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def __bootstrap__():
127127
]
128128
if core.is_compiled_with_dist():
129129
read_env_flags.append('rpc_deadline')
130+
read_env_flags.append('listen_and_serv_profile_period')
130131

131132
if core.is_compiled_with_cuda():
132133
read_env_flags += [

0 commit comments

Comments
 (0)