| OLD | NEW |
| 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 datetime | 5 import datetime |
| 6 import logging | 6 import logging |
| 7 import os | 7 import os |
| 8 import random | 8 import random |
| 9 import shutil | 9 import shutil |
| 10 import StringIO |
| 10 import sys | 11 import sys |
| 11 import tempfile | 12 import tempfile |
| 12 | 13 |
| 13 from telemetry.timeline import trace_data as trace_data_module | 14 from telemetry.timeline import trace_data as trace_data_module |
| 14 from telemetry.core import util | 15 from telemetry.core import util |
| 15 from telemetry.util import cloud_storage | 16 from telemetry.util import cloud_storage |
| 16 from telemetry.util import file_handle | 17 from telemetry.util import file_handle |
| 17 from telemetry import value as value_module | 18 from telemetry import value as value_module |
| 18 | 19 |
| 19 # Bring in tv module for transforming raw trace to html form. | 20 # Bring in tv module for transforming raw trace to html form. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 32 an index, files.html, linking to each of these files. | 33 an index, files.html, linking to each of these files. |
| 33 """ | 34 """ |
| 34 super(TraceValue, self).__init__( | 35 super(TraceValue, self).__init__( |
| 35 page, name='trace', units='', important=important, | 36 page, name='trace', units='', important=important, |
| 36 description=description, tir_label=None) | 37 description=description, tir_label=None) |
| 37 self._temp_file = self._GetTempFileHandle(trace_data) | 38 self._temp_file = self._GetTempFileHandle(trace_data) |
| 38 self._cloud_url = None | 39 self._cloud_url = None |
| 39 self._serialized_file_handle = None | 40 self._serialized_file_handle = None |
| 40 | 41 |
| 41 def _GetTempFileHandle(self, trace_data): | 42 def _GetTempFileHandle(self, trace_data): |
| 42 tf = tempfile.NamedTemporaryFile(delete=False, suffix='.html') | |
| 43 if self.page: | 43 if self.page: |
| 44 title = self.page.display_name | 44 title = self.page.display_name |
| 45 else: | 45 else: |
| 46 title = '' | 46 title = '' |
| 47 content = StringIO.StringIO() |
| 47 trace2html.WriteHTMLForTraceDataToFile( | 48 trace2html.WriteHTMLForTraceDataToFile( |
| 48 [trace_data.GetEventsFor(trace_data_module.CHROME_TRACE_PART)], | 49 [trace_data.GetEventsFor(trace_data_module.CHROME_TRACE_PART)], |
| 49 title, | 50 title, |
| 50 tf) | 51 content) |
| 52 tf = tempfile.NamedTemporaryFile(delete=False, suffix='.html') |
| 53 tf.write(content.getvalue().encode('utf-8')) |
| 51 tf.close() | 54 tf.close() |
| 52 return file_handle.FromTempFile(tf) | 55 return file_handle.FromTempFile(tf) |
| 53 | 56 |
| 54 def __repr__(self): | 57 def __repr__(self): |
| 55 if self.page: | 58 if self.page: |
| 56 page_name = self.page.url | 59 page_name = self.page.url |
| 57 else: | 60 else: |
| 58 page_name = None | 61 page_name = None |
| 59 return 'TraceValue(%s, %s)' % (page_name, self.name) | 62 return 'TraceValue(%s, %s)' % (page_name, self.name) |
| 60 | 63 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 fh.extension)) | 145 fh.extension)) |
| 143 self._cloud_url = cloud_storage.Insert( | 146 self._cloud_url = cloud_storage.Insert( |
| 144 bucket, remote_path, fh.GetAbsPath()) | 147 bucket, remote_path, fh.GetAbsPath()) |
| 145 sys.stderr.write( | 148 sys.stderr.write( |
| 146 'View generated trace files online at %s for page %s\n' % | 149 'View generated trace files online at %s for page %s\n' % |
| 147 (self._cloud_url, self.page.url if self.page else 'unknown')) | 150 (self._cloud_url, self.page.url if self.page else 'unknown')) |
| 148 return self._cloud_url | 151 return self._cloud_url |
| 149 except cloud_storage.PermissionError as e: | 152 except cloud_storage.PermissionError as e: |
| 150 logging.error('Cannot upload trace files to cloud storage due to ' | 153 logging.error('Cannot upload trace files to cloud storage due to ' |
| 151 ' permission error: %s' % e.message) | 154 ' permission error: %s' % e.message) |
| OLD | NEW |