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

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

Issue 1964663003: [telemetry] Add Html2OutputFormatter for generating results2.html (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: fix Created 4 years, 7 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
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import datetime
6 import json
7 import logging
8 import os
9
10 from catapult_base import cloud_storage # pylint: disable=import-error
petrcermak 2016/05/18 10:43:20 Why does this trigger an import error?
benjhayden 2016/05/18 18:23:33 Copy-pasta. presubmit seems ok without it.
11
12 from telemetry.internal.results import output_formatter
13
14 import tracing_project
15
16 from py_vulcanize import generate
17
18
19 class Html2OutputFormatter(output_formatter.OutputFormatter):
20 def __init__(self, output_stream, reset_results, upload_results):
21 super(Html2OutputFormatter, self).__init__(output_stream)
22 self._upload_results = upload_results
23 if reset_results or not output_stream.read():
24 output_stream.write(self._GetHtmlTemplate())
25 output_stream.close()
26 self._output_filename = output_stream.name
petrcermak 2016/05/18 10:43:20 Is there any point in storing this when you can ac
benjhayden 2016/05/18 18:23:33 This is a bit of a work-around for how this output
27
28 def _GetHtmlTemplate(self):
29 project = tracing_project.TracingProject()
30 vulcanizer = project.CreateVulcanizer()
31 # TODO move results2html to telemetry and use source paths magic from
petrcermak 2016/05/18 10:43:20 nit: should be "TODO(username):" or at least "TODO
benjhayden 2016/05/18 18:23:33 I'm not sure who will do this or when.
eakuefner 2016/05/18 19:34:48 In this case I'd usually do TODO(#bug).
benjhayden 2016/05/18 20:03:55 Done.
32 # perf_insights_project
petrcermak 2016/05/18 10:43:20 nit: Add a period
benjhayden 2016/05/18 18:23:33 Done.
33 modules = ['tracing.results2html']
34 load_sequence = vulcanizer.CalcLoadSequenceForModuleNames(modules)
35 return generate.GenerateStandaloneHTMLAsString(load_sequence)
36
37 def Format(self, page_test_results):
38 with file(self._output_filename, 'a') as htmlfp:
petrcermak 2016/05/18 10:43:20 out of curiosity, what does "htmlfp" abbreviate? W
benjhayden 2016/05/18 18:23:33 "file pointer" from C, but "f" sgtm.
39 htmlfp.write('\n<script>\nvalues.addValueDicts(' +
petrcermak 2016/05/18 10:43:20 the following might be more readable: htmlfp.writ
benjhayden 2016/05/18 18:23:33 Done.
40 json.dumps(page_test_results.value_set) +
41 ');\n</script>\n')
42
43 if self._upload_results:
44 file_path = os.path.abspath(self._output_stream.name)
45 file_name = 'html-results/results-%s' % datetime.datetime.now().strftime(
46 '%Y-%m-%d_%H-%M-%S')
47 try:
48 cloud_storage.Insert(cloud_storage.PUBLIC_BUCKET, file_name, file_path)
49 print
50 print ('View online at '
51 'http://storage.googleapis.com/chromium-telemetry/%s'
52 % file_name)
53 except cloud_storage.PermissionError as e:
54 logging.error('Cannot upload profiling files to cloud storage due to '
55 ' permission error: %s' % e.message)
56 print
57 print 'View result at file://%s' % os.path.abspath(
58 self._output_stream.name)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698