@@ -193,20 +193,27 @@ class DeviceTracerImpl : public DeviceTracer {
193
193
194
194
void AddCPURecords (const char *anno, uint64_t start_ns, uint64_t end_ns) {
195
195
std::lock_guard<std::mutex> l (trace_mu_);
196
- cpu_records_.push_back (
197
- CPURecord{anno, start_ns, end_ns,
198
- std::hash<std::thread::id>{}(std::this_thread::get_id ())});
196
+ cpu_records_.push_back (CPURecord{anno, start_ns, end_ns, 0 });
199
197
}
200
198
201
199
void AddMemRecords (const std::string &name, uint64_t start_ns,
202
200
uint64_t end_ns, uint32_t device_id, uint32_t stream_id,
203
201
uint32_t correlation_id, uint64_t bytes) {
202
+ // 0 means timestamp information could not be collected for the kernel.
203
+ if (start_ns == 0 || end_ns == 0 ) {
204
+ return ;
205
+ }
206
+ std::lock_guard<std::mutex> l (trace_mu_);
204
207
mem_records_.push_back (MemRecord{name, start_ns, end_ns, device_id,
205
208
stream_id, correlation_id, bytes});
206
209
}
207
210
208
211
void AddKernelRecords (uint64_t start, uint64_t end, uint32_t device_id,
209
212
uint32_t stream_id, uint32_t correlation_id) {
213
+ // 0 means timestamp information could not be collected for the kernel.
214
+ if (start == 0 || end == 0 ) {
215
+ return ;
216
+ }
210
217
std::lock_guard<std::mutex> l (trace_mu_);
211
218
kernel_records_.push_back (
212
219
KernelRecord{start, end, device_id, stream_id, correlation_id});
@@ -279,10 +286,10 @@ class DeviceTracerImpl : public DeviceTracer {
279
286
event->set_device_id (r.device_id );
280
287
event->mutable_memcopy ()->set_bytes (r.bytes );
281
288
}
282
- std::string profile_str;
283
- google::protobuf::TextFormat::PrintToString (profile_pb, &profile_str);
284
289
std::ofstream profile_f;
285
290
profile_f.open (profile_path, std::ios::out | std::ios::trunc);
291
+ std::string profile_str;
292
+ profile_pb.SerializeToString (&profile_str);
286
293
profile_f << profile_str;
287
294
profile_f.close ();
288
295
return profile_pb;
0 commit comments