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

Unified Diff: tools/android/loading/loading_trace.py

Issue 1707793002: sandwich: Refactor to use more existing code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses benoit's comments Created 4 years, 10 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 | « no previous file | tools/android/loading/pull_sandwich_metrics.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/android/loading/loading_trace.py
diff --git a/tools/android/loading/loading_trace.py b/tools/android/loading/loading_trace.py
index 720fa1d17fce6361613452b6a57f8d295cf3cc45..d383857a6c371aeda270bc9fcafd229078a76ac5 100644
--- a/tools/android/loading/loading_trace.py
+++ b/tools/android/loading/loading_trace.py
@@ -4,10 +4,12 @@
"""Represents the trace of a page load."""
+import json
import page_track
import request_track
import tracing
+
class LoadingTrace(object):
"""Represents the trace of a page load."""
_URL_KEY = 'url'
@@ -40,6 +42,12 @@ class LoadingTrace(object):
self._TRACING_KEY: self.tracing_track.ToJsonDict()}
return result
+ def ToJsonFile(self, json_path):
+ """Save a json file representing this instance."""
+ json_dict = self.ToJsonDict()
+ with open(json_path, 'w') as output_file:
+ json.dump(json_dict, output_file, indent=2)
+
@classmethod
def FromJsonDict(cls, json_dict):
"""Returns an instance from a dictionary returned by ToJsonDict()."""
@@ -53,3 +61,9 @@ class LoadingTrace(object):
json_dict[cls._TRACING_KEY])
return LoadingTrace(json_dict[cls._URL_KEY], json_dict[cls._METADATA_KEY],
page, request, tracing_track)
+
+ @classmethod
+ def FromJsonFile(cls, json_path):
+ """Returns an instance from a json file saved by ToJsonFile()."""
+ with open(json_path) as input_file:
+ return cls.FromJsonDict(json.load(input_file))
« no previous file with comments | « no previous file | tools/android/loading/pull_sandwich_metrics.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698