diff options
author | Yabin Cui <yabinc@google.com> | 2017-08-02 14:00:01 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2017-08-02 15:34:44 -0700 |
commit | 1dafb1a92d990811c1fa9b94a0ac51014c3a685a (patch) | |
tree | d5f94444de713ae76978f03875a61b802b75f26e | |
parent | 76163e6103d6854b89f4916772a838573657e34a (diff) | |
download | extras-1dafb1a92d990811c1fa9b94a0ac51014c3a685a.tar.gz |
simpleperf: fix supporting ctrl-c when using `adb shell simpleperf xxx`.
Also fix a problem that binary_cache_builder.py tries to pull /dev/zero.
Bug: None.
Test: run test.py TestExamplePureJava.test_app_profiler_with_ctrl_c.
Change-Id: Ie99af6795bb1e81ae6e93f8b7a8907d49c048694
-rw-r--r-- | simpleperf/cmd_record.cpp | 5 | ||||
-rw-r--r-- | simpleperf/scripts/binary_cache_builder.py | 2 | ||||
-rw-r--r-- | simpleperf/scripts/test.py | 15 |
3 files changed, 21 insertions, 1 deletions
diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp index bb1fc0f7..493f094d 100644 --- a/simpleperf/cmd_record.cpp +++ b/simpleperf/cmd_record.cpp @@ -186,6 +186,11 @@ class RecordCommand : public Command { exclude_kernel_callchain_(false) { // Stop profiling if parent exits. prctl(PR_SET_PDEATHSIG, SIGHUP, 0, 0, 0); + // If we run `adb shell simpleperf record xxx` and stop profiling by ctrl-c, adb closes + // sockets connecting simpleperf. After that, simpleperf will receive SIGPIPE when writing + // to stdout/stderr, which is a problem when we use '--app' option. So ignore SIGPIPE to + // finish properly. + signal(SIGPIPE, SIG_IGN); app_package_name_ = GetDefaultAppPackageName(); } diff --git a/simpleperf/scripts/binary_cache_builder.py b/simpleperf/scripts/binary_cache_builder.py index 546f76b2..72c1c12c 100644 --- a/simpleperf/scripts/binary_cache_builder.py +++ b/simpleperf/scripts/binary_cache_builder.py @@ -147,7 +147,7 @@ class BinaryCacheBuilder(object): """pull binaries needed in perf.data to binary_cache.""" for binary in self.binaries: build_id = self.binaries[binary] - if binary[0] != '/' or binary == "//anon": + if binary[0] != '/' or binary == "//anon" or binary.startswith("/dev/"): # [kernel.kallsyms] or unknown, or something we can't find binary. continue binary_cache_file = binary[1:].replace('/', os.sep) diff --git a/simpleperf/scripts/test.py b/simpleperf/scripts/test.py index 491e897e..85215480 100644 --- a/simpleperf/scripts/test.py +++ b/simpleperf/scripts/test.py @@ -37,8 +37,10 @@ Test using both `adb root` and `adb unroot`. import os import re import shutil +import signal import sys import tempfile +import time import unittest from utils import * from simpleperf_report_lib import ReportLib @@ -279,6 +281,19 @@ class TestExamplePureJava(TestExampleBase): def test_app_profiler(self): self.common_test_app_profiler() + def test_app_profiler_with_ctrl_c(self): + if is_windows(): + return + args = [sys.executable, "app_profiler.py", "--app", self.package_name, + "-r", "--duration 10000", "-nc"] + subproc = subprocess.Popen(args) + time.sleep(3) + + subproc.send_signal(signal.SIGINT) + 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"]) |