@@ -199,20 +199,29 @@ class DeviceTracerImpl : public DeviceTracer {
199
199
return ;
200
200
}
201
201
std::lock_guard<std::mutex> l (trace_mu_);
202
- cpu_records_.push_back (
203
- CPURecord{anno, start_ns, end_ns,
204
- std::hash<std::thread::id>{}(std::this_thread::get_id ())});
202
+ cpu_records_.push_back (CPURecord{anno, start_ns, end_ns, 0 });
205
203
}
206
204
207
205
void AddMemRecords (const std::string &name, uint64_t start_ns,
208
206
uint64_t end_ns, uint32_t device_id, uint32_t stream_id,
209
207
uint32_t correlation_id, uint64_t bytes) {
208
+ // 0 means timestamp information could not be collected for the kernel.
209
+ if (start_ns == 0 || end_ns == 0 ) {
210
+ VLOG (3 ) << name << " cannot be traced" ;
211
+ return ;
212
+ }
213
+ std::lock_guard<std::mutex> l (trace_mu_);
210
214
mem_records_.push_back (MemRecord{name, start_ns, end_ns, device_id,
211
215
stream_id, correlation_id, bytes});
212
216
}
213
217
214
218
void AddKernelRecords (uint64_t start, uint64_t end, uint32_t device_id,
215
219
uint32_t stream_id, uint32_t correlation_id) {
220
+ // 0 means timestamp information could not be collected for the kernel.
221
+ if (start == 0 || end == 0 ) {
222
+ VLOG (3 ) << correlation_id << " cannot be traced" ;
223
+ return ;
224
+ }
216
225
std::lock_guard<std::mutex> l (trace_mu_);
217
226
kernel_records_.push_back (
218
227
KernelRecord{start, end, device_id, stream_id, correlation_id});
@@ -285,10 +294,10 @@ class DeviceTracerImpl : public DeviceTracer {
285
294
event->set_device_id (r.device_id );
286
295
event->mutable_memcopy ()->set_bytes (r.bytes );
287
296
}
288
- std::string profile_str;
289
- google::protobuf::TextFormat::PrintToString (profile_pb, &profile_str);
290
297
std::ofstream profile_f;
291
298
profile_f.open (profile_path, std::ios::out | std::ios::trunc);
299
+ std::string profile_str;
300
+ profile_pb.SerializeToString (&profile_str);
292
301
profile_f << profile_str;
293
302
profile_f.close ();
294
303
return profile_pb;
0 commit comments