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

Side by Side Diff: tools/android/loading/loading_trace.py

Issue 2047463002: Set tracing categories explicitly in Clovis and Sandwich (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 datetime 7 import datetime
8 import json 8 import json
9 import time 9 import time
10 10
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 page, request, tracing_track) 69 page, request, tracing_track)
70 70
71 @classmethod 71 @classmethod
72 def FromJsonFile(cls, json_path): 72 def FromJsonFile(cls, json_path):
73 """Returns an instance from a json file saved by ToJsonFile().""" 73 """Returns an instance from a json file saved by ToJsonFile()."""
74 with open(json_path) as input_file: 74 with open(json_path) as input_file:
75 return cls.FromJsonDict(json.load(input_file)) 75 return cls.FromJsonDict(json.load(input_file))
76 76
77 @classmethod 77 @classmethod
78 def RecordUrlNavigation( 78 def RecordUrlNavigation(
79 cls, url, connection, chrome_metadata, additional_categories=None, 79 cls, url, connection, chrome_metadata, categories,
80 timeout_seconds=devtools_monitor.DEFAULT_TIMEOUT_SECONDS): 80 timeout_seconds=devtools_monitor.DEFAULT_TIMEOUT_SECONDS):
81 """Create a loading trace by using controller to fetch url. 81 """Create a loading trace by using controller to fetch url.
82 82
83 Args: 83 Args:
84 url: (str) url to fetch. 84 url: (str) url to fetch.
85 connection: An opened devtools connection. 85 connection: An opened devtools connection.
86 chrome_metadata: Dictionary of chrome metadata. 86 chrome_metadata: Dictionary of chrome metadata.
87 additional_categories: ([str] or None) TracingTrack additional categories 87 categories: as in tracing.TracingTrack
88 to capture.
89 timeout_seconds: monitoring connection timeout in seconds. 88 timeout_seconds: monitoring connection timeout in seconds.
90 89
91 Returns: 90 Returns:
92 LoadingTrace instance. 91 LoadingTrace instance.
93 """ 92 """
94 page = page_track.PageTrack(connection) 93 page = page_track.PageTrack(connection)
95 request = request_track.RequestTrack(connection) 94 request = request_track.RequestTrack(connection)
96 trace = tracing.TracingTrack( 95 trace = tracing.TracingTrack(connection, categories)
97 connection,
98 additional_categories=additional_categories)
99 start_date_str = datetime.datetime.utcnow().isoformat() 96 start_date_str = datetime.datetime.utcnow().isoformat()
100 seconds_since_epoch=time.time() 97 seconds_since_epoch=time.time()
101 connection.MonitorUrl(url, timeout_seconds=timeout_seconds) 98 connection.MonitorUrl(url, timeout_seconds=timeout_seconds)
102 trace = cls(url, chrome_metadata, page, request, trace) 99 trace = cls(url, chrome_metadata, page, request, trace)
103 trace.metadata.update(date=start_date_str, 100 trace.metadata.update(date=start_date_str,
104 seconds_since_epoch=seconds_since_epoch) 101 seconds_since_epoch=seconds_since_epoch)
105 return trace 102 return trace
106 103
107 @property 104 @property
108 def tracing_track(self): 105 def tracing_track(self):
109 if not self._tracing_track: 106 if not self._tracing_track:
110 self._RestoreTracingTrack() 107 self._RestoreTracingTrack()
111 return self._tracing_track 108 return self._tracing_track
112 109
113 def Slim(self): 110 def Slim(self):
114 """Slims the memory usage of a trace by dropping the TraceEvents from it. 111 """Slims the memory usage of a trace by dropping the TraceEvents from it.
115 112
116 The tracing track is restored on-demand when accessed. 113 The tracing track is restored on-demand when accessed.
117 """ 114 """
118 self._tracing_json_str = json.dumps(self._tracing_track.ToJsonDict()) 115 self._tracing_json_str = json.dumps(self._tracing_track.ToJsonDict())
119 self._tracing_track = None 116 self._tracing_track = None
120 117
121 def _RestoreTracingTrack(self): 118 def _RestoreTracingTrack(self):
122 if not self._tracing_json_str: 119 if not self._tracing_json_str:
123 return None 120 return None
124 self._tracing_track = tracing.TracingTrack.FromJsonDict( 121 self._tracing_track = tracing.TracingTrack.FromJsonDict(
125 json.loads(self._tracing_json_str)) 122 json.loads(self._tracing_json_str))
126 self._tracing_json_str = None 123 self._tracing_json_str = None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698