summaryrefslogtreecommitdiff
path: root/simpleperf
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2024-04-16 03:10:51 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-04-16 03:10:51 +0000
commit21f7cd36e46c910b8d7f15748ceb5ed12416e1c0 (patch)
tree53f95485e9acd1fd17ff5e98f1eae91663e37b12 /simpleperf
parentbda10da0122e011638df7de725869ad834ae5bd2 (diff)
parentb68f0f9e32e90a19831160ae3a6699dd972c47bd (diff)
downloadextras-21f7cd36e46c910b8d7f15748ceb5ed12416e1c0.tar.gz
Merge "simpleperf: Don't check symbols when getting no samples in emulator" into main
Diffstat (limited to 'simpleperf')
-rw-r--r--simpleperf/cmd_record_test.cpp23
-rw-r--r--simpleperf/test_util.cpp15
-rw-r--r--simpleperf/test_util.h2
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();