diff options
author | Yabin Cui <yabinc@google.com> | 2022-08-25 10:51:11 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2022-08-29 14:14:15 -0700 |
commit | 9f3c6f5ba4e45ea1564b8d8fd5b2f9b6f59a285c (patch) | |
tree | c95c2ff88c3bfc772d793bb1e0ab5e54adf85fc7 | |
parent | 94ab56bd749f5ed15cd4745bc143e3b01dbf2242 (diff) | |
download | extras-9f3c6f5ba4e45ea1564b8d8fd5b2f9b6f59a285c.tar.gz |
simpleperf: accept failures when getting hw counters on a cpu.
When built as a 32-bit program, simpleperf can't set sched_affinity
to a 64-bit only CPU. That can make simpleperf not be able to get
hardware counters on that CPU.
Bug: 243065368
Bug: 243479304
Test: run simpleperf_unit_test
Change-Id: I0eb2841e191e88a96eeae53ec95b265db194cfd8
(cherry picked from commit 5aded99e9925531836b0e2b511b1448b4d64785e)
-rw-r--r-- | simpleperf/cmd_stat.cpp | 14 | ||||
-rw-r--r-- | simpleperf/workload.cpp | 2 |
2 files changed, 9 insertions, 7 deletions
diff --git a/simpleperf/cmd_stat.cpp b/simpleperf/cmd_stat.cpp index f4df9b67..bd2cc5e3 100644 --- a/simpleperf/cmd_stat.cpp +++ b/simpleperf/cmd_stat.cpp @@ -433,7 +433,7 @@ class StatCommand : public Command { private: bool ParseOptions(const std::vector<std::string>& args, std::vector<std::string>* non_option_args); - bool PrintHardwareCounters(); + void PrintHardwareCounters(); bool AddDefaultMeasuredEventTypes(); void SetEventSelectionFlags(); void MonitorEachThread(); @@ -480,7 +480,8 @@ bool StatCommand::Run(const std::vector<std::string>& args) { return false; } if (print_hw_counter_) { - return PrintHardwareCounters(); + PrintHardwareCounters(); + return true; } if (!app_package_name_.empty() && !in_app_context_) { if (!IsRoot()) { @@ -793,16 +794,17 @@ std::optional<size_t> GetHardwareCountersOnCpu(int cpu) { return available_counters; } -bool StatCommand::PrintHardwareCounters() { +void StatCommand::PrintHardwareCounters() { for (int cpu : GetOnlineCpus()) { std::optional<size_t> counters = GetHardwareCountersOnCpu(cpu); if (!counters) { - LOG(ERROR) << "failed to get CPU PMU hardware counters on cpu " << cpu; - return false; + // When built as a 32-bit program, we can't set sched_affinity to a 64-bit only CPU. So we + // may not be able to get hardware counters on that CPU. + LOG(WARNING) << "Failed to get CPU PMU hardware counters on cpu " << cpu; + continue; } printf("There are %zu CPU PMU hardware counters available on cpu %d.\n", counters.value(), cpu); } - return true; } bool StatCommand::AddDefaultMeasuredEventTypes() { diff --git a/simpleperf/workload.cpp b/simpleperf/workload.cpp index 142ed713..92c6537b 100644 --- a/simpleperf/workload.cpp +++ b/simpleperf/workload.cpp @@ -167,7 +167,7 @@ bool Workload::SetCpuAffinity(int cpu) { CPU_ZERO(&mask); CPU_SET(cpu, &mask); if (sched_setaffinity(GetPid(), sizeof(mask), &mask) != 0) { - PLOG(ERROR) << "sched_setaffinity failed"; + PLOG(WARNING) << "sched_setaffinity failed"; return false; } return true; |