Skip to content

Commit 6809238

Browse files
authored
fix analysis predictor profile (#13896)
1 parent 6b795d4 commit 6809238

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

paddle/fluid/framework/operator.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,17 @@ void OperatorBase::Run(const Scope& scope, const platform::Place& place) {
149149
platform::SetDeviceId(dev_id);
150150
#endif
151151
}
152-
platform::DeviceContextPool& pool = platform::DeviceContextPool::Instance();
153-
platform::RecordEvent record_event(Type(), pool.Get(place));
154-
RunImpl(scope, place);
152+
153+
// The profile has a process-wide mutex, results in serious performance issue
154+
// in concurrency scenerio. Here use an `if` to fix this issue.
155+
// Please not remove the `if`, ask @Superjomn if there are any concern.
156+
if (platform::IsProfileEnabled()) {
157+
platform::DeviceContextPool& pool = platform::DeviceContextPool::Instance();
158+
platform::RecordEvent record_event(Type(), pool.Get(place));
159+
RunImpl(scope, place);
160+
} else {
161+
RunImpl(scope, place);
162+
}
155163
VLOG(3) << place << " " << DebugStringEx(&scope);
156164
}
157165

paddle/fluid/inference/api/analysis_predictor.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,19 @@ bool AnalysisPredictor::LoadProgramDesc() {
340340
}
341341
return true;
342342
}
343+
344+
AnalysisPredictor::~AnalysisPredictor() {
345+
#if !defined(_WIN32)
346+
if (FLAGS_profile) {
347+
platform::DisableProfiler(platform::EventSortingKey::kTotal,
348+
"./profile.log");
349+
}
350+
#endif
351+
if (sub_scope_) {
352+
scope_->DeleteScope(sub_scope_);
353+
}
354+
}
355+
343356
std::unique_ptr<PaddlePredictor> AnalysisPredictor::Clone() {
344357
auto *x = new AnalysisPredictor(config_);
345358
x->Init(scope_, inference_program_);

paddle/fluid/inference/api/analysis_predictor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class AnalysisPredictor : public PaddlePredictor {
7272
template <typename T>
7373
void GetFetchOne(const framework::LoDTensor &fetchs,
7474
PaddleTensor *output_data);
75+
~AnalysisPredictor();
7576

7677
private:
7778
contrib::AnalysisConfig config_;

0 commit comments

Comments
 (0)