@@ -173,8 +173,9 @@ void PopEvent(const std::string& name, const DeviceContext* dev_ctx) {
173
173
}
174
174
175
175
RecordEvent::RecordEvent (const std::string& name, const DeviceContext* dev_ctx)
176
- : start_ns_(PosixInNsec()) {
176
+ : is_enabled_( false ), start_ns_(PosixInNsec()) {
177
177
if (g_state == ProfilerState::kDisabled ) return ;
178
+ is_enabled_ = true ;
178
179
dev_ctx_ = dev_ctx;
179
180
name_ = name;
180
181
PushEvent (name_, dev_ctx_);
@@ -183,7 +184,7 @@ RecordEvent::RecordEvent(const std::string& name, const DeviceContext* dev_ctx)
183
184
}
184
185
185
186
RecordEvent::~RecordEvent () {
186
- if (g_state == ProfilerState::kDisabled ) return ;
187
+ if (g_state == ProfilerState::kDisabled || !is_enabled_ ) return ;
187
188
DeviceTracer* tracer = GetDeviceTracer ();
188
189
if (tracer) {
189
190
tracer->AddCPURecords (CurAnnotation (), start_ns_, PosixInNsec (),
@@ -193,14 +194,16 @@ RecordEvent::~RecordEvent() {
193
194
PopEvent (name_, dev_ctx_);
194
195
}
195
196
196
- RecordBlock::RecordBlock (int block_id) : start_ns_(PosixInNsec()) {
197
+ RecordBlock::RecordBlock (int block_id)
198
+ : is_enabled_(false ), start_ns_(PosixInNsec()) {
197
199
if (g_state == ProfilerState::kDisabled ) return ;
200
+ is_enabled_ = true ;
198
201
SetCurBlock (block_id);
199
202
name_ = string::Sprintf (" block_%d" , block_id);
200
203
}
201
204
202
205
RecordBlock::~RecordBlock () {
203
- if (g_state == ProfilerState::kDisabled ) return ;
206
+ if (g_state == ProfilerState::kDisabled || !is_enabled_ ) return ;
204
207
DeviceTracer* tracer = GetDeviceTracer ();
205
208
if (tracer) {
206
209
// We try to put all blocks at the same nested depth in the
0 commit comments