OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
Nirnimesh
2012/07/31 20:05:57
2012
| |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 import json | |
6 import os | |
7 | |
8 def escape_for_quoted_javascript_execution(js): | |
Nirnimesh
2012/07/31 20:05:57
CapitalizeAndRemoveSpaces
Prefix _ for private fu
| |
9 # Poor man's string escape. | |
10 return js.replace("'", "\\'"); | |
11 | |
12 | |
13 class TimelineModelProxy: | |
14 """A proxy for the TimelineModel class located in V8 in a chrome://tracing | |
Nirnimesh
2012/07/31 20:05:57
Make it fit within 1 line please.
| |
15 tab. | |
16 """ | |
17 def __init__(self, js_executor, shim_id): | |
18 self._js_executor = js_executor | |
19 self._shim_id = shim_id | |
20 | |
21 # Warning: The JSON serialization process removes cyclic references. | |
22 # TODO(eatnumber): regenerate these cyclic references on deserialization. | |
23 def _CallModelMethod(self, method_name, *args): | |
24 result = self._js_executor( | |
25 """ | |
Nirnimesh
2012/07/31 20:05:57
Can be moved to previous line
| |
26 window.timelineModelShims['%s'].invokeMethod('%s', '%s') | |
27 """ % ( | |
Nirnimesh
2012/07/31 20:05:57
indent 2 more chars to the right
| |
28 self._shim_id, | |
29 escape_for_quoted_javascript_execution(method_name), | |
30 escape_for_quoted_javascript_execution(json.dumps(args)) | |
31 ) | |
32 ) | |
33 if result["success"]: | |
Nirnimesh
2012/07/31 20:05:57
use ' for quoting
| |
34 return result["data"] | |
35 # TODO(eatnumber): Make these exceptions more reader friendly. | |
36 raise Exception(result) | |
Nirnimesh
2012/07/31 20:05:57
RuntimeError
| |
37 | |
38 def __del__(self): | |
39 self._js_executor( | |
40 """ | |
Nirnimesh
2012/07/31 20:05:57
Needs to be indented 4 chars wrt previous line
Russ Harmon
2012/07/31 20:54:18
It doesn't make sense to further indent this as th
Nirnimesh
2012/07/31 21:15:06
Chromium python style is based loosely on google p
| |
41 window.timelineModelShims['%s'] = undefined; | |
42 window.domAutomationController.send(''); | |
43 """ % self._shim_id | |
44 ) | |
45 | |
46 def GetAllThreads(self): | |
47 return self._CallModelMethod("getAllThreads") | |
48 | |
49 def GetAllCpus(self): | |
50 return self._CallModelMethod("getAllCpus") | |
51 | |
52 def GetAllProcesses(self): | |
53 return self._CallModelMethod("getAllProcesses") | |
54 | |
55 def GetAllCounters(self): | |
56 return self._CallModelMethod("getAllCounters") | |
57 | |
58 def FindAllThreadsNamed(self, name): | |
59 return self._CallModelMethod("findAllThreadsNamed", name); | |
60 | |
61 # Alias TimelineModel to TimelineModelProxy for convenience. | |
62 TimelineModel = TimelineModelProxy | |
OLD | NEW |