summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2018-01-08 11:13:52 -0800
committerYabin Cui <yabinc@google.com>2018-01-08 11:22:48 -0800
commitb00b37dbee4bc1c0633ff0891b939200b32218d0 (patch)
tree5a239974fd61c21cb0ea4d1cc6a8d51f49acdbf4
parentc43ab84678e24f486c6f0c6e5390fcaa97189eb4 (diff)
downloadextras-b00b37dbee4bc1c0633ff0891b939200b32218d0.tar.gz
simpleperf: stop recording when app exits.
Bug: http://b/71708104 Test: run test.py. Change-Id: I06ff0cb4feb046a7e66cea4640e3cbbd71cbb86d
-rw-r--r--simpleperf/cmd_record.cpp1
-rw-r--r--simpleperf/scripts/test.py26
2 files changed, 17 insertions, 10 deletions
diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp
index f3d45f79..26070541 100644
--- a/simpleperf/cmd_record.cpp
+++ b/simpleperf/cmd_record.cpp
@@ -391,6 +391,7 @@ bool RecordCommand::PrepareRecording(Workload* workload) {
// app process. In this way, we can have a better support of app start-up time profiling.
std::set<pid_t> pids = WaitForAppProcesses(app_package_name_);
event_selection_set_.AddMonitoredProcesses(pids);
+ need_to_check_targets = true;
} else {
LOG(ERROR)
<< "No threads to monitor. Try `simpleperf help record` for help";
diff --git a/simpleperf/scripts/test.py b/simpleperf/scripts/test.py
index e44337bf..0452c09b 100644
--- a/simpleperf/scripts/test.py
+++ b/simpleperf/scripts/test.py
@@ -43,8 +43,9 @@ import sys
import tempfile
import time
import unittest
-from utils import *
+
from simpleperf_report_lib import ReportLib
+from utils import *
has_google_protobuf = True
try:
@@ -365,16 +366,10 @@ class TestExamplePureJava(TestExampleBase):
def test_app_profiler_with_ctrl_c(self):
if is_windows():
return
- # `adb root` and `adb unroot` may consumes more time than 3 sec. So
- # do it in advance to make sure ctrl-c happens when recording.
- if self.adb_root:
- self.adb.switch_to_root()
- else:
- self.adb._unroot()
+ self.adb.check_run(['shell', 'am', 'start', '-n', self.package_name + '/.MainActivity'])
+ time.sleep(1)
args = [sys.executable, "app_profiler.py", "--app", self.package_name,
- "-r", "--duration 10000", "-nc"]
- if not self.adb_root:
- args.append("--disable_adb_root")
+ "-r", "--duration 10000", "-nc", "--disable_adb_root"]
subproc = subprocess.Popen(args)
time.sleep(3)
@@ -383,6 +378,17 @@ class TestExamplePureJava(TestExampleBase):
self.assertEqual(subproc.returncode, 0)
self.run_cmd(["report.py"])
+ def test_app_profiler_stop_after_app_exit(self):
+ self.adb.check_run(['shell', 'am', 'start', '-n', self.package_name + '/.MainActivity'])
+ time.sleep(1)
+ subproc = subprocess.Popen([sys.executable, 'app_profiler.py', '--app', self.package_name,
+ '-r', '--duration 10000', '-nc', '--disable_adb_root'])
+ time.sleep(3)
+ self.adb.check_run(['shell', 'am', 'force-stop', self.package_name])
+ subproc.wait()
+ self.assertEqual(subproc.returncode, 0)
+ self.run_cmd(["report.py"])
+
def test_report(self):
self.common_test_report()
self.run_cmd(["report.py", "-g", "-o", "report.txt"])