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

Unified Diff: tools/telemetry/telemetry/core/platform/profiling_controller_backend.py

Issue 511653002: Add profiling_controller that manages profilers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/profilers_controller/profiling_controller Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/core/platform/profiling_controller_backend.py
diff --git a/tools/telemetry/telemetry/core/platform/profiling_controller_backend.py b/tools/telemetry/telemetry/core/platform/profiling_controller_backend.py
new file mode 100644
index 0000000000000000000000000000000000000000..64d66464bd234eaf084587460953f23ca8640586
--- /dev/null
+++ b/tools/telemetry/telemetry/core/platform/profiling_controller_backend.py
@@ -0,0 +1,57 @@
+# Copyright 2014 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.
+from telemetry.core.platform.profiler import profiler_finder
+
+
+class ProfilingControllerBackend(object):
+ def __init__(self, platform_backend):
+ self._platform_backend = platform_backend
+ self._active_profilers = []
+ self._profilers_states = {}
+
+ def StartProfiling(self, profiler_name, base_output_file):
+ """Starts profiling using |profiler_name|. Results are saved to
+ |base_output_file|.<process_name>."""
+ assert not self._active_profilers, 'Already profiling. Must stop first.'
+
+ browser_backend = None
+ # Note that many profilers doesn't rely on browser_backends, so the number
+ # of running_browser_backends may not matter for them.
+ if len(self._platform_backend.running_browser_backends) == 1:
+ browser_backend = self._platform_backend.running_browser_backends[0]
+ else:
+ raise NotImplementedError()
+
+ profiler_class = profiler_finder.FindProfiler(profiler_name)
+
+ if not profiler_class.is_supported(browser_backend.browser_type):
+ raise Exception('The %s profiler is not '
+ 'supported on this platform.' % profiler_name)
+
+ if not profiler_class in self._profilers_states:
+ self._profilers_states[profiler_class] = {}
+
+ self._active_profilers.append(
+ profiler_class(browser_backend, self._platform_backend,
+ base_output_file, self._profilers_states[profiler_class]))
+
+ def StopProfiling(self):
+ """Stops all active profilers and saves their results.
+
+ Returns:
+ A list of filenames produced by the profiler.
+ """
+ output_files = []
+ for profiler in self._active_profilers:
+ output_files.extend(profiler.CollectProfile())
+ self._active_profilers = []
+ return output_files
+
+ def is_profiler_active(self, profiler_name):
+ return profiler_name in [profiler.name() for
+ profiler in self._active_profilers]
+
+ def WillCloseBrowser(self, browser_backend):
+ for profiler_class in self._profilers_states:
+ profiler_class.WillCloseBrowser(browser_backend, self._platform_backend)

Powered by Google App Engine
This is Rietveld 408576698