Skip to content

Commit e765dea

Browse files
authored
add profiler to fluid inference (#12707)
1 parent d96ee24 commit e765dea

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

paddle/fluid/inference/api/api_impl.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ limitations under the License. */
2222
#include <vector>
2323

2424
#include "paddle/fluid/inference/api/api_impl.h"
25+
#include "paddle/fluid/platform/profiler.h"
26+
27+
DEFINE_bool(profile, false, "Turn on profiler for fluid");
2528

2629
namespace paddle {
2730
namespace {
@@ -58,6 +61,15 @@ bool NativePaddlePredictor::Init(
5861
std::shared_ptr<framework::Scope> parent_scope) {
5962
VLOG(3) << "Predictor::init()";
6063

64+
if (FLAGS_profile) {
65+
LOG(WARNING) << "Profiler is actived, might affect the performance";
66+
LOG(INFO) << "You can turn off by set gflags '-profile false'";
67+
68+
auto tracking_device = config_.use_gpu ? platform::ProfilerState::kAll
69+
: platform::ProfilerState::kCPU;
70+
platform::EnableProfiler(tracking_device);
71+
}
72+
6173
if (config_.use_gpu) {
6274
place_ = paddle::platform::CUDAPlace(config_.device);
6375
} else {
@@ -102,6 +114,10 @@ bool NativePaddlePredictor::Init(
102114
}
103115

104116
NativePaddlePredictor::~NativePaddlePredictor() {
117+
if (FLAGS_profile) {
118+
platform::DisableProfiler(platform::EventSortingKey::kTotal,
119+
"./profile.log");
120+
}
105121
if (sub_scope_) {
106122
scope_->DeleteScope(sub_scope_);
107123
}

0 commit comments

Comments
 (0)