From 71681bd6914fed82dabfca3518772b141b1b0cd7 Mon Sep 17 00:00:00 2001 From: Jose Baiocchi Date: Mon, 2 Dec 2019 16:09:38 -0800 Subject: [PATCH] Only save per-thread events when non-empty PiperOrigin-RevId: 283439027 Change-Id: I33118a45a69fff30b3c29d927c8a8380536dd1af --- tensorflow/core/profiler/internal/traceme_recorder.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tensorflow/core/profiler/internal/traceme_recorder.cc b/tensorflow/core/profiler/internal/traceme_recorder.cc index d191a49fc94..3257a347d66 100644 --- a/tensorflow/core/profiler/internal/traceme_recorder.cc +++ b/tensorflow/core/profiler/internal/traceme_recorder.cc @@ -199,7 +199,9 @@ void TraceMeRecorder::RegisterThread(int32 tid, ThreadLocalRecorder* thread) { void TraceMeRecorder::UnregisterThread(TraceMeRecorder::ThreadEvents&& events) { mutex_lock lock(mutex_); threads_.erase(events.thread.tid); - orphaned_events_.push_back(std::move(events)); + if (!events.events.empty()) { + orphaned_events_.push_back(std::move(events)); + } } // This method is performance critical and should be kept fast. It is called @@ -211,7 +213,10 @@ TraceMeRecorder::Events TraceMeRecorder::Clear() { std::swap(orphaned_events_, result); for (const auto& entry : threads_) { auto* recorder = entry.second; - result.push_back(recorder->Clear()); + TraceMeRecorder::ThreadEvents events = recorder->Clear(); + if (!events.events.empty()) { + result.push_back(std::move(events)); + } } return result; }