[Telemetry] Add 'name' attribute for pages, which allows for more human-readable printing

BUG=284547

Review URL: https://chromiumcodereview.appspot.com/23545023

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221312 0039d316-1c4b-4281-b951-d872f2087c98
parent 09510776
......@@ -97,7 +97,7 @@ class BlinkPerf(page_measurement.PageMeasurement):
parts = line.split()
values = [float(v.replace(',', '')) for v in parts[1:-1]]
units = parts[-1]
metric = page.display_url.split('.')[0].replace('/', '_')
metric = page.display_name.split('.')[0].replace('/', '_')
results.Add(metric, units, values)
break
......
......@@ -34,7 +34,7 @@ class LoadingProfile(page_measurement.PageMeasurement):
def WillNavigateToPage(self, page, tab):
tab.browser.StartProfiling(perf_profiler.PerfProfiler.name(),
os.path.join(tempfile.mkdtemp(),
page.url_as_file_safe_name))
page.file_safe_name))
def MeasurePage(self, page, tab, results):
# In current telemetry tests, all tests wait for DocumentComplete state,
......
......@@ -26,7 +26,7 @@ class SkpicturePrinter(page_measurement.PageMeasurement):
raise Exception('Please specify --skp-outdir')
outpath = os.path.abspath(
os.path.join(skp_outdir,
page.url_as_file_safe_name))
page.file_safe_name))
# Replace win32 path separator char '\' with '\\'.
js = _JS.format(outpath.replace('\\', '\\\\'))
tab.EvaluateJavaScript(js)
......
......@@ -183,7 +183,7 @@ class V8ObjectStatsMetric(Metric):
})(%s);
""" % json.dumps(_COUNTER_NAMES))
if not self._results:
logging.warning('No V8 object stats from website: ' + page.display_url)
logging.warning('No V8 object stats from website: ' + page.display_name)
def AddResults(self, tab, results):
"""Add results for this page to the results object."""
......
......@@ -19,8 +19,8 @@ class BlockPageMeasurementResults(
super(BlockPageMeasurementResults, self).DidMeasurePage()
return
lines = ['url: %s' %
self.values_for_current_page.page.url]
lines = ['name: %s' %
self.values_for_current_page.page.display_name]
sorted_measurement_names = page_values.measurement_names
sorted_measurement_names.sort()
......
......@@ -53,10 +53,10 @@ class BlockPageMeasurementResultsTest(unittest.TestCase):
results.DidMeasurePage()
expected = [
['url', 'http://www.foo.com/'],
['name', 'http://www.foo.com/'],
['foo (seconds)', '3'],
[''],
['url', 'http://www.bar.com/'],
['name', 'http://www.bar.com/'],
['bar (seconds)', '4'],
['']
]
......
......@@ -34,16 +34,16 @@ class BuildbotPageMeasurementResults(
# Print out the list of unique pages.
# Use a set and a list to efficiently create an order preserving list of
# unique URLs.
unique_page_urls = []
unique_page_urls_set = set()
# unique page display_names.
unique_pages = []
unique_pages_set = set()
for page_values in success_page_results:
url = page_values.page.display_url
if url in unique_page_urls_set:
name = page_values.page.display_name
if name in unique_pages_set:
continue
unique_page_urls.append(url)
unique_page_urls_set.add(url)
perf_tests_helper.PrintPages(unique_page_urls)
unique_pages.append(name)
unique_pages_set.add(name)
perf_tests_helper.PrintPages(unique_pages)
# Build the results summary.
results_summary = defaultdict(list)
......@@ -56,48 +56,51 @@ class BuildbotPageMeasurementResults(
measurement_units_type = (measurement_name,
value.units,
value.data_type)
value_url = (value.value, page_values.page.display_url)
results_summary[measurement_units_type].append(value_url)
value_and_display_name = (value.value, page_values.page.display_name)
results_summary[measurement_units_type].append(value_and_display_name)
# Output the results summary sorted by name, then units, then data type.
for measurement_units_type, value_url_list in sorted(
# Output the results summary sorted by measurement name, then units, then
# data type.
for measurement_units_type, value_and_display_name_list in sorted(
results_summary.iteritems()):
measurement, units, data_type = measurement_units_type
if 'histogram' in data_type:
by_url_data_type = 'unimportant-histogram'
by_name_data_type = 'unimportant-histogram'
else:
by_url_data_type = 'unimportant'
by_name_data_type = 'unimportant'
if '.' in measurement and 'histogram' not in data_type:
measurement, trace = measurement.split('.', 1)
trace += self._trace_tag
else:
trace = measurement + self._trace_tag
# Print individual _by_url results if there's more than 1 successful page,
# or if there's exactly 1 successful page but a failure exists.
if not self._trace_tag and (len(value_url_list) > 1 or
((self.errors or self.failures) and len(value_url_list) == 1)):
url_value_map = defaultdict(list)
for value, url in value_url_list:
if 'histogram' in data_type and url_value_map[url]:
# Print individual _by_name results if there's more than 1 successful
# page, or if there's exactly 1 successful page but a failure exists.
if not self._trace_tag and (len(value_and_display_name_list) > 1 or
((self.errors or self.failures) and
len(value_and_display_name_list) == 1)):
name_value_map = defaultdict(list)
for value, name in value_and_display_name_list:
if 'histogram' in data_type and name_value_map[name]:
# TODO(tonyg/marja): The histogram processing code only accepts one
# histogram, so we only report the first histogram. Once histograms
# support aggregating multiple values, this can be removed.
continue
url_value_map[url].append(value)
for url in unique_page_urls:
if not len(url_value_map[url]):
name_value_map[name].append(value)
for name in unique_pages:
if not len(name_value_map[name]):
continue
self._PrintPerfResult(measurement + '_by_url', url,
url_value_map[url], units, by_url_data_type)
self._PrintPerfResult(measurement + '_by_name', name,
name_value_map[name], units, by_name_data_type)
# If there were no page failures, print the average data.
# For histograms, we don't print the average data, only the _by_url,
# unless there is only 1 page in which case the _by_urls are omitted.
# For histograms, we don't print the average data, only the _by_name,
# unless there is only 1 page in which case the _by_names are omitted.
if not (self.errors or self.failures):
if 'histogram' not in data_type or len(value_url_list) == 1:
values = [i[0] for i in value_url_list]
if ('histogram' not in data_type or
len(value_and_display_name_list) == 1):
values = [i[0] for i in value_and_display_name_list]
if isinstance(values[0], list):
values = list(chain.from_iterable(values))
self._PrintPerfResult(measurement, trace, values, units, data_type)
......
......@@ -43,8 +43,8 @@ class BuildbotPageMeasurementResultsTest(unittest.TestCase):
measurement_results.DidMeasurePage()
measurement_results.PrintSummary()
expected = ['RESULT a_by_url: http___www.foo.com_= 3 seconds',
'RESULT a_by_url: http___www.bar.com_= 7 seconds',
expected = ['RESULT a_by_name: http___www.foo.com_= 3 seconds',
'RESULT a_by_name: http___www.bar.com_= 7 seconds',
'*RESULT a: a= [3,7] seconds\nAvg a: 5.000000seconds\n' +
'Sd a: 2.828427seconds']
self.assertEquals(measurement_results.results, expected)
......@@ -69,13 +69,13 @@ class BuildbotPageMeasurementResultsTest(unittest.TestCase):
measurement_results.DidMeasurePage()
measurement_results.PrintSummary()
expected = ['RESULT a_by_url: http___www.foo.com_= 3 seconds',
'RESULT a_by_url: http___www.bar.com_= 3 seconds',
'RESULT a_by_url: http___www.baz.com_= 7 seconds',
expected = ['RESULT a_by_name: http___www.foo.com_= 3 seconds',
'RESULT a_by_name: http___www.bar.com_= 3 seconds',
'RESULT a_by_name: http___www.baz.com_= 7 seconds',
'*RESULT a: a= [3,3,7] seconds\nAvg a: 4.333333seconds\n' +
'Sd a: 2.309401seconds',
'RESULT b_by_url: http___www.foo.com_= 10 seconds',
'RESULT b_by_url: http___www.bar.com_= 10 seconds',
'RESULT b_by_name: http___www.foo.com_= 10 seconds',
'RESULT b_by_name: http___www.bar.com_= 10 seconds',
'*RESULT b: b= [10,10] seconds\nAvg b: 10.000000seconds']
self.assertEquals(measurement_results.results, expected)
......@@ -94,7 +94,7 @@ class BuildbotPageMeasurementResultsTest(unittest.TestCase):
measurement_results.DidMeasurePage()
measurement_results.PrintSummary()
expected = ['RESULT a_by_url: http___www.bar.com_= 7 seconds']
expected = ['RESULT a_by_name: http___www.bar.com_= 7 seconds']
self.assertEquals(measurement_results.results, expected)
def test_repeated_pageset_one_iteration_one_page_fails(self):
......@@ -120,8 +120,9 @@ class BuildbotPageMeasurementResultsTest(unittest.TestCase):
measurement_results.DidMeasurePage()
measurement_results.PrintSummary()
expected = ['RESULT a_by_url: http___www.foo.com_= [3,4] seconds\n' +
'Avg a_by_url: 3.500000seconds\nSd a_by_url: 0.707107seconds']
expected = ['RESULT a_by_name: http___www.foo.com_= [3,4] seconds\n' +
'Avg a_by_name: 3.500000seconds\n' +
'Sd a_by_name: 0.707107seconds']
self.assertEquals(measurement_results.results, expected)
def test_repeated_pageset(self):
......@@ -145,12 +146,15 @@ class BuildbotPageMeasurementResultsTest(unittest.TestCase):
measurement_results.DidMeasurePage()
measurement_results.PrintSummary()
expected = ['RESULT a_by_url: http___www.foo.com_= [3,4] seconds\n' +
'Avg a_by_url: 3.500000seconds\nSd a_by_url: 0.707107seconds',
'RESULT a_by_url: http___www.bar.com_= [7,8] seconds\n' +
'Avg a_by_url: 7.500000seconds\nSd a_by_url: 0.707107seconds',
expected = ['RESULT a_by_name: http___www.foo.com_= [3,4] seconds\n' +
'Avg a_by_name: 3.500000seconds\n' +
'Sd a_by_name: 0.707107seconds',
'RESULT a_by_name: http___www.bar.com_= [7,8] seconds\n' +
'Avg a_by_name: 7.500000seconds\n' +
'Sd a_by_name: 0.707107seconds',
'*RESULT a: a= [3,7,4,8] seconds\n' +
'Avg a: 5.500000seconds\nSd a: 2.380476seconds'
'Avg a: 5.500000seconds\n'
'Sd a: 2.380476seconds'
]
self.assertEquals(
measurement_results.results,
......@@ -177,12 +181,15 @@ class BuildbotPageMeasurementResultsTest(unittest.TestCase):
measurement_results.DidMeasurePage()
measurement_results.PrintSummary()
expected = ['RESULT a_by_url: http___www.foo.com_= [3,4] seconds\n' +
'Avg a_by_url: 3.500000seconds\nSd a_by_url: 0.707107seconds',
'RESULT a_by_url: http___www.bar.com_= [7,8] seconds\n' +
'Avg a_by_url: 7.500000seconds\nSd a_by_url: 0.707107seconds',
expected = ['RESULT a_by_name: http___www.foo.com_= [3,4] seconds\n' +
'Avg a_by_name: 3.500000seconds\n' +
'Sd a_by_name: 0.707107seconds',
'RESULT a_by_name: http___www.bar.com_= [7,8] seconds\n' +
'Avg a_by_name: 7.500000seconds\n' +
'Sd a_by_name: 0.707107seconds',
'*RESULT a: a= [3,4,7,8] seconds\n' +
'Avg a: 5.500000seconds\nSd a: 2.380476seconds'
'Avg a: 5.500000seconds\n' +
'Sd a: 2.380476seconds'
]
self.assertEquals(
measurement_results.results,
......@@ -209,8 +216,8 @@ class BuildbotPageMeasurementResultsTest(unittest.TestCase):
self.assertEquals(
measurement_results.results,
['RESULT b_by_url: http___www.foo.com_= 2 seconds',
'RESULT b_by_url: http___www.bar.com_= 3 seconds',
['RESULT b_by_name: http___www.foo.com_= 2 seconds',
'RESULT b_by_name: http___www.bar.com_= 3 seconds',
'*RESULT b: b= [2,3] seconds\n' +
'Avg b: 2.500000seconds\nSd b: 0.707107seconds',
'*RESULT a: a= 1 seconds',
......@@ -261,10 +268,10 @@ class BuildbotPageMeasurementResultsTest(unittest.TestCase):
measurement_results.PrintSummary()
expected = [
'HISTOGRAM a_by_url: http___www.foo.com_= ' +
'HISTOGRAM a_by_name: http___www.foo.com_= ' +
'{"buckets": [{"low": 1, "high": 2, "count": 1}]}\n' +
'Avg a_by_url: 1.500000',
'HISTOGRAM a_by_url: http___www.bar.com_= ' +
'Avg a_by_name: 1.500000',
'HISTOGRAM a_by_name: http___www.bar.com_= ' +
'{"buckets": [{"low": 2, "high": 3, "count": 1}]}\n' +
'Avg a_by_url: 2.500000']
'Avg a_by_name: 2.500000']
self.assertEquals(measurement_results.results, expected)
......@@ -70,7 +70,7 @@ PageMeasurement.results_are_the_same_on_every_page to return False.
self._did_output_header = True
self._header_names_written_to_writer = list(all_measurement_names)
row = ['url']
row = ['page_name']
for measurement_name in all_measurement_names:
measurement_data = \
self.all_measurements_that_have_been_seen[measurement_name]
......@@ -78,7 +78,7 @@ PageMeasurement.results_are_the_same_on_every_page to return False.
self._results_writer.writerow(row)
def _OutputValuesForPage(self, page_values):
row = [page_values.page.display_url]
row = [page_values.page.display_name]
for measurement_name in self._header_names_written_to_writer:
value = page_values.FindValueByMeasurementName(measurement_name)
if value:
......
......@@ -53,7 +53,7 @@ class CsvPageMeasurementResultsTest(unittest.TestCase):
results.DidMeasurePage()
self.assertEquals(
self.output_header_row,
['url', 'foo (seconds)'])
['page_name', 'foo (seconds)'])
self.assertEquals(
self.output_data_rows[0],
[self._page_set[0].url, '3'])
......@@ -96,11 +96,11 @@ class CsvPageMeasurementResultsTest(unittest.TestCase):
self.assertEquals(
self.output_header_row,
['url', 'bar (seconds)', 'foo (seconds)'])
['page_name', 'bar (seconds)', 'foo (seconds)'])
self.assertEquals(
self.output_data_rows,
[[self._page_set[0].url, '-', '3'],
[self._page_set[1].url, '4', '-']])
[[self._page_set[0].display_name, '-', '3'],
[self._page_set[1].display_name, '4', '-']])
def test_histogram(self):
results = NonPrintingCsvPageMeasurementResults(self._output, False)
......@@ -120,8 +120,8 @@ class CsvPageMeasurementResultsTest(unittest.TestCase):
self.assertEquals(
self.output_header_row,
['url', 'a ()'])
['page_name', 'a ()'])
self.assertEquals(
self.output_data_rows,
[[self._page_set[0].url, '1.5'],
[self._page_set[1].url, '2.5']])
[[self._page_set[0].display_name, '1.5'],
[self._page_set[1].display_name, '2.5']])
......@@ -70,12 +70,12 @@ class HtmlPageMeasurementResultsTest(unittest.TestCase):
'"units": "seconds", '
'"important": true'
'}, '
'"a_by_url.http://www.bar.com/": {'
'"a_by_name.http://www.bar.com/": {'
'"current": [7], '
'"units": "seconds", '
'"important": false'
'}, '
'"a_by_url.http://www.foo.com/": {'
'"a_by_name.http://www.foo.com/": {'
'"current": [3], '
'"units": "seconds", '
'"important": false'
......@@ -113,12 +113,12 @@ class HtmlPageMeasurementResultsTest(unittest.TestCase):
'"units": "seconds", '
'"important": true'
'}, '
'"a_by_url.http://www.bar.com/": {'
'"a_by_name.http://www.bar.com/": {'
'"current": [7], '
'"units": "seconds", '
'"important": false'
'}, '
'"a_by_url.http://www.foo.com/": {'
'"a_by_name.http://www.foo.com/": {'
'"current": [3], '
'"units": "seconds", '
'"important": false'
......@@ -139,12 +139,12 @@ class HtmlPageMeasurementResultsTest(unittest.TestCase):
'"units": "seconds", '
'"important": true'
'}, '
'"a_by_url.http://www.bar.com/": {'
'"a_by_name.http://www.bar.com/": {'
'"current": [8], '
'"units": "seconds", '
'"important": false'
'}, '
'"a_by_url.http://www.foo.com/": {'
'"a_by_name.http://www.foo.com/": {'
'"current": [4], '
'"units": "seconds", '
'"important": false'
......
......@@ -52,6 +52,7 @@ class Page(object):
# These attributes can be set dynamically by the page.
self.credentials = None
self.disabled = False
self.name = None
self.script_to_evaluate_on_commit = None
if attributes:
......@@ -88,14 +89,16 @@ class Page(object):
return os.path.split(path)
# A version of this page's URL that's safe to use as a filename.
@property
def url_as_file_safe_name(self):
def file_safe_name(self):
"""A version of display_name that's safe to use as a filename."""
# Just replace all special characters in the url with underscore.
return re.sub('[^a-zA-Z0-9]', '_', self.display_url)
return re.sub('[^a-zA-Z0-9]', '_', self.display_name)
@property
def display_url(self):
def display_name(self):
if self.name:
return self.name
if not self.is_local:
return self.url
url_paths = ['/'.join(p.url.strip('/').split('/')[:-1])
......
......@@ -98,7 +98,7 @@ class _RunState(object):
def StartProfiling(self, page, finder_options):
if not self.profiler_dir:
self.profiler_dir = tempfile.mkdtemp()
output_file = os.path.join(self.profiler_dir, page.url_as_file_safe_name)
output_file = os.path.join(self.profiler_dir, page.file_safe_name)
if finder_options.repeat_options.IsRepeating():
output_file = _GetSequentialFileName(output_file)
self.browser.StartProfiling(finder_options.profiler, output_file)
......
......@@ -57,8 +57,8 @@ class TestPage(unittest.TestCase):
{"url": "http://www.bar.com/"}
]
}, os.path.dirname(__file__))
self.assertEquals(ps[0].display_url, 'http://www.foo.com/')
self.assertEquals(ps[1].display_url, 'http://www.bar.com/')
self.assertEquals(ps[0].display_name, 'http://www.foo.com/')
self.assertEquals(ps[1].display_name, 'http://www.bar.com/')
def testDisplayUrlForHttps(self):
ps = page_set.PageSet.FromDict({
......@@ -69,8 +69,8 @@ class TestPage(unittest.TestCase):
{"url": "https://www.bar.com/"}
]
}, os.path.dirname(__file__))
self.assertEquals(ps[0].display_url, 'http://www.foo.com/')
self.assertEquals(ps[1].display_url, 'https://www.bar.com/')
self.assertEquals(ps[0].display_name, 'http://www.foo.com/')
self.assertEquals(ps[1].display_name, 'https://www.bar.com/')
def testDisplayUrlForFile(self):
ps = page_set.PageSet.FromDict({
......@@ -81,8 +81,8 @@ class TestPage(unittest.TestCase):
{"url": "file:///../../otherdir/bar.html"},
]
}, os.path.dirname(__file__))
self.assertEquals(ps[0].display_url, 'foo.html')
self.assertEquals(ps[1].display_url, 'bar.html')
self.assertEquals(ps[0].display_name, 'foo.html')
self.assertEquals(ps[1].display_name, 'bar.html')
def testDisplayUrlForFilesDifferingBySuffix(self):
ps = page_set.PageSet.FromDict({
......@@ -93,8 +93,8 @@ class TestPage(unittest.TestCase):
{"url": "file:///../../otherdir/foo1.html"},
]
}, os.path.dirname(__file__))
self.assertEquals(ps[0].display_url, 'foo.html')
self.assertEquals(ps[1].display_url, 'foo1.html')
self.assertEquals(ps[0].display_name, 'foo.html')
self.assertEquals(ps[1].display_name, 'foo1.html')
def testDisplayUrlForFileOfDifferentPaths(self):
ps = page_set.PageSet.FromDict({
......@@ -105,8 +105,8 @@ class TestPage(unittest.TestCase):
{"url": "file:///../../otherdir/bar.html"},
]
}, os.path.dirname(__file__))
self.assertEquals(ps[0].display_url, 'somedir/foo.html')
self.assertEquals(ps[1].display_url, 'otherdir/bar.html')
self.assertEquals(ps[0].display_name, 'somedir/foo.html')
self.assertEquals(ps[1].display_name, 'otherdir/bar.html')
def testDisplayUrlForFileDirectories(self):
ps = page_set.PageSet.FromDict({
......@@ -117,8 +117,8 @@ class TestPage(unittest.TestCase):
{"url": "file:///../../otherdir/bar/"},
]
}, os.path.dirname(__file__))
self.assertEquals(ps[0].display_url, 'foo')
self.assertEquals(ps[1].display_url, 'bar')
self.assertEquals(ps[0].display_name, 'foo')
self.assertEquals(ps[1].display_name, 'bar')
def testDisplayUrlForSingleFile(self):
ps = page_set.PageSet.FromDict({
......@@ -128,7 +128,7 @@ class TestPage(unittest.TestCase):
{"url": "file:///../../otherdir/foo.html"},
]
}, os.path.dirname(__file__))
self.assertEquals(ps[0].display_url, 'foo.html')
self.assertEquals(ps[0].display_name, 'foo.html')
def testDisplayUrlForSingleDirectory(self):
ps = page_set.PageSet.FromDict({
......@@ -138,4 +138,4 @@ class TestPage(unittest.TestCase):
{"url": "file:///../../otherdir/foo/"},
]
}, os.path.dirname(__file__))
self.assertEquals(ps[0].display_url, 'foo')
self.assertEquals(ps[0].display_name, 'foo')
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