summaryrefslogtreecommitdiff
path: root/simpleperf/app_api
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2020-02-10 17:53:34 -0800
committerYabin Cui <yabinc@google.com>2020-02-12 13:16:16 -0800
commitdc1a475dd3a444a77937f4eaaedb749c82c13c14 (patch)
treea1dfc7d7becd36d0c811b3d3edf2e8b9df06559a /simpleperf/app_api
parent0e3245fdb39ccf2e8a5364084706ce5d6065c5a0 (diff)
downloadextras-dc1a475dd3a444a77937f4eaaedb749c82c13c14.tar.gz
simpleperf: add test to app recording api.
1. Modify app_api code to work with new perf event limit in R. 2. Modify demo code to exit after recording. So they can be used to generate test apks directly. Use cpu-clock in demo code to pass presubmit test. 3. Add api tests in cmd_api_test.cpp. Bug: none Test: run simpleperf_unit_test. Change-Id: I37d786a2f6bdc2af1d807b91796484c58f309e2c
Diffstat (limited to 'simpleperf/app_api')
-rw-r--r--simpleperf/app_api/cpp/simpleperf.cpp10
-rw-r--r--simpleperf/app_api/java/com/android/simpleperf/ProfileSession.java12
2 files changed, 16 insertions, 6 deletions
diff --git a/simpleperf/app_api/cpp/simpleperf.cpp b/simpleperf/app_api/cpp/simpleperf.cpp
index 54b331a3..71216fa0 100644
--- a/simpleperf/app_api/cpp/simpleperf.cpp
+++ b/simpleperf/app_api/cpp/simpleperf.cpp
@@ -359,8 +359,14 @@ std::string ProfileSessionImpl::FindSimpleperfInTempDir() {
if (!RunCmd({"/system/bin/cp", path.c_str(), to_path.c_str()}, nullptr)) {
return "";
}
- // For apps with target sdk >= 29, executing app data file isn't allowed. So test executing it.
- if (!RunCmd({to_path.c_str()}, nullptr)) {
+ // For apps with target sdk >= 29, executing app data file isn't allowed.
+ // For android R, app context isn't allowed to use perf_event_open.
+ // So test executing downloaded simpleperf.
+ std::string s;
+ if (!RunCmd({to_path.c_str(), "list", "sw"}, &s)) {
+ return "";
+ }
+ if (s.find("cpu-clock") == std::string::npos) {
return "";
}
return to_path;
diff --git a/simpleperf/app_api/java/com/android/simpleperf/ProfileSession.java b/simpleperf/app_api/java/com/android/simpleperf/ProfileSession.java
index cb0eac3d..1c512c63 100644
--- a/simpleperf/app_api/java/com/android/simpleperf/ProfileSession.java
+++ b/simpleperf/app_api/java/com/android/simpleperf/ProfileSession.java
@@ -248,12 +248,16 @@ public class ProfileSession {
if (!isExecutableFile(toPath)) {
return null;
}
- // For apps with target sdk >= 29, executing app data file isn't allowed. So test executing
- // it.
+ // For apps with target sdk >= 29, executing app data file isn't allowed.
+ // For android R, app context isn't allowed to use perf_event_open.
+ // So test executing downloaded simpleperf.
try {
- Process process = new ProcessBuilder()
- .command(toPath).start();
+ Process process = new ProcessBuilder().command(toPath + "list sw").start();
process.waitFor();
+ String data = readInputStream(process.getInputStream());
+ if (data.indexOf("cpu-clock") == -1) {
+ return null;
+ }
} catch (Exception e) {
return null;
}