OSDN Git Service

simpleperf: add pid argument to inferno
authorWei Wang <wvw@google.com>
Thu, 2 Aug 2018 19:26:10 +0000 (12:26 -0700)
committerYabin Cui <yabinc@google.com>
Wed, 15 Aug 2018 17:22:04 +0000 (10:22 -0700)
Bug: 112146809
Test: inferno.sh --pid 620
Change-Id: I99afe432a194bb8799e4633f0a651ff1be2354f5
(cherry picked from commit 6db1fa95d3d4e25c49d3e7b0224df45f521f1f90)

simpleperf/scripts/inferno/inferno.py

index 0bc0665..bf2cf9a 100755 (executable)
@@ -264,6 +264,8 @@ def main():
                               Like -np surfaceflinger.""")
     record_group.add_argument('-p', '--app', help="""Profile an Android app, given the package
                               name. Like -p com.example.android.myapp.""")
+    record_group.add_argument('--pid', type=int, default=-1, help="""Profile a native program
+                              with given pid, the pid should exist on the device.""")
     record_group.add_argument('--record_file', default='perf.data', help='Default is perf.data.')
     record_group.add_argument('-sc', '--skip_collection', action='store_true', help="""Skip data
                               collection""")
@@ -301,6 +303,15 @@ def main():
     process = Process("", 0)
 
     if not args.skip_collection:
+        if args.pid != -1:
+            result, output = AdbHelper().run_and_return_output(['shell', 'ps', '-p',
+                                                                str(args.pid), '-o', 'comm='])
+            if result:
+                try:
+                    args.native_program = output.replace('\n', '')
+                except:
+                    log_warning("Could not find native app for pid '%d'." % process.pid)
+
         process.name = args.app or args.native_program
         log_info("Starting data collection stage for process '%s'." % process.name)
         if not collect_data(args):