diff options
author | Yabin Cui <yabinc@google.com> | 2020-02-10 17:53:34 -0800 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2020-02-12 13:16:16 -0800 |
commit | dc1a475dd3a444a77937f4eaaedb749c82c13c14 (patch) | |
tree | a1dfc7d7becd36d0c811b3d3edf2e8b9df06559a /simpleperf/app_api | |
parent | 0e3245fdb39ccf2e8a5364084706ce5d6065c5a0 (diff) | |
download | extras-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.cpp | 10 | ||||
-rw-r--r-- | simpleperf/app_api/java/com/android/simpleperf/ProfileSession.java | 12 |
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; } |