summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-07-31 23:08:58 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-07-31 23:08:58 +0000
commitabee686ee0df393d85bd430013551be4bc8e7531 (patch)
treedd72a84514306c5cc0c9025a1fb9e9e3976ced32
parent992fa2fcf8544a4f9c9b5ec89c49c7c3187892fe (diff)
parentee3097ce79889c5e0bbaec34cda8becebcc9f64f (diff)
downloadextras-abee686ee0df393d85bd430013551be4bc8e7531.tar.gz
Snap for 7600758 from ee3097ce79889c5e0bbaec34cda8becebcc9f64f to sc-d1-release
Change-Id: Ia5ef923e0b273613a9602ef1365e74ab1deb656f
-rw-r--r--simpleperf/test_util.cpp41
1 files changed, 14 insertions, 27 deletions
diff --git a/simpleperf/test_util.cpp b/simpleperf/test_util.cpp
index c2a21960..547eaf90 100644
--- a/simpleperf/test_util.cpp
+++ b/simpleperf/test_util.cpp
@@ -48,29 +48,6 @@ 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") ||
- android::base::StartsWith(prop_value, "cf_x86_64_phone") ||
- android::base::StartsWith(prop_value, "aosp_cf_x86_64_phone")) {
- return true;
- }
- // aosp_x86* builds may also run on cloud Android. Detect it by checking
- /// if cpu-cycles isn't supported.
- if (android::base::StartsWith(prop_value, "aosp_x86")) {
- const simpleperf::EventType* type = simpleperf::FindEventTypeByName("cpu-cycles", false);
- CHECK(type != nullptr);
- perf_event_attr attr = CreateDefaultPerfEventAttr(*type);
- return !IsEventAttrSupported(attr, "cpu-cycles");
- }
-#endif
-#endif
- return false;
-}
-
#if defined(__arm__)
// Check if we can get a non-zero instruction event count by monitoring current thread.
static bool HasNonZeroInstructionEventCount() {
@@ -96,18 +73,28 @@ static bool HasNonZeroInstructionEventCount() {
#endif // defined(__arm__)
bool HasHardwareCounter() {
+#if defined(__linux__)
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 simpleperf::EventType* type = simpleperf::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__)
// For arm32 devices, external non-invasive debug signal controls PMU counters. Once it is
// disabled for security reason, we always get zero values for PMU counters. And we want to
// skip hardware counter tests once we detect it.
has_hw_counter &= HasNonZeroInstructionEventCount() ? 1 : 0;
-#endif
+#endif // defined(__arm__)
}
return has_hw_counter == 1;
+#else // defined(__linux__)
+ return false;
+#endif // defined(__linux__)
}
bool HasPmuCounter() {