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

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

Issue 2672803002: [Telemetry refactor] Migrate clients to new JavaScript API (batch 3) (Closed)
Patch Set: Created 3 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 """Library handling DevTools websocket interaction. 5 """Library handling DevTools websocket interaction.
6 """ 6 """
7 7
8 import datetime 8 import datetime
9 import httplib 9 import httplib
10 import json 10 import json
11 import logging 11 import logging
12 import os 12 import os
13 import sys 13 import sys
14 import time 14 import time
15 15
16 file_dir = os.path.dirname(__file__) 16 file_dir = os.path.dirname(__file__)
17 sys.path.append(os.path.join(file_dir, '..', '..', 'perf')) 17 sys.path.append(os.path.join(file_dir, '..', '..', 'perf'))
18 from chrome_telemetry_build import chromium_config 18 from chrome_telemetry_build import chromium_config
19 sys.path.append(chromium_config.GetTelemetryDir()) 19 sys.path.append(chromium_config.GetTelemetryDir())
20 20
21 from telemetry.internal.backends.chrome_inspector import inspector_websocket 21 from telemetry.internal.backends.chrome_inspector import inspector_websocket
22 from telemetry.internal.backends.chrome_inspector import websocket 22 from telemetry.internal.backends.chrome_inspector import websocket
23 from telemetry.util import js_template
pasko 2017/02/06 21:50:51 we try to avoid depending on libraries exported fr
23 24
24 import common_util 25 import common_util
25 26
26 27
27 DEFAULT_TIMEOUT_SECONDS = 10 28 DEFAULT_TIMEOUT_SECONDS = 10
28 29
29 _WEBSOCKET_TIMEOUT_SECONDS = 10 30 _WEBSOCKET_TIMEOUT_SECONDS = 10
30 31
31 32
32 class DevToolsConnectionException(Exception): 33 class DevToolsConnectionException(Exception):
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 assert self._monitoring_start_timestamp is not None 273 assert self._monitoring_start_timestamp is not None
273 current_time = datetime.datetime.now() 274 current_time = datetime.datetime.now()
274 stop_delay_duration_seconds = self._stop_delay_multiplier * ( 275 stop_delay_duration_seconds = self._stop_delay_multiplier * (
275 current_time - self._monitoring_start_timestamp).seconds 276 current_time - self._monitoring_start_timestamp).seconds
276 logging.info('Delaying monitoring stop for %.1fs', 277 logging.info('Delaying monitoring stop for %.1fs',
277 stop_delay_duration_seconds) 278 stop_delay_duration_seconds)
278 self._monitoring_stop_timestamp = ( 279 self._monitoring_stop_timestamp = (
279 current_time + datetime.timedelta( 280 current_time + datetime.timedelta(
280 seconds=stop_delay_duration_seconds)) 281 seconds=stop_delay_duration_seconds))
281 282
282 def ExecuteJavaScript(self, expression): 283 def ExecuteJavaScript2(self, expression, **kwargs):
283 """Run JavaScript expression. 284 """Run JavaScript expression.
284 285
285 Args: 286 Args:
286 expression: JavaScript expression to run. 287 expression: JavaScript expression to run.
287 288
288 Returns: 289 Returns:
289 The return value from the JavaScript expression. 290 The return value from the JavaScript expression.
290 """ 291 """
292 expression = js_template.Render(expression, **kwargs)
pasko 2017/02/02 20:15:49 the discussion in the bug is a leaning towards len
perezju 2017/02/03 09:31:45 You are right. Strictly speaking the changes in to
pasko 2017/02/06 21:50:51 Ah, I see. Actually we do not want to increase our
perezju 2017/02/07 10:02:21 To keep things simple I'll just discard the change
pasko 2017/02/07 18:57:29 Sounds good. Please add a comment with this link t
perezju 2017/02/08 09:58:34 Done.
291 response = self.SyncRequest('Runtime.evaluate', { 293 response = self.SyncRequest('Runtime.evaluate', {
292 'expression': expression, 294 'expression': expression,
293 'returnByValue': True}) 295 'returnByValue': True})
294 if 'error' in response: 296 if 'error' in response:
295 raise Exception(response['error']['message']) 297 raise Exception(response['error']['message'])
296 if 'wasThrown' in response['result'] and response['result']['wasThrown']: 298 if 'wasThrown' in response['result'] and response['result']['wasThrown']:
297 raise Exception(response['error']['result']['description']) 299 raise Exception(response['error']['result']['description'])
298 if response['result']['result']['type'] == 'undefined': 300 if response['result']['result']['type'] == 'undefined':
299 return None 301 return None
300 return response['result']['result']['value'] 302 return response['result']['result']['value']
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 json_data: (dict) Parsed from a JSON file using the json module. 482 json_data: (dict) Parsed from a JSON file using the json module.
481 483
482 Returns: 484 Returns:
483 a Track instance. 485 a Track instance.
484 """ 486 """
485 # There is no sensible way to deserialize this abstract class, but 487 # There is no sensible way to deserialize this abstract class, but
486 # subclasses are not required to define a deserialization method. For 488 # subclasses are not required to define a deserialization method. For
487 # example, for testing we have a FakeRequestTrack which is never 489 # example, for testing we have a FakeRequestTrack which is never
488 # deserialized; instead fake instances are deserialized as RequestTracks. 490 # deserialized; instead fake instances are deserialized as RequestTracks.
489 assert False 491 assert False
OLDNEW
« no previous file with comments | « tools/android/loading/device_setup.py ('k') | tools/chrome_proxy/common/chrome_proxy_measurements.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698