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..d70384d21450a9b05fd5b6f7aec747bcb3f27b3d 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 SaveToJsonFile(self, json_path): |
Benoit L
2016/02/22 10:26:12
nit: ToJsonFile to be more consistent with the oth
gabadie
2016/02/22 11:05:06
Done.
|
+ """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,10 @@ 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 SaveToJsonFile().""" |
Benoit L
2016/02/22 10:26:13
nit: don't forget to update this docstring as well
gabadie
2016/02/22 11:05:06
Done.
|
+ with open(json_path) as input_file: |
+ return cls.FromJsonDict(json.load(input_file)) |
+ assert False |
Benoit L
2016/02/22 10:26:13
Is this really necessary?
gabadie
2016/02/22 11:05:06
Removed the assert. But yes this method is handy t
|