Commit 7103545f authored by jbudorick's avatar jbudorick Committed by Commit bot

[Android] Add LogcatMonitor.

LogcatMonitor provides the same functionality as
AndroidCommands.WaitForLogMatch and the associated functions.

BUG=267773

Review URL: https://codereview.chromium.org/896503002

Cr-Commit-Position: refs/heads/master@{#314384}
parent ff49cf31
......@@ -62,6 +62,7 @@ def CommonChecks(input_api, output_api):
output_api,
unit_tests=[
J('pylib', 'device', 'device_utils_test.py'),
J('pylib', 'device', 'logcat_monitor_test.py'),
J('pylib', 'gtest', 'gtest_test_instance_test.py'),
J('pylib', 'instrumentation',
'instrumentation_test_instance_test.py'),
......
......@@ -285,7 +285,8 @@ class AdbWrapper(object):
cmd, 'path does not specify an accessible directory in the device',
device_serial=self._device_serial)
def Logcat(self, filter_spec=None, timeout=None):
def Logcat(self, clear=False, dump=False, filter_spec=None,
logcat_format=None, timeout=None):
"""Get an iterator over the logcat output.
Args:
......@@ -296,6 +297,12 @@ class AdbWrapper(object):
logcat output line by line.
"""
cmd = ['logcat']
if clear:
cmd.append('-c')
if dump:
cmd.append('-d')
if logcat_format:
cmd.extend(['-v', logcat_format])
if filter_spec is not None:
cmd.append(filter_spec)
return self._IterRunDeviceAdbCmd(cmd, timeout)
......
......@@ -6,7 +6,7 @@
Eventually, this will be based on adb_wrapper.
"""
# pylint: disable=W0613
# pylint: disable=unused-argument
import logging
import multiprocessing
......@@ -24,6 +24,7 @@ from pylib.device import adb_wrapper
from pylib.device import decorators
from pylib.device import device_errors
from pylib.device import intent
from pylib.device import logcat_monitor
from pylib.device.commands import install_commands
from pylib.utils import apk_helper
from pylib.utils import device_temp_file
......@@ -1290,6 +1291,19 @@ class DeviceUtils(object):
"""
return self.old_interface.GetMemoryUsageForPid(pid)
@decorators.WithTimeoutAndRetriesFromInstance()
def GetLogcatMonitor(self, timeout=None, retries=None, *args, **kwargs):
"""Returns a new LogcatMonitor associated with this device.
Parameters passed to this function are passed directly to
|logcat_monitor.LogcatMonitor| and are documented there.
Args:
timeout: timeout in seconds
retries: number of retries
"""
return logcat_monitor.LogcatMonitor(self.adb, *args, **kwargs)
def __str__(self):
"""Returns the device serial."""
return self.adb.GetDeviceSerial()
......
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# pylint: disable=unused-argument
import collections
import itertools
import logging
import subprocess
import tempfile
import time
import re
from pylib.device import adb_wrapper
from pylib.device import decorators
from pylib.device import device_errors
class LogcatMonitor(object):
# Format: <DATE> <TIME> <PID> <TID> <LEVEL> <COMPONENT>: <MESSAGE>
_THREADTIME_RE_FORMAT = r'\S* +\S* +(%s) +(%s) +(%s) +(%s): +(%s)$'
def __init__(self, adb, clear=True):
"""Create a LogcatMonitor instance.
Args:
adb: An instance of adb_wrapper.AdbWrapper.
clear: If True, clear the logcat when monitoring starts.
"""
if isinstance(adb, adb_wrapper.AdbWrapper):
self._adb = adb
else:
raise ValueError('Unsupported type passed for argument "device"')
self._clear = clear
self._logcat_out = None
self._logcat_out_file = None
self._logcat_proc = None
@decorators.WithTimeoutAndRetriesDefaults(10, 0)
def WaitFor(self, success_regex, failure_regex=None, timeout=None,
retries=None):
"""Wait for a matching logcat line or until a timeout occurs.
This will attempt to match lines in the logcat against both |success_regex|
and |failure_regex| (if provided). Note that this calls re.search on each
logcat line, not re.match, so the provided regular expressions don't have
to match an entire line.
Args:
success_regex: The regular expression to search for.
failure_regex: An optional regular expression that, if hit, causes this
to stop looking for a match. Can be None.
timeout: timeout in seconds
retries: number of retries
Returns:
A match object if |success_regex| matches a part of a logcat line, or
None if |failure_regex| matches a part of a logcat line.
Raises:
CommandFailedError on logcat failure (NOT on a |failure_regex| match).
CommandTimeoutError if no logcat line matching either |success_regex| or
|failure_regex| is found in |timeout| seconds.
DeviceUnreachableError if the device becomes unreachable.
"""
if isinstance(success_regex, basestring):
success_regex = re.compile(success_regex)
if isinstance(failure_regex, basestring):
failure_regex = re.compile(failure_regex)
logging.debug('Waiting %d seconds for "%s"', timeout, success_regex.pattern)
# NOTE This will continue looping until:
# - success_regex matches a line, in which case the match object is
# returned.
# - failure_regex matches a line, in which case None is returned
# - the timeout is hit, in which case a CommandTimeoutError is raised.
for l in self._adb.Logcat():
m = success_regex.search(l)
if m:
return m
if failure_regex and failure_regex.search(l):
return None
def FindAll(self, message_regex, proc_id=None, thread_id=None, log_level=None,
component=None):
"""Finds all lines in the logcat that match the provided constraints.
Args:
message_regex: The regular expression that the <message> section must
match.
proc_id: The process ID to match. If None, matches any process ID.
thread_id: The thread ID to match. If None, matches any thread ID.
log_level: The log level to match. If None, matches any log level.
component: The component to match. If None, matches any component.
Returns:
An iterable containing objects with five attributes:
|proc_id|: the process ID
|thread_id|: the thread ID
|log_level|: the log level
|component|: the component
|message|: the logcat message
"""
LogcatLine = collections.namedtuple(
'LogcatLine',
['proc_id', 'thread_id', 'log_level', 'component', 'message'])
if proc_id is None:
proc_id = r'\d+'
if thread_id is None:
thread_id = r'\d+'
if log_level is None:
log_level = r'[VDIWEF]'
if component is None:
component = r'[^\s:]+'
threadtime_re = re.compile(
type(self)._THREADTIME_RE_FORMAT % (
proc_id, thread_id, log_level, component, message_regex))
regexed_lines = (
re.match(threadtime_re, l)
for l in self._adb.Logcat(dump=True, logcat_format='threadtime'))
only_matches = (m for m in regexed_lines if m)
return (LogcatLine(*m.group(1, 2, 3, 4, 5)) for m in only_matches)
def Start(self):
"""Starts the logcat monitor.
Clears the logcat if |clear| was set in |__init__|.
"""
if self._clear:
self._adb.Logcat(clear=True)
def __enter__(self):
"""Starts the logcat monitor."""
self.Start()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
"""Stops the logcat monitor."""
pass
#!/usr/bin/env python
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import itertools
import os
import sys
import unittest
from pylib import constants
from pylib.device import adb_wrapper
from pylib.device import decorators
from pylib.device import logcat_monitor
sys.path.append(os.path.join(
constants.DIR_SOURCE_ROOT, 'third_party', 'pymock'))
import mock # pylint: disable=F0401
class LogcatMonitorTest(unittest.TestCase):
_TEST_THREADTIME_LOGCAT_DATA = [
'01-01 01:02:03.456 7890 0987 V LogcatMonitorTest: '
'verbose logcat monitor test message 1',
'01-01 01:02:03.457 8901 1098 D LogcatMonitorTest: '
'debug logcat monitor test message 2',
'01-01 01:02:03.458 9012 2109 I LogcatMonitorTest: '
'info logcat monitor test message 3',
'01-01 01:02:03.459 0123 3210 W LogcatMonitorTest: '
'warning logcat monitor test message 4',
'01-01 01:02:03.460 1234 4321 E LogcatMonitorTest: '
'error logcat monitor test message 5',
'01-01 01:02:03.461 2345 5432 F LogcatMonitorTest: '
'fatal logcat monitor test message 6',
'01-01 01:02:03.462 3456 6543 D LogcatMonitorTest: '
'ignore me',]
def _createTestLog(self, raw_logcat=None):
test_adb = adb_wrapper.AdbWrapper('0123456789abcdef')
test_adb.Logcat = mock.Mock(return_value=(l for l in raw_logcat))
test_log = logcat_monitor.LogcatMonitor(test_adb, clear=False)
return test_log
def assertIterEqual(self, expected_iter, actual_iter):
for expected, actual in itertools.izip_longest(expected_iter, actual_iter):
self.assertIsNotNone(
expected,
msg='actual has unexpected elements starting with %s' % str(actual))
self.assertIsNotNone(
actual,
msg='actual is missing elements starting with %s' % str(expected))
self.assertEqual(actual.proc_id, expected[0])
self.assertEqual(actual.thread_id, expected[1])
self.assertEqual(actual.log_level, expected[2])
self.assertEqual(actual.component, expected[3])
self.assertEqual(actual.message, expected[4])
with self.assertRaises(StopIteration):
next(actual_iter)
with self.assertRaises(StopIteration):
next(expected_iter)
def testWaitFor_success(self):
test_log = self._createTestLog(
raw_logcat=type(self)._TEST_THREADTIME_LOGCAT_DATA)
actual_match = test_log.WaitFor(r'.*(fatal|error) logcat monitor.*', None)
self.assertTrue(actual_match)
self.assertEqual(
'01-01 01:02:03.460 1234 4321 E LogcatMonitorTest: '
'error logcat monitor test message 5',
actual_match.group(0))
self.assertEqual('error', actual_match.group(1))
def testWaitFor_failure(self):
test_log = self._createTestLog(
raw_logcat=type(self)._TEST_THREADTIME_LOGCAT_DATA)
actual_match = test_log.WaitFor(
r'.*My Success Regex.*', r'.*(fatal|error) logcat monitor.*')
self.assertIsNone(actual_match)
def testFindAll_defaults(self):
test_log = self._createTestLog(
raw_logcat=type(self)._TEST_THREADTIME_LOGCAT_DATA)
expected_results = [
('7890', '0987', 'V', 'LogcatMonitorTest',
'verbose logcat monitor test message 1'),
('8901', '1098', 'D', 'LogcatMonitorTest',
'debug logcat monitor test message 2'),
('9012', '2109', 'I', 'LogcatMonitorTest',
'info logcat monitor test message 3'),
('0123', '3210', 'W', 'LogcatMonitorTest',
'warning logcat monitor test message 4'),
('1234', '4321', 'E', 'LogcatMonitorTest',
'error logcat monitor test message 5'),
('2345', '5432', 'F', 'LogcatMonitorTest',
'fatal logcat monitor test message 6')]
actual_results = test_log.FindAll(r'\S* logcat monitor test message \d')
self.assertIterEqual(iter(expected_results), actual_results)
def testFindAll_defaults_miss(self):
test_log = self._createTestLog(
raw_logcat=type(self)._TEST_THREADTIME_LOGCAT_DATA)
expected_results = []
actual_results = test_log.FindAll(r'\S* nothing should match this \d')
self.assertIterEqual(iter(expected_results), actual_results)
def testFindAll_filterProcId(self):
test_log = self._createTestLog(
raw_logcat=type(self)._TEST_THREADTIME_LOGCAT_DATA)
actual_results = test_log.FindAll(
r'\S* logcat monitor test message \d', proc_id=1234)
expected_results = [
('1234', '4321', 'E', 'LogcatMonitorTest',
'error logcat monitor test message 5')]
self.assertIterEqual(iter(expected_results), actual_results)
def testFindAll_filterThreadId(self):
test_log = self._createTestLog(
raw_logcat=type(self)._TEST_THREADTIME_LOGCAT_DATA)
actual_results = test_log.FindAll(
r'\S* logcat monitor test message \d', thread_id=2109)
expected_results = [
('9012', '2109', 'I', 'LogcatMonitorTest',
'info logcat monitor test message 3')]
self.assertIterEqual(iter(expected_results), actual_results)
def testFindAll_filterLogLevel(self):
test_log = self._createTestLog(
raw_logcat=type(self)._TEST_THREADTIME_LOGCAT_DATA)
actual_results = test_log.FindAll(
r'\S* logcat monitor test message \d', log_level=r'[DW]')
expected_results = [
('8901', '1098', 'D', 'LogcatMonitorTest',
'debug logcat monitor test message 2'),
('0123', '3210', 'W', 'LogcatMonitorTest',
'warning logcat monitor test message 4'),]
self.assertIterEqual(iter(expected_results), actual_results)
def testFindAll_filterComponent(self):
test_log = self._createTestLog(
raw_logcat=type(self)._TEST_THREADTIME_LOGCAT_DATA)
actual_results = test_log.FindAll(r'.*', component='LogcatMonitorTest')
expected_results = [
('7890', '0987', 'V', 'LogcatMonitorTest',
'verbose logcat monitor test message 1'),
('8901', '1098', 'D', 'LogcatMonitorTest',
'debug logcat monitor test message 2'),
('9012', '2109', 'I', 'LogcatMonitorTest',
'info logcat monitor test message 3'),
('0123', '3210', 'W', 'LogcatMonitorTest',
'warning logcat monitor test message 4'),
('1234', '4321', 'E', 'LogcatMonitorTest',
'error logcat monitor test message 5'),
('2345', '5432', 'F', 'LogcatMonitorTest',
'fatal logcat monitor test message 6'),
('3456', '6543', 'D', 'LogcatMonitorTest',
'ignore me'),]
self.assertIterEqual(iter(expected_results), actual_results)
if __name__ == '__main__':
unittest.main(verbosity=2)
......@@ -51,6 +51,7 @@ class TestRunner(base_test_runner.BaseTestRunner):
super(TestRunner, self).__init__(device, test_options.tool,
test_options.cleanup_test_files)
self._lighttp_port = constants.LIGHTTPD_RANDOM_PORT_FIRST + shard_index
self._logcat_monitor = None
self.coverage_device_file = None
self.coverage_dir = test_options.coverage_dir
......@@ -174,9 +175,10 @@ class TestRunner(base_test_runner.BaseTestRunner):
"""
if not self._IsPerfTest(test):
return
self.device.old_interface.Adb().SendCommand(
'shell rm ' + TestRunner._DEVICE_PERF_OUTPUT_SEARCH_PREFIX)
self.device.old_interface.StartMonitoringLogcat()
self.device.RunShellCommand(
['rm', TestRunner._DEVICE_PERF_OUTPUT_SEARCH_PREFIX])
self._logcat_monitor = self.device.GetLogcatMonitor()
self._logcat_monitor.Start()
def TestTeardown(self, test, result):
"""Cleans up the test harness after running a particular test.
......@@ -219,9 +221,8 @@ class TestRunner(base_test_runner.BaseTestRunner):
raw_test_name = test.split('#')[1]
# Wait and grab annotation data so we can figure out which traces to parse
regex = self.device.old_interface.WaitForLogMatch(
re.compile(r'\*\*PERFANNOTATION\(' + raw_test_name + r'\)\:(.*)'),
None)
regex = self._logcat_monitor.WaitFor(
re.compile(r'\*\*PERFANNOTATION\(' + raw_test_name + r'\)\:(.*)'))
# If the test is set to run on a specific device type only (IE: only
# tablet or phone) and it is being run on the wrong device, the test
......
......@@ -42,6 +42,7 @@ import time
from pylib import constants
from pylib.base import base_test_result
from pylib.device import device_errors
from pylib.device import intent
......@@ -70,10 +71,11 @@ _LOGCAT_FILTERS = ['*:s', 'chromium:v', 'chromium_android_linker:v']
#_LOGCAT_FILTERS = ['*:v'] ## DEBUG
# Regular expression used to match status lines in logcat.
re_status_line = re.compile(r'(BROWSER|RENDERER)_LINKER_TEST: (FAIL|SUCCESS)')
_RE_BROWSER_STATUS_LINE = re.compile(r' BROWSER_LINKER_TEST: (FAIL|SUCCESS)$')
_RE_RENDERER_STATUS_LINE = re.compile(r' RENDERER_LINKER_TEST: (FAIL|SUCCESS)$')
# Regular expression used to mach library load addresses in logcat.
re_library_address = re.compile(
_RE_LIBRARY_ADDRESS = re.compile(
r'(BROWSER|RENDERER)_LIBRARY_ADDRESS: (\S+) ([0-9A-Fa-f]+)')
......@@ -109,46 +111,6 @@ def _GetBrowserSharedRelroConfig():
return configs[0]
def _WriteCommandLineFile(device, command_line, command_line_file):
"""Create a command-line file on the device. This does not use FlagChanger
because its implementation assumes the device has 'su', and thus does
not work at all with production devices."""
device.RunShellCommand(
'echo "%s" > %s' % (command_line, command_line_file))
def _CheckLinkerTestStatus(logcat):
"""Parse the content of |logcat| and checks for both a browser and
renderer status line.
Args:
logcat: A string to parse. Can include line separators.
Returns:
A tuple, result[0] is True if there is a complete match, then
result[1] and result[2] will be True or False to reflect the
test status for the browser and renderer processes, respectively.
"""
browser_found = False
renderer_found = False
for m in re_status_line.finditer(logcat):
process_type, status = m.groups()
if process_type == 'BROWSER':
browser_found = True
browser_success = (status == 'SUCCESS')
elif process_type == 'RENDERER':
renderer_found = True
renderer_success = (status == 'SUCCESS')
else:
assert False, 'Invalid process type ' + process_type
if browser_found and renderer_found:
return (True, browser_success, renderer_success)
# Didn't find anything.
return (False, None, None)
def _StartActivityAndWaitForLinkerTestStatus(device, timeout):
"""Force-start an activity and wait up to |timeout| seconds until the full
linker test status lines appear in the logcat, recorded through |device|.
......@@ -159,38 +121,30 @@ def _StartActivityAndWaitForLinkerTestStatus(device, timeout):
A (status, logs) tuple, where status is a ResultType constant, and logs
if the final logcat output as a string.
"""
# 1. Start recording logcat with appropriate filters.
device.old_interface.StartRecordingLogcat(
clear=True, filters=_LOGCAT_FILTERS)
with device.GetLogcatMonitor(filters=_LOGCAT_FILTERS) as logmon:
try:
# 2. Force-start activity.
device.StartActivity(
intent.Intent(package=_PACKAGE_NAME, activity=_ACTIVITY_NAME),
force_stop=True)
# 3. Wait up to |timeout| seconds until the test status is in the logcat.
num_tries = 0
max_tries = timeout
found = False
while num_tries < max_tries:
time.sleep(1)
num_tries += 1
found, browser_ok, renderer_ok = _CheckLinkerTestStatus(
device.old_interface.GetCurrentRecordedLogcat())
if found:
break
finally:
logs = device.old_interface.StopRecordingLogcat()
if num_tries >= max_tries:
return ResultType.TIMEOUT, logs
if browser_ok and renderer_ok:
return ResultType.PASS, logs
return ResultType.FAIL, logs
result = ResultType.PASS
try:
browser_match = logmon.WaitFor(_RE_BROWSER_STATUS_LINE, timeout=timeout)
logging.debug('Found browser match: %s', browser_match.group(0))
renderer_match = logmon.WaitFor(_RE_RENDERER_STATUS_LINE,
timeout=timeout)
logging.debug('Found renderer match: %s', renderer_match.group(0))
if (browser_match.group(1) != 'SUCCESS'
or renderer_match.group(1) != 'SUCCESS'):
result = ResultType.FAIL
except device_errors.CommandTimeoutError:
result = ResultType.TIMEOUT
return result, '\n'.join(device.adb.Logcat(dump=True))
class LibraryLoadMap(dict):
......@@ -226,7 +180,7 @@ def _ExtractLibraryLoadAddressesFromLogcat(logs):
"""
browser_libs = LibraryLoadMap()
renderer_libs = LibraryLoadMap()
for m in re_library_address.finditer(logs):
for m in _RE_LIBRARY_ADDRESS.finditer(logs):
process_type, lib_name, lib_address = m.groups()
lib_address = int(lib_address, 16)
if process_type == 'BROWSER':
......@@ -323,7 +277,7 @@ class LinkerTestCaseBase(object):
command_line_flags = ''
if self.is_low_memory:
command_line_flags = '--low-memory-device'
_WriteCommandLineFile(device, command_line_flags, _COMMAND_LINE_FILE)
device.WriteFile(_COMMAND_LINE_FILE, command_line_flags)
# Run the test.
status, logs = self._RunTest(device)
......
......@@ -9,7 +9,7 @@ import time
from profile_chrome import controllers
from pylib import pexpect
from pylib.device import device_errors
from pylib.device import intent
......@@ -23,6 +23,7 @@ class ChromeTracingController(controllers.BaseController):
self._package_info = package_info
self._categories = categories
self._ring_buffer = ring_buffer
self._logcat_monitor = self._device.GetLogcatMonitor()
self._trace_file = None
self._trace_interval = None
self._trace_memory = trace_memory
......@@ -31,21 +32,21 @@ class ChromeTracingController(controllers.BaseController):
re.compile(r'Logging performance trace to file')
self._trace_finish_re = \
re.compile(r'Profiler finished[.] Results are in (.*)[.]')
self._device.old_interface.StartMonitoringLogcat(clear=False)
def __repr__(self):
return 'chrome trace'
@staticmethod
def GetCategories(device, package_info):
device.BroadcastIntent(intent.Intent(
action='%s.GPU_PROFILER_LIST_CATEGORIES' % package_info.package))
try:
json_category_list = device.old_interface.WaitForLogMatch(
re.compile(r'{"traceCategoriesList(.*)'), None, timeout=5).group(0)
except pexpect.TIMEOUT:
raise RuntimeError('Performance trace category list marker not found. '
'Is the correct version of the browser running?')
with device.GetLogcatMonitor() as logmon:
device.BroadcastIntent(intent.Intent(
action='%s.GPU_PROFILER_LIST_CATEGORIES' % package_info.package))
try:
json_category_list = logmon.WaitFor(
re.compile(r'{"traceCategoriesList(.*)'), timeout=5).group(0)
except device_errors.CommandTimeoutError:
raise RuntimeError('Performance trace category list marker not found. '
'Is the correct version of the browser running?')
record_categories = set()
disabled_by_default_categories = set()
......@@ -61,7 +62,7 @@ class ChromeTracingController(controllers.BaseController):
def StartTracing(self, interval):
self._trace_interval = interval
self._device.old_interface.SyncLogCat()
self._logcat_monitor.Start()
start_extras = {'categories': ','.join(self._categories)}
if self._ring_buffer:
start_extras['continuous'] = None
......@@ -70,7 +71,7 @@ class ChromeTracingController(controllers.BaseController):
extras=start_extras))
if self._trace_memory:
self._device.old_interface.EnableAdbRoot()
self._device.EnableRoot()
self._device.SetProp(_HEAP_PROFILE_MMAP_PROPERTY, 1)
# Chrome logs two different messages related to tracing:
......@@ -81,10 +82,9 @@ class ChromeTracingController(controllers.BaseController):
# The first one is printed when tracing starts and the second one indicates
# that the trace file is ready to be pulled.
try:
self._device.old_interface.WaitForLogMatch(
self._trace_start_re, None, timeout=5)
self._logcat_monitor.WaitFor(self._trace_start_re, timeout=5)
self._is_tracing = True
except pexpect.TIMEOUT:
except device_errors.CommandTimeoutError:
raise RuntimeError('Trace start marker not found. Is the correct version '
'of the browser running?')
......@@ -92,8 +92,8 @@ class ChromeTracingController(controllers.BaseController):
if self._is_tracing:
self._device.BroadcastIntent(intent.Intent(
action='%s.GPU_PROFILER_STOP' % self._package_info.package))
self._trace_file = self._device.old_interface.WaitForLogMatch(
self._trace_finish_re, None, timeout=120).group(1)
self._trace_file = self._logcat_monitor.WaitFor(
self._trace_finish_re, timeout=120).group(1)
self._is_tracing = False
if self._trace_memory:
self._device.SetProp(_HEAP_PROFILE_MMAP_PROPERTY, 0)
......
......@@ -16,10 +16,10 @@ class ChromeStartupTracingController(controllers.BaseController):
self._device = device
self._package_info = package_info
self._cold = cold
self._logcat_monitor = self._device.GetLogcatMonitor()
self._url = url
self._trace_file = None
self._trace_finish_re = re.compile(r' Completed startup tracing to (.*)')
self._device.old_interface.StartMonitoringLogcat(clear=False)
def __repr__(self):
return 'Browser Startup Trace'
......@@ -30,15 +30,16 @@ class ChromeStartupTracingController(controllers.BaseController):
changer = flag_changer.FlagChanger(
self._device, self._package_info.cmdline_file)
changer.AddFlags(['--trace-startup'])
self._device.old_interface.CloseApplication(self._package_info.package)
self._device.ForceStop(self._package_info.package)
if self._cold:
self._device.old_interface.EnableAdbRoot()
self._device.EnableRoot()
cache_control.CacheControl(self._device).DropRamCaches()
self._device.old_interface.StartActivity(
package=self._package_info.package,
activity=self._package_info.activity,
data=self._url,
extras={'create_new_tab' : True})
self._device.StartActivity(
intent.Intent(
package=self._package_info.package,
activity=self._package_info.activity,
data=self._url,
extras={'create_new_tab' : True}))
def _TearDownTracing(self):
changer = flag_changer.FlagChanger(
......@@ -47,12 +48,12 @@ class ChromeStartupTracingController(controllers.BaseController):
def StartTracing(self, interval):
self._SetupTracing()
self._device.old_interface.SyncLogCat()
self._logcat_monitor.Start()
def StopTracing(self):
try:
self._trace_file = self._device.old_interface.WaitForLogMatch(
self._trace_finish_re, None, timeout=10).group(1)
self._trace_file = self._logcat_monitor.WaitFor(
self._trace_finish_re).group(1)
finally:
self._TearDownTracing()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment