diff options
author | Yabin Cui <yabinc@google.com> | 2024-04-15 16:34:00 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2024-04-15 16:34:00 -0700 |
commit | b68f0f9e32e90a19831160ae3a6699dd972c47bd (patch) | |
tree | 14df0eb445ce71215e72383c085c39ecf48e56f4 /simpleperf | |
parent | 0744f4b1eb07920150f5561dfbcb38fb11b5b89c (diff) | |
download | extras-b68f0f9e32e90a19831160ae3a6699dd972c47bd.tar.gz |
simpleperf: Don't check symbols when getting no samples in emulator
Bug: 328598190
Test: run CtsSimpleperfTestCases
Change-Id: Ic011c16aca7359aa9ecc6140a76d722959aeec83
Diffstat (limited to 'simpleperf')
-rw-r--r-- | simpleperf/cmd_record_test.cpp | 23 | ||||
-rw-r--r-- | simpleperf/test_util.cpp | 15 | ||||
-rw-r--r-- | simpleperf/test_util.h | 2 |
3 files changed, 35 insertions, 5 deletions
diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index 0b5cde9a..131f6da4 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -792,6 +792,11 @@ class RecordingAppHelper { }; ProcessSymbolsInPerfDataFile(GetDataPath(), callback); if (!success) { + if (IsInEmulator() && !HasSample()) { + // In emulator, the monitored app may not have a chance to run. + GTEST_LOG_(INFO) << "No samples are recorded. Skip checking symbols."; + return true; + } DumpData(); } return success; @@ -802,6 +807,24 @@ class RecordingAppHelper { std::string GetDataPath() const { return perf_data_file_.path; } private: + bool HasSample() { + std::unique_ptr<RecordFileReader> reader = RecordFileReader::CreateInstance(GetDataPath()); + if (!reader) { + return false; + } + bool has_sample = false; + auto process_record = [&](std::unique_ptr<Record> r) { + if (r->type() == PERF_RECORD_SAMPLE) { + has_sample = true; + } + return true; + }; + if (!reader->ReadDataSection(process_record)) { + return false; + } + return has_sample; + } + AppHelper app_helper_; TemporaryFile perf_data_file_; }; diff --git a/simpleperf/test_util.cpp b/simpleperf/test_util.cpp index 7e99b5d5..9ac4e46b 100644 --- a/simpleperf/test_util.cpp +++ b/simpleperf/test_util.cpp @@ -117,18 +117,23 @@ static bool HasNonZeroInstructionEventCount() { return false; } +bool IsInEmulator() { + std::string fingerprint = android::base::GetProperty("ro.system.build.fingerprint", ""); + return android::base::StartsWith(fingerprint, "google/sdk_gphone") || + android::base::StartsWith(fingerprint, "google/sdk_gpc") || + android::base::StartsWith(fingerprint, "generic/cf") || + android::base::StartsWith(fingerprint, "generic/aosp_cf"); +} + bool HasHardwareCounter() { static int has_hw_counter = -1; if (has_hw_counter == -1) { has_hw_counter = 1; auto arch = GetTargetArch(); - std::string fingerprint = android::base::GetProperty("ro.system.build.fingerprint", ""); - bool is_emulator = android::base::StartsWith(fingerprint, "google/sdk_gphone") || - android::base::StartsWith(fingerprint, "google/sdk_gpc") || - android::base::StartsWith(fingerprint, "generic/cf"); + bool in_native_abi = IsInNativeAbi() == std::optional(true); - if (arch == ARCH_X86_64 || arch == ARCH_X86_32 || !in_native_abi || is_emulator) { + if (arch == ARCH_X86_64 || arch == ARCH_X86_32 || !in_native_abi || IsInEmulator()) { // 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. diff --git a/simpleperf/test_util.h b/simpleperf/test_util.h index 16483103..4264c9a3 100644 --- a/simpleperf/test_util.h +++ b/simpleperf/test_util.h @@ -201,3 +201,5 @@ class AppHelper { std::vector<std::string> installed_packages_; std::unique_ptr<Workload> app_start_proc_; }; + +bool IsInEmulator(); |