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

Side by Side 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: Integrates options layer slightly more 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 unified diff | Download patch
OLDNEW
1 # Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2016 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 """Represents the trace of a page load.""" 5 """Represents the trace of a page load."""
6 6
7 import json
7 import page_track 8 import page_track
8 import request_track 9 import request_track
9 import tracing 10 import tracing
10 11
12
11 class LoadingTrace(object): 13 class LoadingTrace(object):
12 """Represents the trace of a page load.""" 14 """Represents the trace of a page load."""
13 _URL_KEY = 'url' 15 _URL_KEY = 'url'
14 _METADATA_KEY = 'metadata' 16 _METADATA_KEY = 'metadata'
15 _PAGE_KEY = 'page_track' 17 _PAGE_KEY = 'page_track'
16 _REQUEST_KEY = 'request_track' 18 _REQUEST_KEY = 'request_track'
17 _TRACING_KEY = 'tracing_track' 19 _TRACING_KEY = 'tracing_track'
18 20
19 def __init__(self, url, metadata, page, request, tracing_track): 21 def __init__(self, url, metadata, page, request, tracing_track):
20 """Initializes a loading trace instance. 22 """Initializes a loading trace instance.
(...skipping 12 matching lines...) Expand all
33 self.tracing_track = tracing_track 35 self.tracing_track = tracing_track
34 36
35 def ToJsonDict(self): 37 def ToJsonDict(self):
36 """Returns a dictionary representing this instance.""" 38 """Returns a dictionary representing this instance."""
37 result = {self._URL_KEY: self.url, self._METADATA_KEY: self.metadata, 39 result = {self._URL_KEY: self.url, self._METADATA_KEY: self.metadata,
38 self._PAGE_KEY: self.page_track.ToJsonDict(), 40 self._PAGE_KEY: self.page_track.ToJsonDict(),
39 self._REQUEST_KEY: self.request_track.ToJsonDict(), 41 self._REQUEST_KEY: self.request_track.ToJsonDict(),
40 self._TRACING_KEY: self.tracing_track.ToJsonDict()} 42 self._TRACING_KEY: self.tracing_track.ToJsonDict()}
41 return result 43 return result
42 44
45 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.
46 """Save a json file representing this instance."""
47 json_dict = self.ToJsonDict()
48 with open(json_path, 'w') as output_file:
49 json.dump(json_dict, output_file, indent=2)
50
43 @classmethod 51 @classmethod
44 def FromJsonDict(cls, json_dict): 52 def FromJsonDict(cls, json_dict):
45 """Returns an instance from a dictionary returned by ToJsonDict().""" 53 """Returns an instance from a dictionary returned by ToJsonDict()."""
46 keys = (cls._URL_KEY, cls._METADATA_KEY, cls._PAGE_KEY, cls._REQUEST_KEY, 54 keys = (cls._URL_KEY, cls._METADATA_KEY, cls._PAGE_KEY, cls._REQUEST_KEY,
47 cls._TRACING_KEY) 55 cls._TRACING_KEY)
48 assert all(key in json_dict for key in keys) 56 assert all(key in json_dict for key in keys)
49 page = page_track.PageTrack.FromJsonDict(json_dict[cls._PAGE_KEY]) 57 page = page_track.PageTrack.FromJsonDict(json_dict[cls._PAGE_KEY])
50 request = request_track.RequestTrack.FromJsonDict( 58 request = request_track.RequestTrack.FromJsonDict(
51 json_dict[cls._REQUEST_KEY]) 59 json_dict[cls._REQUEST_KEY])
52 tracing_track = tracing.TracingTrack.FromJsonDict( 60 tracing_track = tracing.TracingTrack.FromJsonDict(
53 json_dict[cls._TRACING_KEY]) 61 json_dict[cls._TRACING_KEY])
54 return LoadingTrace(json_dict[cls._URL_KEY], json_dict[cls._METADATA_KEY], 62 return LoadingTrace(json_dict[cls._URL_KEY], json_dict[cls._METADATA_KEY],
55 page, request, tracing_track) 63 page, request, tracing_track)
64
65 @classmethod
66 def FromJsonFile(cls, json_path):
67 """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.
68 with open(json_path) as input_file:
69 return cls.FromJsonDict(json.load(input_file))
70 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
OLDNEW
« no previous file with comments | « no previous file | tools/android/loading/pull_sandwich_metrics.py » ('j') | tools/android/loading/run_sandwich.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698