diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2023-06-02 22:23:57 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2023-06-02 22:23:57 +0000 |
commit | c039b5cf02687e7eeefd1f02865b67eaa2cb1c56 (patch) | |
tree | bdc4645891f89abd11e0f8dcb89f51dedcbef087 | |
parent | b19afd3d01b26ae513c87e23492cb0c8e7084fa9 (diff) | |
parent | 1bc8ecbb9b94634f8e0f5960e79c3c21c941fa58 (diff) | |
download | extras-c039b5cf02687e7eeefd1f02865b67eaa2cb1c56.tar.gz |
Merge "simpleperf: replace InCloudAndroid() with runtime check." into android11-tests-dev
-rw-r--r-- | simpleperf/cmd_record_test.cpp | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index 50730e22..ffaf649b 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -269,24 +269,10 @@ bool IsInNativeAbi() { return in_native_abi == 1; } -static bool InCloudAndroid() { -#if defined(__i386__) || defined(__x86_64__) -#if defined(__ANDROID__) - std::string prop_value = android::base::GetProperty("ro.build.flavor", ""); - if (android::base::StartsWith(prop_value, "cf_x86_phone") || - android::base::StartsWith(prop_value, "aosp_cf_x86_phone")) { - return true; - } -#endif -#endif - return false; -} - bool HasTracepointEvents() { static int has_tracepoint_events = -1; if (has_tracepoint_events == -1) { - // Cloud Android doesn't support tracepoint events. - has_tracepoint_events = InCloudAndroid() ? 0 : 1; + has_tracepoint_events = (GetTraceFsDir() != nullptr) ? 1 : 0; } return has_tracepoint_events == 1; } @@ -294,9 +280,15 @@ bool HasTracepointEvents() { bool HasHardwareCounter() { static int has_hw_counter = -1; if (has_hw_counter == -1) { - // Cloud Android doesn't have hardware counters. - has_hw_counter = InCloudAndroid() ? 0 : 1; -#if defined(__arm__) + 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); @@ -307,7 +299,7 @@ bool HasHardwareCounter() { has_hw_counter = 0; } } -#endif +#endif // defined(__arm__) } return has_hw_counter == 1; } |