OSDN Git Service

simpleperf: fix supporting ctrl-c when using `adb shell simpleperf xxx`.
authorYabin Cui <yabinc@google.com>
Wed, 2 Aug 2017 21:00:01 +0000 (14:00 -0700)
committerYabin Cui <yabinc@google.com>
Wed, 2 Aug 2017 22:34:44 +0000 (15:34 -0700)
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

simpleperf/cmd_record.cpp
simpleperf/scripts/binary_cache_builder.py
simpleperf/scripts/test.py

index bb1fc0f..493f094 100644 (file)
@@ -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();
   }
 
index 546f76b..72c1c12 100644 (file)
@@ -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)
index 491e897..8521548 100644 (file)
@@ -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"])