Skip to content

Commit

Permalink
tp: migrate all cpu counter tracks to new track name system
Browse files Browse the repository at this point in the history
Change-Id: I0e36ff253b8946d601061052ba10260ae8bb8e40
  • Loading branch information
LalitMaganti committed Oct 21, 2024
1 parent cc724c2 commit 2cf86e4
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 74 deletions.
80 changes: 25 additions & 55 deletions src/trace_processor/importers/common/track_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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 ==
Expand All @@ -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
Expand Down Expand Up @@ -458,36 +433,31 @@ 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<std::string> 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);
if (it) {
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;
Expand Down
29 changes: 21 additions & 8 deletions src/trace_processor/importers/ftrace/ftrace_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -1689,7 +1690,8 @@ void FtraceParser::ParseCpuFreqThrottle(int64_t timestamp, ConstBytes blob) {
uint32_t cpu = static_cast<uint32_t>(freq.cpu());
double new_freq_khz = static_cast<double>(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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<double>(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<double>(evt.min_freq()), min_track);
}
Expand Down Expand Up @@ -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<double>(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<double>(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<double>(evt.nr_running()), nrr_track);
}
Expand Down
30 changes: 20 additions & 10 deletions src/trace_processor/importers/proto/system_probes_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(*it), track);
}

Expand All @@ -377,45 +378,53 @@ 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<double>(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<double>(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<double>(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<double>(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<double>(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<double>(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<double>(ct.softirq_ns()), track);
}

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<double>(ic.count()),
track);
}
Expand All @@ -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<double>(ic.count()),
track);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t> event_cpu = base::StringToUInt32(args["cpu_id"]);
Expand Down

0 comments on commit 2cf86e4

Please sign in to comment.