Index: tools/telemetry/telemetry/core/platform/profiler/tcpdump_profiler.py |
diff --git a/tools/telemetry/telemetry/core/platform/profiler/tcpdump_profiler.py b/tools/telemetry/telemetry/core/platform/profiler/tcpdump_profiler.py |
index 6ad22c4e664257c1c06746506e4eb3be2b9e1b40..16962c82f53988658494b46d7ea3d42b5d3a9d85 100644 |
--- a/tools/telemetry/telemetry/core/platform/profiler/tcpdump_profiler.py |
+++ b/tools/telemetry/telemetry/core/platform/profiler/tcpdump_profiler.py |
@@ -2,15 +2,21 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
+import logging |
import os |
import signal |
import subprocess |
import sys |
import tempfile |
+from telemetry.core import util |
from telemetry.core.platform import profiler |
from telemetry.core.platform.profiler import android_prebuilt_profiler_helper |
+util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android') |
+from pylib import device_signal # pylint: disable=import-error |
+from pylib.device import device_errors # pylint: disable=import-error |
+ |
_TCP_DUMP_BASE_OPTS = ['-i', 'any', '-p', '-s', '0', '-w'] |
@@ -23,28 +29,30 @@ class _TCPDumpProfilerAndroid(object): |
_DEVICE_DUMP_FILE = '/sdcard/tcpdump_profiles/capture.pcap' |
- def __init__(self, adb, output_path): |
- self._adb = adb |
+ def __init__(self, device, output_path): |
+ self._device = device |
self._output_path = output_path |
- self._adb.RunShellCommand('mkdir -p ' + |
- os.path.dirname(self._DEVICE_DUMP_FILE)) |
+ self._device.RunShellCommand('mkdir -p ' + |
+ os.path.dirname(self._DEVICE_DUMP_FILE)) |
self._proc = subprocess.Popen( |
- ['adb', '-s', self._adb.device_serial(), |
+ ['adb', '-s', self._device.adb.GetDeviceSerial(), |
'shell', android_prebuilt_profiler_helper.GetDevicePath('tcpdump')] + |
_TCP_DUMP_BASE_OPTS + |
[self._DEVICE_DUMP_FILE]) |
def CollectProfile(self): |
- tcpdump_pid = self._adb.ExtractPid('tcpdump') |
- if not tcpdump_pid or not tcpdump_pid[0]: |
+ try: |
+ self._device.KillAll('tcpdump', signum=device_signal.SIGTERM) |
+ except device_errors.CommandFailedError: |
+ logging.exception('Unable to kill TCPDump.') |
raise Exception('Unable to find TCPDump. Check your device is rooted ' |
'and tcpdump is installed at ' + |
android_prebuilt_profiler_helper.GetDevicePath('tcpdump')) |
- self._adb.RunShellCommand('kill -term ' + tcpdump_pid[0]) |
+ |
self._proc.terminate() |
host_dump = os.path.join(self._output_path, |
os.path.basename(self._DEVICE_DUMP_FILE)) |
- self._adb.device().PullFile(self._DEVICE_DUMP_FILE, host_dump) |
+ self._device.PullFile(self._DEVICE_DUMP_FILE, host_dump) |
print 'TCP dump available at: %s ' % host_dump |
print 'Use Wireshark to open it.' |
return host_dump |
@@ -98,9 +106,9 @@ class TCPDumpProfiler(profiler.Profiler): |
browser_backend, platform_backend, output_path, state) |
if platform_backend.GetOSName() == 'android': |
android_prebuilt_profiler_helper.InstallOnDevice( |
- browser_backend.adb.device(), 'tcpdump') |
+ browser_backend.device, 'tcpdump') |
self._platform_profiler = _TCPDumpProfilerAndroid( |
- browser_backend.adb, output_path) |
+ browser_backend.device, output_path) |
else: |
self._platform_profiler = _TCPDumpProfilerLinux(output_path) |