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

Side by Side Diff: tools/android/loading/pull_sandwich_metrics.py

Issue 1726403005: sandwich: Makes pull_sandwich_metrics.py a sub-command. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@i09
Patch Set: Addresses pasko's nits Created 4 years, 9 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/android/loading/sandwich.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 #! /usr/bin/env python
2 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # 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
4 # found in the LICENSE file. 3 # found in the LICENSE file.
5 4
6 """Pull a sandwich run's output directory's metrics from traces into a CSV. 5 """Pull a sandwich run's output directory's metrics from traces into a CSV.
7 6
8 python pull_sandwich_metrics.py -h 7 python pull_sandwich_metrics.py -h
9 """ 8 """
10 9
11 import argparse
12 import csv
13 import json 10 import json
14 import logging 11 import logging
15 import os 12 import os
16 import sys 13 import sys
17 14
18 import loading_trace as loading_trace_module 15 import loading_trace as loading_trace_module
19 import tracing 16 import tracing
20 17
21 18
22 CATEGORIES = ['blink.user_timing', 'disabled-by-default-memory-infra'] 19 CATEGORIES = ['blink.user_timing', 'disabled-by-default-memory-infra']
23 20
24 _CSV_FIELD_NAMES = [ 21 CSV_FIELD_NAMES = [
25 'id', 22 'id',
26 'url', 23 'url',
27 'total_load', 24 'total_load',
28 'onload', 25 'onload',
29 'browser_malloc_avg', 26 'browser_malloc_avg',
30 'browser_malloc_max'] 27 'browser_malloc_max']
31 28
32 _TRACKED_EVENT_NAMES = set(['requestStart', 'loadEventStart', 'loadEventEnd']) 29 _TRACKED_EVENT_NAMES = set(['requestStart', 'loadEventStart', 'loadEventEnd'])
33 30
34 31
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 return tracked_events 104 return tracked_events
108 105
109 106
110 def _PullMetricsFromLoadingTrace(loading_trace): 107 def _PullMetricsFromLoadingTrace(loading_trace):
111 """Pulls all the metrics from a given trace. 108 """Pulls all the metrics from a given trace.
112 109
113 Args: 110 Args:
114 loading_trace: loading_trace_module.LoadingTrace. 111 loading_trace: loading_trace_module.LoadingTrace.
115 112
116 Returns: 113 Returns:
117 Dictionary with all _CSV_FIELD_NAMES's field set (except the 'id'). 114 Dictionary with all CSV_FIELD_NAMES's field set (except the 'id').
118 """ 115 """
119 browser_dump_events = _GetBrowserDumpEvents(loading_trace.tracing_track) 116 browser_dump_events = _GetBrowserDumpEvents(loading_trace.tracing_track)
120 web_page_tracked_events = _GetWebPageTrackedEvents( 117 web_page_tracked_events = _GetWebPageTrackedEvents(
121 loading_trace.tracing_track) 118 loading_trace.tracing_track)
122 119
123 browser_malloc_sum = 0 120 browser_malloc_sum = 0
124 browser_malloc_max = 0 121 browser_malloc_max = 0
125 for dump_event in browser_dump_events: 122 for dump_event in browser_dump_events:
126 attr = dump_event.args['dumps']['allocators']['malloc']['attrs']['size'] 123 attr = dump_event.args['dumps']['allocators']['malloc']['attrs']['size']
127 assert attr['units'] == 'bytes' 124 assert attr['units'] == 'bytes'
128 size = int(attr['value'], 16) 125 size = int(attr['value'], 16)
129 browser_malloc_sum += size 126 browser_malloc_sum += size
130 browser_malloc_max = max(browser_malloc_max, size) 127 browser_malloc_max = max(browser_malloc_max, size)
131 128
132 return { 129 return {
133 'total_load': (web_page_tracked_events['loadEventEnd'].start_msec - 130 'total_load': (web_page_tracked_events['loadEventEnd'].start_msec -
134 web_page_tracked_events['requestStart'].start_msec), 131 web_page_tracked_events['requestStart'].start_msec),
135 'onload': (web_page_tracked_events['loadEventEnd'].start_msec - 132 'onload': (web_page_tracked_events['loadEventEnd'].start_msec -
136 web_page_tracked_events['loadEventStart'].start_msec), 133 web_page_tracked_events['loadEventStart'].start_msec),
137 'browser_malloc_avg': browser_malloc_sum / float(len(browser_dump_events)), 134 'browser_malloc_avg': browser_malloc_sum / float(len(browser_dump_events)),
138 'browser_malloc_max': browser_malloc_max 135 'browser_malloc_max': browser_malloc_max
139 } 136 }
140 137
141 138
142 def _PullMetricsFromOutputDirectory(output_directory_path): 139 def PullMetricsFromOutputDirectory(output_directory_path):
143 """Pulls all the metrics from all the traces of a sandwich run directory. 140 """Pulls all the metrics from all the traces of a sandwich run directory.
144 141
145 Args: 142 Args:
146 output_directory_path: The sandwich run's output directory to pull the 143 output_directory_path: The sandwich run's output directory to pull the
147 metrics from. 144 metrics from.
148 145
149 Returns: 146 Returns:
150 List of dictionaries with all _CSV_FIELD_NAMES's field set. 147 List of dictionaries with all CSV_FIELD_NAMES's field set.
151 """ 148 """
152 assert os.path.isdir(output_directory_path) 149 assert os.path.isdir(output_directory_path)
153 run_infos = None 150 run_infos = None
154 with open(os.path.join(output_directory_path, 'run_infos.json')) as f: 151 with open(os.path.join(output_directory_path, 'run_infos.json')) as f:
155 run_infos = json.load(f) 152 run_infos = json.load(f)
156 assert run_infos 153 assert run_infos
157 metrics = [] 154 metrics = []
158 for node_name in os.listdir(output_directory_path): 155 for node_name in os.listdir(output_directory_path):
159 if not os.path.isdir(os.path.join(output_directory_path, node_name)): 156 if not os.path.isdir(os.path.join(output_directory_path, node_name)):
160 continue 157 continue
161 try: 158 try:
162 page_id = int(node_name) 159 page_id = int(node_name)
163 except ValueError: 160 except ValueError:
164 continue 161 continue
165 trace_path = os.path.join(output_directory_path, node_name, 'trace.json') 162 trace_path = os.path.join(output_directory_path, node_name, 'trace.json')
166 if not os.path.isfile(trace_path): 163 if not os.path.isfile(trace_path):
167 continue 164 continue
168 logging.info('processing \'%s\'' % trace_path) 165 logging.info('processing \'%s\'' % trace_path)
169 loading_trace = loading_trace_module.LoadingTrace.FromJsonFile(trace_path) 166 loading_trace = loading_trace_module.LoadingTrace.FromJsonFile(trace_path)
170 trace_metrics = _PullMetricsFromLoadingTrace(loading_trace) 167 trace_metrics = _PullMetricsFromLoadingTrace(loading_trace)
171 trace_metrics['id'] = page_id 168 trace_metrics['id'] = page_id
172 trace_metrics['url'] = run_infos['urls'][page_id] 169 trace_metrics['url'] = run_infos['urls'][page_id]
173 metrics.append(trace_metrics) 170 metrics.append(trace_metrics)
174 assert len(metrics) > 0, ('Looks like \'{}\' was not a sandwich ' + 171 assert len(metrics) > 0, ('Looks like \'{}\' was not a sandwich ' +
175 'run directory.').format(output_directory_path) 172 'run directory.').format(output_directory_path)
176 return metrics 173 return metrics
177
178
179 def main():
180 logging.basicConfig(level=logging.INFO)
181
182 parser = argparse.ArgumentParser()
183 parser.add_argument('output', type=str,
184 help='Output directory of run_sandwich.py command.')
185 args = parser.parse_args()
186
187 trace_metrics_list = _PullMetricsFromOutputDirectory(args.output)
188 trace_metrics_list.sort(key=lambda e: e['id'])
189 cs_file_path = os.path.join(args.output, 'trace_analysis.csv')
190 with open(cs_file_path, 'w') as csv_file:
191 writer = csv.DictWriter(csv_file, fieldnames=_CSV_FIELD_NAMES)
192 writer.writeheader()
193 for trace_metrics in trace_metrics_list:
194 writer.writerow(trace_metrics)
195 return 0
196
197
198 if __name__ == '__main__':
199 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | tools/android/loading/sandwich.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698