diff options
author | Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> | 2023-06-09 21:00:04 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2023-06-09 21:00:04 +0000 |
commit | 86f86677d38008c9756c3c09d4036bd1baa17aac (patch) | |
tree | 9925dc63fbb3814b2857236220d32b3552ec4a3c | |
parent | c039b5cf02687e7eeefd1f02865b67eaa2cb1c56 (diff) | |
parent | f232ffbd6f4d97dd6d086bc96d0f0075c83d0fa9 (diff) | |
download | extras-86f86677d38008c9756c3c09d4036bd1baa17aac.tar.gz |
Merge "simpleperf: Check hardware counter dynamically in non-native ABIs" into android11-tests-devandroid11-tests-dev
-rw-r--r-- | simpleperf/cmd_record_test.cpp | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index ffaf649b..7583bc50 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -281,25 +281,27 @@ bool HasHardwareCounter() { static int has_hw_counter = -1; if (has_hw_counter == -1) { has_hw_counter = 1; -#if defined(__x86__) || defined(__x86_64__) - // On x86 and x86_64, it's likely to run on an emulator or vm without hardware perf counters. - // It's hard to enumerate them all. So check the support at runtime. - const EventType* type = FindEventTypeByName("cpu-cycles", false); - CHECK(type != nullptr); - perf_event_attr attr = CreateDefaultPerfEventAttr(*type); - has_hw_counter = IsEventAttrSupported(attr, "cpu-cycles") ? 1 : 0; -#elif defined(__arm__) - std::string cpu_info; - if (android::base::ReadFileToString("/proc/cpuinfo", &cpu_info)) { - std::string hardware = GetHardwareFromCpuInfo(cpu_info); - if (std::regex_search(hardware, std::regex(R"(i\.MX6.*Quad)")) || - std::regex_search(hardware, std::regex(R"(SC7731e)")) || - std::regex_search(hardware, std::regex(R"(Qualcomm Technologies, Inc MSM8909)")) || - std::regex_search(hardware, std::regex(R"(Broadcom STB \(Flattened Device Tree\))"))) { - has_hw_counter = 0; + auto arch = GetBuildArch(); + if (arch == ARCH_X86_64 || arch == ARCH_X86_32 || !IsInNativeAbi()) { + // On x86 and x86_64, or when we are not in native abi, it's likely to run on an emulator or + // vm without hardware perf counters. It's hard to enumerate them all. So check the support + // at runtime. + const EventType* type = FindEventTypeByName("cpu-cycles", false); + CHECK(type != nullptr); + perf_event_attr attr = CreateDefaultPerfEventAttr(*type); + has_hw_counter = IsEventAttrSupported(attr, "cpu-cycles") ? 1 : 0; + } else if (arch == ARCH_ARM) { + std::string cpu_info; + if (android::base::ReadFileToString("/proc/cpuinfo", &cpu_info)) { + std::string hardware = GetHardwareFromCpuInfo(cpu_info); + if (std::regex_search(hardware, std::regex(R"(i\.MX6.*Quad)")) || + std::regex_search(hardware, std::regex(R"(SC7731e)")) || + std::regex_search(hardware, std::regex(R"(Qualcomm Technologies, Inc MSM8909)")) || + std::regex_search(hardware, std::regex(R"(Broadcom STB \(Flattened Device Tree\))"))) { + has_hw_counter = 0; + } } } -#endif // defined(__arm__) } return has_hw_counter == 1; } |