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

Side by Side Diff: telemetry/telemetry/internal/results/page_test_results.py

Issue 2342023005: Outputting chart json for disabled tests. (Closed)
Patch Set: Review comments Created 4 years, 2 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
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 collections 5 import collections
6 import copy 6 import copy
7 import datetime 7 import datetime
8 import logging 8 import logging
9 import random 9 import random
10 import sys 10 import sys
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 d['storyGroupingKeys'] = self.story_grouping_keys 103 d['storyGroupingKeys'] = self.story_grouping_keys
104 d['storyRepeatCounter'] = self.story_repeat_counter 104 d['storyRepeatCounter'] = self.story_repeat_counter
105 d['storyUrl'] = self.story_url 105 d['storyUrl'] = self.story_url
106 d['storysetRepeatCounter'] = self.storyset_repeat_counter 106 d['storysetRepeatCounter'] = self.storyset_repeat_counter
107 return d 107 return d
108 108
109 109
110 class PageTestResults(object): 110 class PageTestResults(object):
111 def __init__(self, output_formatters=None, 111 def __init__(self, output_formatters=None,
112 progress_reporter=None, trace_tag='', output_dir=None, 112 progress_reporter=None, trace_tag='', output_dir=None,
113 value_can_be_added_predicate=lambda v, is_first: True): 113 value_can_be_added_predicate=lambda v, is_first: True,
114 benchmark_enabled=True):
114 """ 115 """
115 Args: 116 Args:
116 output_formatters: A list of output formatters. The output 117 output_formatters: A list of output formatters. The output
117 formatters are typically used to format the test results, such 118 formatters are typically used to format the test results, such
118 as CsvPivotTableOutputFormatter, which output the test results as CSV. 119 as CsvPivotTableOutputFormatter, which output the test results as CSV.
119 progress_reporter: An instance of progress_reporter.ProgressReporter, 120 progress_reporter: An instance of progress_reporter.ProgressReporter,
120 to be used to output test status/results progressively. 121 to be used to output test status/results progressively.
121 trace_tag: A string to append to the buildbot trace name. Currently only 122 trace_tag: A string to append to the buildbot trace name. Currently only
122 used for buildbot. 123 used for buildbot.
123 output_dir: A string specified the directory where to store the test 124 output_dir: A string specified the directory where to store the test
(...skipping 25 matching lines...) Expand all
149 self._pages_to_profiling_files = collections.defaultdict(list) 150 self._pages_to_profiling_files = collections.defaultdict(list)
150 self._pages_to_profiling_files_cloud_url = collections.defaultdict(list) 151 self._pages_to_profiling_files_cloud_url = collections.defaultdict(list)
151 152
152 # You'd expect this to be a set(), but Values are dictionaries, which are 153 # You'd expect this to be a set(), but Values are dictionaries, which are
153 # unhashable. We could wrap Values with custom __eq/hash__, but we don't 154 # unhashable. We could wrap Values with custom __eq/hash__, but we don't
154 # actually need set-ness in python. 155 # actually need set-ness in python.
155 self._value_set = [] 156 self._value_set = []
156 157
157 self._iteration_info = IterationInfo() 158 self._iteration_info = IterationInfo()
158 159
160 # State of the benchmark this set of results represents.
161 self._benchmark_enabled = benchmark_enabled
162
159 @property 163 @property
160 def iteration_info(self): 164 def iteration_info(self):
161 return self._iteration_info 165 return self._iteration_info
162 166
163 @property 167 @property
164 def value_set(self): 168 def value_set(self):
165 return self._value_set 169 return self._value_set
166 170
167 def __copy__(self): 171 def __copy__(self):
168 cls = self.__class__ 172 cls = self.__class__
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 page: The current page under test. 273 page: The current page under test.
270 """ 274 """
271 assert self._current_page_run, 'Did not call WillRunPage.' 275 assert self._current_page_run, 'Did not call WillRunPage.'
272 self._progress_reporter.DidRunPage(self) 276 self._progress_reporter.DidRunPage(self)
273 self._all_page_runs.append(self._current_page_run) 277 self._all_page_runs.append(self._current_page_run)
274 self._all_stories.add(self._current_page_run.story) 278 self._all_stories.add(self._current_page_run.story)
275 self._current_page_run = None 279 self._current_page_run = None
276 280
277 def AddValue(self, value): 281 def AddValue(self, value):
278 assert self._current_page_run, 'Not currently running test.' 282 assert self._current_page_run, 'Not currently running test.'
283 assert self._benchmark_enabled, 'Cannot add value to disabled results'
279 self._ValidateValue(value) 284 self._ValidateValue(value)
280 is_first_result = ( 285 is_first_result = (
281 self._current_page_run.story not in self._all_stories) 286 self._current_page_run.story not in self._all_stories)
282 287
283 story_keys = self._current_page_run.story.grouping_keys 288 story_keys = self._current_page_run.story.grouping_keys
284 289
285 if story_keys: 290 if story_keys:
286 for k, v in story_keys.iteritems(): 291 for k, v in story_keys.iteritems():
287 assert k not in value.grouping_keys, ( 292 assert k not in value.grouping_keys, (
288 'Tried to add story grouping key ' + k + ' already defined by ' + 293 'Tried to add story grouping key ' + k + ' already defined by ' +
(...skipping 28 matching lines...) Expand all
317 322
318 def _ValidateValue(self, value): 323 def _ValidateValue(self, value):
319 assert isinstance(value, value_module.Value) 324 assert isinstance(value, value_module.Value)
320 if value.name not in self._representative_value_for_each_value_name: 325 if value.name not in self._representative_value_for_each_value_name:
321 self._representative_value_for_each_value_name[value.name] = value 326 self._representative_value_for_each_value_name[value.name] = value
322 representative_value = self._representative_value_for_each_value_name[ 327 representative_value = self._representative_value_for_each_value_name[
323 value.name] 328 value.name]
324 assert value.IsMergableWith(representative_value) 329 assert value.IsMergableWith(representative_value)
325 330
326 def PrintSummary(self): 331 def PrintSummary(self):
327 self._progress_reporter.DidFinishAllTests(self) 332 if self._benchmark_enabled:
333 self._progress_reporter.DidFinishAllTests(self)
328 334
329 # Only serialize the trace if output_format is json. 335 # Only serialize the trace if output_format is json.
330 if (self._output_dir and 336 if (self._output_dir and
331 any(isinstance(o, json_output_formatter.JsonOutputFormatter) 337 any(isinstance(o, json_output_formatter.JsonOutputFormatter)
332 for o in self._output_formatters)): 338 for o in self._output_formatters)):
333 self._SerializeTracesToDirPath(self._output_dir) 339 self._SerializeTracesToDirPath(self._output_dir)
334 for output_formatter in self._output_formatters: 340 for output_formatter in self._output_formatters:
335 output_formatter.Format(self) 341 output_formatter.Format(self)
342 else:
343 for output_formatter in self._output_formatters:
344 output_formatter.FormatDisabled(self)
336 345
337 def FindValues(self, predicate): 346 def FindValues(self, predicate):
338 """Finds all values matching the specified predicate. 347 """Finds all values matching the specified predicate.
339 348
340 Args: 349 Args:
341 predicate: A function that takes a Value and returns a bool. 350 predicate: A function that takes a Value and returns a bool.
342 Returns: 351 Returns:
343 A list of values matching |predicate|. 352 A list of values matching |predicate|.
344 """ 353 """
345 values = [] 354 values = []
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 try: 392 try:
384 cloud_url = cloud_storage.Insert( 393 cloud_url = cloud_storage.Insert(
385 bucket, remote_path, file_handle.GetAbsPath()) 394 bucket, remote_path, file_handle.GetAbsPath())
386 sys.stderr.write( 395 sys.stderr.write(
387 'View generated profiler files online at %s for page %s\n' % 396 'View generated profiler files online at %s for page %s\n' %
388 (cloud_url, page.display_name)) 397 (cloud_url, page.display_name))
389 self._pages_to_profiling_files_cloud_url[page].append(cloud_url) 398 self._pages_to_profiling_files_cloud_url[page].append(cloud_url)
390 except cloud_storage.PermissionError as e: 399 except cloud_storage.PermissionError as e:
391 logging.error('Cannot upload profiling files to cloud storage due to ' 400 logging.error('Cannot upload profiling files to cloud storage due to '
392 ' permission error: %s' % e.message) 401 ' permission error: %s' % e.message)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698