summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-06 20:17:35 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2023-07-06 20:17:35 +0000
commit611c263798909aa85f4aab2167f199e0d664b6da (patch)
tree9925dc63fbb3814b2857236220d32b3552ec4a3c
parentc82db66d9e28ca5d465755adb5eafc8628dc008b (diff)
parent83437f0c2408d0d4c9b2822c2c63630cd6a87ed1 (diff)
downloadextras-android11-tests-release.tar.gz
Merge "Snap for 10442607 from 86f86677d38008c9756c3c09d4036bd1baa17aac to android11-tests-release" into android11-tests-releaseandroid-vts-11.0_r16android-vts-11.0_r15android-vts-11.0_r14android-vts-11.0_r13android-cts-11.0_r16android-cts-11.0_r15android-cts-11.0_r14android-cts-11.0_r13android11-tests-release
-rw-r--r--simpleperf/cmd_record_test.cpp48
-rw-r--r--simpleperf/environment.cpp5
2 files changed, 24 insertions, 29 deletions
diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp
index 50730e22..7583bc50 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,20 +280,28 @@ 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__)
- 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;
+ has_hw_counter = 1;
+ 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
}
return has_hw_counter == 1;
}
diff --git a/simpleperf/environment.cpp b/simpleperf/environment.cpp
index 5b2fcaa8..4cc47914 100644
--- a/simpleperf/environment.cpp
+++ b/simpleperf/environment.cpp
@@ -388,9 +388,10 @@ bool SetPerfEventLimits(uint64_t sample_freq, size_t cpu_percent, uint64_t mlock
}
// Wait for init process to change perf event limits based on properties.
const size_t max_wait_us = 3 * 1000000;
+ const size_t interval_us = 10000;
int finish_mask = 0;
- for (size_t i = 0; i < max_wait_us && finish_mask != 7; ++i) {
- usleep(1); // Wait 1us to avoid busy loop.
+ for (size_t i = 0; i < max_wait_us && finish_mask != 7; i += interval_us) {
+ usleep(interval_us); // Wait 10ms to avoid busy loop.
if ((finish_mask & 1) == 0) {
uint64_t freq;
if (!GetMaxSampleFrequency(&freq) || freq == sample_freq) {