OLD | NEW |
1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Pull a sandwich run's output directory's metrics from traces into a CSV. | 6 """Pull a sandwich run's output directory's metrics from traces into a CSV. |
7 | 7 |
8 python pull_sandwich_metrics.py -h | 8 python pull_sandwich_metrics.py -h |
9 """ | 9 """ |
10 | 10 |
11 import argparse | 11 import argparse |
12 import csv | 12 import csv |
13 import json | 13 import json |
14 import logging | 14 import logging |
15 import os | 15 import os |
16 import sys | 16 import sys |
17 | 17 |
18 | 18 |
19 CATEGORIES = ['blink.user_timing', 'disabled-by-default-memory-infra'] | 19 CATEGORIES = ['blink.user_timing', 'disabled-by-default-memory-infra'] |
20 | 20 |
21 _CSV_FIELD_NAMES = [ | 21 _CSV_FIELD_NAMES = [ |
22 'id', | 22 'id', |
| 23 'url', |
23 'total_load', | 24 'total_load', |
24 'onload', | 25 'onload', |
25 'browser_malloc_avg', | 26 'browser_malloc_avg', |
26 'browser_malloc_max'] | 27 'browser_malloc_max'] |
27 | 28 |
28 _TRACKED_EVENT_NAMES = set(['requestStart', 'loadEventStart', 'loadEventEnd']) | 29 _TRACKED_EVENT_NAMES = set(['requestStart', 'loadEventStart', 'loadEventEnd']) |
29 | 30 |
30 | 31 |
31 def _GetBrowserPID(trace): | 32 def _GetBrowserPID(trace): |
32 """Get the browser PID from a trace. | 33 """Get the browser PID from a trace. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 """Pulls all the metrics from all the traces of a sandwich run directory. | 139 """Pulls all the metrics from all the traces of a sandwich run directory. |
139 | 140 |
140 Args: | 141 Args: |
141 output_directory_path: The sandwich run's output directory to pull the | 142 output_directory_path: The sandwich run's output directory to pull the |
142 metrics from. | 143 metrics from. |
143 | 144 |
144 Returns: | 145 Returns: |
145 List of dictionaries with all _CSV_FIELD_NAMES's field set. | 146 List of dictionaries with all _CSV_FIELD_NAMES's field set. |
146 """ | 147 """ |
147 assert os.path.isdir(output_directory_path) | 148 assert os.path.isdir(output_directory_path) |
| 149 run_infos = None |
| 150 with open(os.path.join(output_directory_path, 'run_infos.json')) as f: |
| 151 run_infos = json.load(f) |
| 152 assert run_infos |
148 metrics = [] | 153 metrics = [] |
149 for node_name in os.listdir(output_directory_path): | 154 for node_name in os.listdir(output_directory_path): |
150 if not os.path.isdir(os.path.join(output_directory_path, node_name)): | 155 if not os.path.isdir(os.path.join(output_directory_path, node_name)): |
151 continue | 156 continue |
152 try: | 157 try: |
153 page_id = int(node_name) | 158 page_id = int(node_name) |
154 except ValueError: | 159 except ValueError: |
155 continue | 160 continue |
156 trace_path = os.path.join(output_directory_path, node_name, 'trace.json') | 161 trace_path = os.path.join(output_directory_path, node_name, 'trace.json') |
157 if not os.path.isfile(trace_path): | 162 if not os.path.isfile(trace_path): |
158 continue | 163 continue |
159 logging.info('processing \'%s\'' % trace_path) | 164 logging.info('processing \'%s\'' % trace_path) |
160 with open(trace_path) as trace_file: | 165 with open(trace_path) as trace_file: |
161 trace = json.load(trace_file) | 166 trace = json.load(trace_file) |
162 trace_metrics = _PullMetricsFromTrace(trace) | 167 trace_metrics = _PullMetricsFromTrace(trace) |
163 trace_metrics['id'] = page_id | 168 trace_metrics['id'] = page_id |
| 169 trace_metrics['url'] = run_infos['urls'][page_id] |
164 metrics.append(trace_metrics) | 170 metrics.append(trace_metrics) |
165 assert len(metrics) > 0, ('Looks like \'{}\' was not a sandwich ' + | 171 assert len(metrics) > 0, ('Looks like \'{}\' was not a sandwich ' + |
166 'run directory.').format(output_directory_path) | 172 'run directory.').format(output_directory_path) |
167 return metrics | 173 return metrics |
168 | 174 |
169 | 175 |
170 def main(): | 176 def main(): |
171 logging.basicConfig(level=logging.INFO) | 177 logging.basicConfig(level=logging.INFO) |
172 | 178 |
173 parser = argparse.ArgumentParser() | 179 parser = argparse.ArgumentParser() |
174 parser.add_argument('output', type=str, | 180 parser.add_argument('output', type=str, |
175 help='Output directory of run_sandwich.py command.') | 181 help='Output directory of run_sandwich.py command.') |
176 args = parser.parse_args() | 182 args = parser.parse_args() |
177 | 183 |
178 trace_metrics_list = _PullMetricsFromOutputDirectory(args.output) | 184 trace_metrics_list = _PullMetricsFromOutputDirectory(args.output) |
179 trace_metrics_list.sort(key=lambda e: e['id']) | 185 trace_metrics_list.sort(key=lambda e: e['id']) |
180 cs_file_path = os.path.join(args.output, 'trace_analysis.csv') | 186 cs_file_path = os.path.join(args.output, 'trace_analysis.csv') |
181 with open(cs_file_path, 'w') as csv_file: | 187 with open(cs_file_path, 'w') as csv_file: |
182 writer = csv.DictWriter(csv_file, fieldnames=_CSV_FIELD_NAMES) | 188 writer = csv.DictWriter(csv_file, fieldnames=_CSV_FIELD_NAMES) |
183 writer.writeheader() | 189 writer.writeheader() |
184 for trace_metrics in trace_metrics_list: | 190 for trace_metrics in trace_metrics_list: |
185 writer.writerow(trace_metrics) | 191 writer.writerow(trace_metrics) |
186 return 0 | 192 return 0 |
187 | 193 |
188 | 194 |
189 if __name__ == '__main__': | 195 if __name__ == '__main__': |
190 sys.exit(main()) | 196 sys.exit(main()) |
OLD | NEW |