From 2cf86e463dea17b98b65753c4bdd0809a9c92415 Mon Sep 17 00:00:00 2001 From: Lalit Maganti Date: Mon, 21 Oct 2024 05:20:33 -0700 Subject: [PATCH] tp: migrate all cpu counter tracks to new track name system Change-Id: I0e36ff253b8946d601061052ba10260ae8bb8e40 --- .../importers/common/track_tracker.cc | 80 ++++++------------- .../importers/ftrace/ftrace_parser.cc | 29 +++++-- .../importers/proto/system_probes_parser.cc | 30 ++++--- .../systrace/systrace_line_parser.cc | 3 +- 4 files changed, 68 insertions(+), 74 deletions(-) diff --git a/src/trace_processor/importers/common/track_tracker.cc b/src/trace_processor/importers/common/track_tracker.cc index e756af4148..253fc14d0c 100644 --- a/src/trace_processor/importers/common/track_tracker.cc +++ b/src/trace_processor/importers/common/track_tracker.cc @@ -65,47 +65,6 @@ const char* GetNameForGroup(TrackTracker::Group group) { PERFETTO_FATAL("For GCC"); } -// This function is added to keep backward compatibility. Don't add new names. -inline std::optional GetCpuCounterTrackName( - TrackClassification type, - uint32_t cpu) { - if (type == TrackClassification::kCpuFrequency) - return "cpufreq"; - if (type == TrackClassification::kCpuFrequencyThrottle) - return "cpufreq_throttle"; - if (type == TrackClassification::kCpuIdle) - return "cpuidle"; - if (type == TrackClassification::kUserTime) - return "cpu.times.user_ns"; - if (type == TrackClassification::kNiceUserTime) - return "cpu.times.user_nice_ns"; - if (type == TrackClassification::kSystemModeTime) - return "cpu.times.system_mode_ns"; - if (type == TrackClassification::kCpuIdleTime) - return "cpu.times.idle_ns"; - if (type == TrackClassification::kIoWaitTime) - return "cpu.times.io_wait_ns"; - if (type == TrackClassification::kIrqTime) - return "cpu.times.irq_ns"; - if (type == TrackClassification::kSoftIrqTime) - return "cpu.times.softirq_ns"; - if (type == TrackClassification::kIrqCounter) - return "num_irq"; - if (type == TrackClassification::kSoftirqCounter) - return "num_softirq"; - if (type == TrackClassification::kCpuUtilization) - return base::StackString<255>("Cpu %u Util", cpu).ToStdString(); - if (type == TrackClassification::kCpuCapacity) - return base::StackString<255>("Cpu %u Cap", cpu).ToStdString(); - if (type == TrackClassification::kCpuNumberRunning) - return base::StackString<255>("Cpu %u Nr Running", cpu).ToStdString(); - if (type == TrackClassification::kCpuMaxFrequencyLimit) - return base::StackString<255>("Cpu %u Max Freq Limit", cpu).ToStdString(); - if (type == TrackClassification::kCpuMinFrequencyLimit) - return base::StackString<255>("Cpu %u Min Freq Limit", cpu).ToStdString(); - return std::nullopt; -} - bool IsLegacyStringIdNameAllowed(TrackClassification classification) { // **DO NOT** add new values here. Use TrackTracker::AutoName instead. return classification == @@ -125,7 +84,23 @@ bool IsLegacyCharArrayNameAllowed(TrackClassification classification) { classification == TrackClassification::kNapiGroCpu || classification == TrackClassification::kFuncgraphCpu || classification == TrackClassification::kMaliIrqCpu || - classification == TrackClassification::kPkvmHypervisor; + classification == TrackClassification::kPkvmHypervisor || + classification == TrackClassification::kCpuFrequency || + classification == TrackClassification::kCpuFrequencyThrottle || + classification == TrackClassification::kCpuIdle || + classification == TrackClassification::kUserTime || + classification == TrackClassification::kSystemModeTime || + classification == TrackClassification::kCpuIdleTime || + classification == TrackClassification::kIoWaitTime || + classification == TrackClassification::kIrqTime || + classification == TrackClassification::kSoftIrqTime || + classification == TrackClassification::kIrqCounter || + classification == TrackClassification::kSoftirqCounter || + classification == TrackClassification::kCpuUtilization || + classification == TrackClassification::kCpuCapacity || + classification == TrackClassification::kCpuNumberRunning || + classification == TrackClassification::kCpuMaxFrequencyLimit || + classification == TrackClassification::kCpuMinFrequencyLimit; } } // namespace @@ -458,20 +433,18 @@ TrackId TrackTracker::LegacyInternGlobalCounterTrack(TrackTracker::Group group, return track; } -TrackId TrackTracker::InternCpuCounterTrack(TrackClassification type, +TrackId TrackTracker::InternCpuCounterTrack(TrackClassification classification, uint32_t cpu, - const TrackName&) { + const TrackName& name) { auto ucpu = context_->cpu_tracker->GetOrCreateCpu(cpu); + StringId name_id = StringIdFromTrackName(classification, name); TrackMapKey key; - key.classification = type; + key.classification = classification; DimensionsBuilder dims_builder = CreateDimensionsBuilder(); dims_builder.AppendUcpu(ucpu); - std::optional maybe_name = GetCpuCounterTrackName(type, cpu); - if (maybe_name) { - dims_builder.AppendName(context_->storage->InternString(*maybe_name)); - } + dims_builder.AppendName(name_id); key.dimensions = std::move(dims_builder).Build(); auto* it = tracks_.Find(key); @@ -479,15 +452,12 @@ TrackId TrackTracker::InternCpuCounterTrack(TrackClassification type, return *it; } - tables::CpuCounterTrackTable::Row row; + tables::CpuCounterTrackTable::Row row(name_id); row.ucpu = ucpu; row.machine_id = context_->machine_id(); - row.classification = - context_->storage->InternString(TrackClassificationToString(type)); + row.classification = context_->storage->InternString( + TrackClassificationToString(classification)); row.dimension_arg_set_id = key.dimensions->arg_set_id; - if (maybe_name) { - row.name = context_->storage->InternString(*maybe_name); - } TrackId track_id = context_->storage->mutable_cpu_counter_track_table()->Insert(row).id; diff --git a/src/trace_processor/importers/ftrace/ftrace_parser.cc b/src/trace_processor/importers/ftrace/ftrace_parser.cc index 78cf3acf91..69974de4ff 100644 --- a/src/trace_processor/importers/ftrace/ftrace_parser.cc +++ b/src/trace_processor/importers/ftrace/ftrace_parser.cc @@ -1680,7 +1680,8 @@ void FtraceParser::ParseCpuFreq(int64_t timestamp, ConstBytes blob) { uint32_t cpu = freq.cpu_id(); uint32_t new_freq_khz = freq.state(); TrackId track = context_->track_tracker->InternCpuCounterTrack( - TrackClassification::kCpuFrequency, cpu); + TrackClassification::kCpuFrequency, cpu, + TrackTracker::LegacyCharArrayName{"cpufreq"}); context_->event_tracker->PushCounter(timestamp, new_freq_khz, track); } @@ -1689,7 +1690,8 @@ void FtraceParser::ParseCpuFreqThrottle(int64_t timestamp, ConstBytes blob) { uint32_t cpu = static_cast(freq.cpu()); double new_freq_khz = static_cast(freq.freq()); TrackId track = context_->track_tracker->InternCpuCounterTrack( - TrackClassification::kCpuFrequencyThrottle, cpu); + TrackClassification::kCpuFrequencyThrottle, cpu, + TrackTracker::LegacyCharArrayName{"cpufreq_throttle"}); context_->event_tracker->PushCounter(timestamp, new_freq_khz, track); } @@ -1718,7 +1720,8 @@ void FtraceParser::ParseCpuIdle(int64_t timestamp, ConstBytes blob) { uint32_t cpu = idle.cpu_id(); uint32_t new_state = idle.state(); TrackId track = context_->track_tracker->InternCpuCounterTrack( - TrackClassification::kCpuIdle, cpu); + TrackClassification::kCpuIdle, cpu, + TrackTracker::LegacyCharArrayName{"cpuidle"}); context_->event_tracker->PushCounter(timestamp, new_state, track); } @@ -2929,12 +2932,16 @@ void FtraceParser::ParseCpuFrequencyLimits(int64_t timestamp, blob.size); TrackId max_track = context_->track_tracker->InternCpuCounterTrack( - TrackClassification::kCpuMaxFrequencyLimit, evt.cpu_id()); + TrackClassification::kCpuMaxFrequencyLimit, evt.cpu_id(), + TrackTracker::LegacyCharArrayName{ + base::StackString<255>("Cpu %u Max Freq Limit", evt.cpu_id())}); context_->event_tracker->PushCounter( timestamp, static_cast(evt.max_freq()), max_track); TrackId min_track = context_->track_tracker->InternCpuCounterTrack( - TrackClassification::kCpuMinFrequencyLimit, evt.cpu_id()); + TrackClassification::kCpuMinFrequencyLimit, evt.cpu_id(), + TrackTracker::LegacyCharArrayName{ + base::StackString<255>("Cpu %u Min Freq Limit", evt.cpu_id())}); context_->event_tracker->PushCounter( timestamp, static_cast(evt.min_freq()), min_track); } @@ -3498,17 +3505,23 @@ void FtraceParser::ParseSchedCpuUtilCfs(int64_t timestamp, protozero::ConstBytes blob) { protos::pbzero::SchedCpuUtilCfsFtraceEvent::Decoder evt(blob.data, blob.size); TrackId util_track = context_->track_tracker->InternCpuCounterTrack( - TrackClassification::kCpuUtilization, evt.cpu()); + TrackClassification::kCpuUtilization, evt.cpu(), + TrackTracker::LegacyCharArrayName{ + base::StackString<255>("Cpu %u Util", evt.cpu())}); context_->event_tracker->PushCounter( timestamp, static_cast(evt.cpu_util()), util_track); TrackId cap_track = context_->track_tracker->InternCpuCounterTrack( - TrackClassification::kCpuCapacity, evt.cpu()); + TrackClassification::kCpuCapacity, evt.cpu(), + TrackTracker::LegacyCharArrayName{ + base::StackString<255>("Cpu %u Cap", evt.cpu())}); context_->event_tracker->PushCounter( timestamp, static_cast(evt.capacity()), cap_track); TrackId nrr_track = context_->track_tracker->InternCpuCounterTrack( - TrackClassification::kCpuNumberRunning, evt.cpu()); + TrackClassification::kCpuNumberRunning, evt.cpu(), + TrackTracker::LegacyCharArrayName{ + base::StackString<255>("Cpu %u Nr Running", evt.cpu())}); context_->event_tracker->PushCounter( timestamp, static_cast(evt.nr_running()), nrr_track); } diff --git a/src/trace_processor/importers/proto/system_probes_parser.cc b/src/trace_processor/importers/proto/system_probes_parser.cc index ca5e1db062..f3508eac7e 100644 --- a/src/trace_processor/importers/proto/system_probes_parser.cc +++ b/src/trace_processor/importers/proto/system_probes_parser.cc @@ -350,7 +350,8 @@ void SystemProbesParser::ParseSysStats(int64_t ts, ConstBytes blob) { uint32_t c = 0; for (auto it = sys_stats.cpufreq_khz(); it; ++it, ++c) { TrackId track = context_->track_tracker->InternCpuCounterTrack( - TrackClassification::kCpuFrequency, c); + TrackClassification::kCpuFrequency, c, + TrackTracker::LegacyCharArrayName{"cpufreq"}); context_->event_tracker->PushCounter(ts, static_cast(*it), track); } @@ -377,37 +378,44 @@ void SystemProbesParser::ParseSysStats(int64_t ts, ConstBytes blob) { } TrackId track = context_->track_tracker->InternCpuCounterTrack( - TrackClassification::kUserTime, ct.cpu_id()); + TrackClassification::kUserTime, ct.cpu_id(), + TrackTracker::LegacyCharArrayName{"cpu.times.user_ns"}); context_->event_tracker->PushCounter(ts, static_cast(ct.user_ns()), track); track = context_->track_tracker->InternCpuCounterTrack( - TrackClassification::kNiceUserTime, ct.cpu_id()); + TrackClassification::kNiceUserTime, ct.cpu_id(), + TrackTracker::LegacyCharArrayName{"cpu.times.user_nice_ns"}); context_->event_tracker->PushCounter( ts, static_cast(ct.user_nice_ns()), track); track = context_->track_tracker->InternCpuCounterTrack( - TrackClassification::kSystemModeTime, ct.cpu_id()); + TrackClassification::kSystemModeTime, ct.cpu_id(), + TrackTracker::LegacyCharArrayName{"cpu.times.system_mode_ns"}); context_->event_tracker->PushCounter( ts, static_cast(ct.system_mode_ns()), track); track = context_->track_tracker->InternCpuCounterTrack( - TrackClassification::kCpuIdleTime, ct.cpu_id()); + TrackClassification::kCpuIdleTime, ct.cpu_id(), + TrackTracker::LegacyCharArrayName{"cpu.times.idle_ns"}); context_->event_tracker->PushCounter(ts, static_cast(ct.idle_ns()), track); track = context_->track_tracker->InternCpuCounterTrack( - TrackClassification::kIoWaitTime, ct.cpu_id()); + TrackClassification::kIoWaitTime, ct.cpu_id(), + TrackTracker::LegacyCharArrayName{"cpu.times.io_wait_ns"}); context_->event_tracker->PushCounter( ts, static_cast(ct.io_wait_ns()), track); track = context_->track_tracker->InternCpuCounterTrack( - TrackClassification::kIrqTime, ct.cpu_id()); + TrackClassification::kIrqTime, ct.cpu_id(), + TrackTracker::LegacyCharArrayName{"cpu.times.irq_ns"}); context_->event_tracker->PushCounter(ts, static_cast(ct.irq_ns()), track); track = context_->track_tracker->InternCpuCounterTrack( - TrackClassification::kSoftIrqTime, ct.cpu_id()); + TrackClassification::kSoftIrqTime, ct.cpu_id(), + TrackTracker::LegacyCharArrayName{"cpu.times.softirq_ns"}); context_->event_tracker->PushCounter( ts, static_cast(ct.softirq_ns()), track); } @@ -415,7 +423,8 @@ void SystemProbesParser::ParseSysStats(int64_t ts, ConstBytes blob) { for (auto it = sys_stats.num_irq(); it; ++it) { protos::pbzero::SysStats::InterruptCount::Decoder ic(*it); TrackId track = context_->track_tracker->InternSingleDimensionTrack( - TrackClassification::kIrqCounter, irq_id_, Variadic::Integer(ic.irq())); + TrackClassification::kIrqCounter, irq_id_, Variadic::Integer(ic.irq()), + TrackTracker::LegacyCharArrayName{"num_irq"}); context_->event_tracker->PushCounter(ts, static_cast(ic.count()), track); } @@ -424,7 +433,8 @@ void SystemProbesParser::ParseSysStats(int64_t ts, ConstBytes blob) { protos::pbzero::SysStats::InterruptCount::Decoder ic(*it); TrackId track = context_->track_tracker->InternSingleDimensionTrack( TrackClassification::kSoftirqCounter, irq_id_, - Variadic::Integer(ic.irq())); + Variadic::Integer(ic.irq()), + TrackTracker::LegacyCharArrayName{"num_softirq"}); context_->event_tracker->PushCounter(ts, static_cast(ic.count()), track); } diff --git a/src/trace_processor/importers/systrace/systrace_line_parser.cc b/src/trace_processor/importers/systrace/systrace_line_parser.cc index a228f133cf..863cb069e2 100644 --- a/src/trace_processor/importers/systrace/systrace_line_parser.cc +++ b/src/trace_processor/importers/systrace/systrace_line_parser.cc @@ -137,7 +137,8 @@ util::Status SystraceLineParser::ParseLine(const SystraceLine& line) { } TrackId track = context_->track_tracker->InternCpuCounterTrack( - TrackClassification::kCpuFrequency, event_cpu.value()); + TrackClassification::kCpuFrequency, event_cpu.value(), + TrackTracker::LegacyCharArrayName{"cpufreq"}); context_->event_tracker->PushCounter(line.ts, new_state.value(), track); } else if (line.event_name == "cpu_idle") { std::optional event_cpu = base::StringToUInt32(args["cpu_id"]);