Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: tools/profile_chrome/chrome_controller.py

Issue 879853002: Add a --startup option to generate combined traces for startup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/profile_chrome/main.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import json 5 import json
6 import os 6 import os
7 import re 7 import re
8 import time 8 import time
9 9
10 from profile_chrome import controllers 10 from profile_chrome import controllers
11 11
12 from pylib import android_commands
13 from pylib import flag_changer
12 from pylib import pexpect 14 from pylib import pexpect
13 from pylib.device import intent 15 from pylib.device import intent
14 16
15 17
16 _HEAP_PROFILE_MMAP_PROPERTY = 'heapprof.mmap' 18 _HEAP_PROFILE_MMAP_PROPERTY = 'heapprof.mmap'
17 19
18 class ChromeTracingController(controllers.BaseController): 20 class ChromeTracingController(controllers.BaseController):
19 def __init__(self, device, package_info, 21 def __init__(self, device, package_info,
20 categories, ring_buffer, trace_memory=False): 22 categories, ring_buffer, trace_memory=False,
23 startup=None):
21 controllers.BaseController.__init__(self) 24 controllers.BaseController.__init__(self)
22 self._device = device 25 self._device = device
23 self._package_info = package_info 26 self._package_info = package_info
24 self._categories = categories 27 self._categories = categories
25 self._ring_buffer = ring_buffer 28 self._ring_buffer = ring_buffer
26 self._trace_file = None 29 self._trace_file = None
27 self._trace_interval = None 30 self._trace_interval = None
28 self._trace_memory = trace_memory 31 self._trace_memory = trace_memory
32 self._startup = startup
29 self._is_tracing = False 33 self._is_tracing = False
30 self._trace_start_re = \ 34 self._trace_start_re = \
31 re.compile(r'Logging performance trace to file') 35 re.compile(r'Logging performance trace to file')
32 self._trace_finish_re = \ 36 if self._startup:
37 self._trace_finish_re = re.compile(
38 r' Completed startup tracing to (.*)')
39 else:
40 self._trace_finish_re = \
33 re.compile(r'Profiler finished[.] Results are in (.*)[.]') 41 re.compile(r'Profiler finished[.] Results are in (.*)[.]')
34 self._device.old_interface.StartMonitoringLogcat(clear=False) 42 self._device.old_interface.StartMonitoringLogcat(clear=False)
35 43
36 def __repr__(self): 44 def __repr__(self):
37 return 'chrome trace' 45 return 'chrome trace'
38 46
39 @staticmethod 47 @staticmethod
40 def GetCategories(device, package_info): 48 def GetCategories(device, package_info):
41 device.BroadcastIntent(intent.Intent( 49 device.BroadcastIntent(intent.Intent(
42 action='%s.GPU_PROFILER_LIST_CATEGORIES' % package_info.package)) 50 action='%s.GPU_PROFILER_LIST_CATEGORIES' % package_info.package))
43 try: 51 try:
44 json_category_list = device.old_interface.WaitForLogMatch( 52 json_category_list = device.old_interface.WaitForLogMatch(
45 re.compile(r'{"traceCategoriesList(.*)'), None, timeout=5).group(0) 53 re.compile(r'{"traceCategoriesList(.*)'), None, timeout=5).group(0)
46 except pexpect.TIMEOUT: 54 except pexpect.TIMEOUT:
47 raise RuntimeError('Performance trace category list marker not found. ' 55 raise RuntimeError('Performance trace category list marker not found. '
48 'Is the correct version of the browser running?') 56 'Is the correct version of the browser running?')
49 57
50 record_categories = set() 58 record_categories = set()
51 disabled_by_default_categories = set() 59 disabled_by_default_categories = set()
52 json_data = json.loads(json_category_list)['traceCategoriesList'] 60 json_data = json.loads(json_category_list)['traceCategoriesList']
53 for item in json_data: 61 for item in json_data:
54 for category in item.split(','): 62 for category in item.split(','):
55 if category.startswith('disabled-by-default'): 63 if category.startswith('disabled-by-default'):
56 disabled_by_default_categories.add(category) 64 disabled_by_default_categories.add(category)
57 else: 65 else:
58 record_categories.add(category) 66 record_categories.add(category)
59 67
60 return list(record_categories), list(disabled_by_default_categories) 68 return list(record_categories), list(disabled_by_default_categories)
61 69
70 def _SetupStartupTracing(self):
71 changer = flag_changer.FlagChanger(
72 self._device, self._package_info.cmdline_file)
73 changer.AddFlags(['--trace-startup'])
74 self._device.old_interface.CloseApplication(self._package_info.package)
75 if self._startup == 'cold':
76 self._device.old_interface.EnableAdbRoot()
77 adb = android_commands.AndroidCommands()
78 adb.RunShellCommand('echo 1 > /proc/vm/drop_caches')
pasko-google - do not use 2015/01/27 15:20:52 There is cache_control.DropRamCaches, which also d
Benoit L 2015/01/27 16:31:33 Done.
79 self._device.old_interface.StartActivity(
80 package=self._package_info.package,
81 activity=self._package_info.activity,
82 data='http://www.google.com/',
83 extras={'create_new_tab' : True})
84
62 def StartTracing(self, interval): 85 def StartTracing(self, interval):
86 if self._startup:
87 self._SetupStartupTracing()
63 self._trace_interval = interval 88 self._trace_interval = interval
64 self._device.old_interface.SyncLogCat() 89 self._device.old_interface.SyncLogCat()
65 start_extras = {'categories': ','.join(self._categories)} 90 start_extras = {'categories': ','.join(self._categories)}
66 if self._ring_buffer: 91 if self._ring_buffer:
67 start_extras['continuous'] = None 92 start_extras['continuous'] = None
68 self._device.BroadcastIntent(intent.Intent( 93 self._device.BroadcastIntent(intent.Intent(
69 action='%s.GPU_PROFILER_START' % self._package_info.package, 94 action='%s.GPU_PROFILER_START' % self._package_info.package,
70 extras=start_extras)) 95 extras=start_extras))
71 96
72 if self._trace_memory: 97 if self._trace_memory:
73 self._device.old_interface.EnableAdbRoot() 98 self._device.old_interface.EnableAdbRoot()
74 self._device.SetProp(_HEAP_PROFILE_MMAP_PROPERTY, 1) 99 self._device.SetProp(_HEAP_PROFILE_MMAP_PROPERTY, 1)
75 100
76 # Chrome logs two different messages related to tracing: 101 # Chrome logs two different messages related to tracing:
77 # 102 #
78 # 1. "Logging performance trace to file" 103 # 1. "Logging performance trace to file"
79 # 2. "Profiler finished. Results are in [...]" 104 # 2. "Profiler finished. Results are in [...]"
80 # 105 #
81 # The first one is printed when tracing starts and the second one indicates 106 # The first one is printed when tracing starts and the second one indicates
82 # that the trace file is ready to be pulled. 107 # that the trace file is ready to be pulled.
83 try: 108 if not self._startup:
84 self._device.old_interface.WaitForLogMatch( 109 try:
85 self._trace_start_re, None, timeout=5) 110 self._device.old_interface.WaitForLogMatch(
86 self._is_tracing = True 111 self._trace_start_re, None, timeout=5)
87 except pexpect.TIMEOUT: 112 except pexpect.TIMEOUT:
88 raise RuntimeError('Trace start marker not found. Is the correct version ' 113 raise RuntimeError('Trace start marker not found. Is the correct '
89 'of the browser running?') 114 'version of the browser running?')
115 self._is_tracing = True
90 116
91 def StopTracing(self): 117 def StopTracing(self):
92 if self._is_tracing: 118 if self._is_tracing:
93 self._device.BroadcastIntent(intent.Intent( 119 self._device.BroadcastIntent(intent.Intent(
94 action='%s.GPU_PROFILER_STOP' % self._package_info.package)) 120 action='%s.GPU_PROFILER_STOP' % self._package_info.package))
95 self._trace_file = self._device.old_interface.WaitForLogMatch( 121 self._trace_file = self._device.old_interface.WaitForLogMatch(
96 self._trace_finish_re, None, timeout=120).group(1) 122 self._trace_finish_re, None, timeout=120).group(1)
97 self._is_tracing = False 123 self._is_tracing = False
98 if self._trace_memory: 124 if self._trace_memory:
99 self._device.SetProp(_HEAP_PROFILE_MMAP_PROPERTY, 0) 125 self._device.SetProp(_HEAP_PROFILE_MMAP_PROPERTY, 0)
100 126
101 def PullTrace(self): 127 def PullTrace(self):
102 # Wait a bit for the browser to finish writing the trace file. 128 # Wait a bit for the browser to finish writing the trace file.
103 time.sleep(self._trace_interval / 4 + 1) 129 time.sleep(self._trace_interval / 4 + 1)
104
105 trace_file = self._trace_file.replace('/storage/emulated/0/', '/sdcard/') 130 trace_file = self._trace_file.replace('/storage/emulated/0/', '/sdcard/')
106 host_file = os.path.join(os.path.curdir, os.path.basename(trace_file)) 131 host_file = os.path.join(os.path.curdir, os.path.basename(trace_file))
107 self._device.PullFile(trace_file, host_file) 132 self._device.PullFile(trace_file, host_file)
108 return host_file 133 return host_file
OLDNEW
« no previous file with comments | « no previous file | tools/profile_chrome/main.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698