Index: chrome/test/functional/tracing/timeline_model.py |
diff --git a/chrome/test/functional/tracing/timeline_model.py b/chrome/test/functional/tracing/timeline_model.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9fb069600b46300368ef495ffd51848ace07a3fa |
--- /dev/null |
+++ b/chrome/test/functional/tracing/timeline_model.py |
@@ -0,0 +1,58 @@ |
+# Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import json |
+import os |
+ |
+def escape_for_quoted_javascript_execution(js): |
+ # Poor man's string escape. |
+ return js.replace("'", "\\'"); |
+ |
+class TimelineModelProxy: |
+ def __init__(self, js_executor, shim_id): |
+ self._js_executor = js_executor |
+ self._shim_id = shim_id |
+ |
+ # Warning: The JSON serialization process removes cyclic references. |
+ # TODO(eatnumber) regenerate these cyclic references on deserialization. |
+ def _callModelMethod(self, method_name, *args): |
+ result = self._js_executor( |
+ """ |
+ window.timelineModelShims['%s'].invokeMethod('%s', '%s') |
+ """ % ( |
+ self._shim_id, |
+ escape_for_quoted_javascript_execution(method_name), |
+ escape_for_quoted_javascript_execution(json.dumps(args)) |
+ ) |
+ ) |
+ if result["success"]: |
+ return result["data"] |
+ # TODO(eatnumber) Make these exceptions more reader friendly. |
+ raise Exception(result) |
+ |
+ def __del__(self): |
+ self._js_executor( |
+ """ |
+ window.timelineModelShims['%s'] = undefined; |
+ window.domAutomationController.send(''); |
+ """ % self._shim_id |
+ ) |
+ |
+ def getAllThreads(self): |
+ return self._callModelMethod("getAllThreads") |
+ |
+ def getAllCpus(self): |
+ return self._callModelMethod("getAllCpus") |
+ |
+ def getAllProcesses(self): |
+ return self._callModelMethod("getAllProcesses") |
+ |
+ def getAllCounters(self): |
+ return self._callModelMethod("getAllCounters") |
+ |
+ def findAllThreadsNamed(self, name): |
+ return self._callModelMethod("findAllThreadsNamed", name); |
+ |
+# Alias TimelineModel to TimelineModelProxy for convenience. |
+TimelineModel = TimelineModelProxy |