Skip to content

Commit cf6244c

Browse files
committed
Improve profiler
smaller binary proto avoid untrackable kernel
1 parent c7b7291 commit cf6244c

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

paddle/fluid/platform/device_tracer.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,27 @@ class DeviceTracerImpl : public DeviceTracer {
193193

194194
void AddCPURecords(const char *anno, uint64_t start_ns, uint64_t end_ns) {
195195
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});
199197
}
200198

201199
void AddMemRecords(const std::string &name, uint64_t start_ns,
202200
uint64_t end_ns, uint32_t device_id, uint32_t stream_id,
203201
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_);
204207
mem_records_.push_back(MemRecord{name, start_ns, end_ns, device_id,
205208
stream_id, correlation_id, bytes});
206209
}
207210

208211
void AddKernelRecords(uint64_t start, uint64_t end, uint32_t device_id,
209212
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+
}
210217
std::lock_guard<std::mutex> l(trace_mu_);
211218
kernel_records_.push_back(
212219
KernelRecord{start, end, device_id, stream_id, correlation_id});
@@ -279,10 +286,10 @@ class DeviceTracerImpl : public DeviceTracer {
279286
event->set_device_id(r.device_id);
280287
event->mutable_memcopy()->set_bytes(r.bytes);
281288
}
282-
std::string profile_str;
283-
google::protobuf::TextFormat::PrintToString(profile_pb, &profile_str);
284289
std::ofstream profile_f;
285290
profile_f.open(profile_path, std::ios::out | std::ios::trunc);
291+
std::string profile_str;
292+
profile_pb.SerializeToString(&profile_str);
286293
profile_f << profile_str;
287294
profile_f.close();
288295
return profile_pb;

paddle/fluid/platform/profiler.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License. */
1515
syntax = "proto2";
1616
package paddle.platform.proto;
1717

18-
message MemCopy { optional uint64 bytes = 3; }
18+
message MemCopy { optional uint64 bytes = 1; }
1919

2020
message Event {
2121
optional string name = 1;

tools/timeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def generate_chrome_trace(self):
159159
with open(profile_path, 'r') as f:
160160
profile_s = f.read()
161161
profile_pb = profiler_pb2.Profile()
162-
text_format.Merge(profile_s, profile_pb)
162+
profile_pb.ParseFromString(profile_s)
163163

164164
tl = Timeline(profile_pb)
165165
with open(timeline_path, 'w') as f:

0 commit comments

Comments
 (0)