File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
paddle/fluid/inference/api Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,9 @@ limitations under the License. */
22
22
#include < vector>
23
23
24
24
#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" );
25
28
26
29
namespace paddle {
27
30
namespace {
@@ -58,6 +61,15 @@ bool NativePaddlePredictor::Init(
58
61
std::shared_ptr<framework::Scope> parent_scope) {
59
62
VLOG (3 ) << " Predictor::init()" ;
60
63
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
+
61
73
if (config_.use_gpu ) {
62
74
place_ = paddle::platform::CUDAPlace (config_.device );
63
75
} else {
@@ -102,6 +114,10 @@ bool NativePaddlePredictor::Init(
102
114
}
103
115
104
116
NativePaddlePredictor::~NativePaddlePredictor () {
117
+ if (FLAGS_profile) {
118
+ platform::DisableProfiler (platform::EventSortingKey::kTotal ,
119
+ " ./profile.log" );
120
+ }
105
121
if (sub_scope_) {
106
122
scope_->DeleteScope (sub_scope_);
107
123
}
You can’t perform that action at this time.
0 commit comments