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

Unified Diff: telemetry/telemetry/value/trace.py

Issue 3007313002: Revert of Plumb trace canonicalUrl through TelemetryInfo. (Closed)
Patch Set: Created 3 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « telemetry/telemetry/internal/story_runner.py ('k') | telemetry/telemetry/value/trace_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: telemetry/telemetry/value/trace.py
diff --git a/telemetry/telemetry/value/trace.py b/telemetry/telemetry/value/trace.py
index 301f297bfe75ec753169493e46ad587f162e597a..fe784520d8574c21f6c95d484650ec9d0672144e 100644
--- a/telemetry/telemetry/value/trace.py
+++ b/telemetry/telemetry/value/trace.py
@@ -2,8 +2,10 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import datetime
import logging
import os
+import random
import shutil
import sys
import tempfile
@@ -17,9 +19,7 @@
class TraceValue(value_module.Value):
- def __init__(self, page, trace_data, important=False, description=None,
- file_path=None, remote_path=None, upload_bucket=None,
- cloud_url=None):
+ def __init__(self, page, trace_data, important=False, description=None):
"""A value that contains a TraceData object and knows how to
output it.
@@ -31,10 +31,7 @@
page, name='trace', units='', important=important,
description=description, tir_label=None, grouping_keys=None)
self._temp_file = self._GetTempFileHandle(trace_data)
- self._file_path = file_path
- self._remote_path = remote_path
- self._upload_bucket = upload_bucket
- self._cloud_url = cloud_url
+ self._cloud_url = None
self._serialized_file_handle = None
@property
@@ -125,14 +122,22 @@
d['cloud_url'] = self._cloud_url
return d
- def Serialize(self):
- if self._temp_file is None or self._file_path is None:
+ def Serialize(self, dir_path):
+ if self._temp_file is None:
raise ValueError('Tried to serialize nonexistent trace.')
- shutil.copy(self._temp_file.GetAbsPath(), self._file_path)
- self._serialized_file_handle = file_handle.FromFilePath(self._file_path)
+ if self.page:
+ file_name = self.page.file_safe_name
+ else:
+ file_name = ''
+ file_name += str(self._temp_file.id)
+ file_name += datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
+ file_name += self._temp_file.extension
+ file_path = os.path.abspath(os.path.join(dir_path, file_name))
+ shutil.copy(self._temp_file.GetAbsPath(), file_path)
+ self._serialized_file_handle = file_handle.FromFilePath(file_path)
return self._serialized_file_handle
- def UploadToCloud(self):
+ def UploadToCloud(self, bucket):
if self._temp_file is None:
raise ValueError('Tried to upload nonexistent trace to Cloud Storage.')
try:
@@ -140,8 +145,13 @@
fh = self._serialized_file_handle
else:
fh = self._temp_file
- cloud_storage.Insert(
- self._upload_bucket, self._remote_path, fh.GetAbsPath())
+ remote_path = ('trace-file-id_%s-%s-%d%s' % (
+ fh.id,
+ datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S'),
+ random.randint(1, 100000),
+ fh.extension))
+ self._cloud_url = cloud_storage.Insert(
+ bucket, remote_path, fh.GetAbsPath())
sys.stderr.write(
'View generated trace files online at %s for story %s\n' %
(self._cloud_url, self.page.name if self.page else 'unknown'))
« no previous file with comments | « telemetry/telemetry/internal/story_runner.py ('k') | telemetry/telemetry/value/trace_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698