trace_to_text: Store thread names
Store the thread names from prev sched switch events
to be used for any other ftrace events with the
same tid in the future.
Bug:119035890
Change-Id: I634cbc40d11215434434e369fdb77797d6fc4531
diff --git a/tools/trace_to_text/ftrace_event_formatter.cc b/tools/trace_to_text/ftrace_event_formatter.cc
index 913188a..2357eef 100644
--- a/tools/trace_to_text/ftrace_event_formatter.cc
+++ b/tools/trace_to_text/ftrace_event_formatter.cc
@@ -3534,13 +3534,21 @@
uint64_t timestamp,
uint32_t cpu,
const protos::FtraceEvent& event,
- const std::unordered_map<uint32_t /*tid*/, uint32_t /*tgid*/>& thread_map) {
+ const std::unordered_map<uint32_t /*tid*/, uint32_t /*tgid*/>& thread_map,
+ std::unordered_map<uint32_t /*tid*/, std::string>& thread_names) {
// Sched_switch events contain the thread name so use that in the prefix.
std::string name;
if (event.has_sched_switch()) {
name = event.sched_switch().prev_comm();
+ thread_names[event.pid()] = event.sched_switch().prev_comm();
} else {
- name = "<...>";
+ // For non sched switch events use name stored from a sched switch event.
+ auto it = thread_names.find(event.pid());
+ if (it != thread_names.end()) {
+ name = it->second;
+ } else {
+ name = "<...>";
+ }
}
std::string line = FormatEventText(event);