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

Unified Diff: tools/telemetry/telemetry/core/platform/profiler/perf_profiler.py

Issue 14978006: Telemetry: makes profilers a bit more generic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: dict / member name Created 7 years, 7 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/profiler/perf_profiler.py
diff --git a/tools/telemetry/telemetry/core/platform/profiler/perf_profiler.py b/tools/telemetry/telemetry/core/platform/profiler/perf_profiler.py
index eb737440ff015776059472581235a58f18502f8e..18074f28e34a661f229360ea8d6c73b9eb1291d3 100644
--- a/tools/telemetry/telemetry/core/platform/profiler/perf_profiler.py
+++ b/tools/telemetry/telemetry/core/platform/profiler/perf_profiler.py
@@ -10,34 +10,16 @@ import tempfile
from telemetry.core.platform import profiler
-class PerfProfiler(profiler.Profiler):
-
- def __init__(self, browser_backend, pid, output_path):
- super(PerfProfiler, self).__init__(output_path)
- self._browser_backend = browser_backend
+class _SingleProcessPerfProfiler(object):
+ """An internal class for using perf for a given process."""
+ def __init__(self, pid, output_file):
+ self._output_file = output_file
self._tmp_output_file = tempfile.NamedTemporaryFile('w', 0)
self._proc = subprocess.Popen(
['perf', 'record', '--call-graph',
- '--pid', str(pid), '--output', self.output_path],
+ '--pid', str(pid), '--output', output_file],
stdout=self._tmp_output_file, stderr=subprocess.STDOUT)
- @classmethod
- def name(cls):
- return 'perf'
-
- @classmethod
- def is_supported(cls, options):
- if (sys.platform != 'linux2'
- or options.browser_type.startswith('android')
- or options.browser_type.startswith('cros')):
- return False
- try:
- return not subprocess.Popen(['perf', '--version'],
- stderr=subprocess.STDOUT,
- stdout=subprocess.PIPE).wait()
- except OSError:
- return False
-
def CollectProfile(self):
self._proc.send_signal(signal.SIGINT)
exit_code = self._proc.wait()
@@ -47,11 +29,9 @@ class PerfProfiler(profiler.Profiler):
'perf failed with exit code %d. Output:\n%s' % (exit_code,
self._GetStdOut()))
finally:
- self._proc = None
self._tmp_output_file.close()
-
print 'To view the profile, run:'
- print ' perf report -i %s' % self.output_path
+ print ' perf report -i %s' % self._output_file
def _GetStdOut(self):
self._tmp_output_file.flush()
@@ -60,3 +40,36 @@ class PerfProfiler(profiler.Profiler):
return f.read()
except IOError:
return ''
+
+
+class PerfProfiler(profiler.Profiler):
+
+ def __init__(self, browser_backend, platform_backend, output_path):
+ super(PerfProfiler, self).__init__(
+ browser_backend, platform_backend, output_path)
+ process_output_file_map = self._GetProcessOutputFileMap()
+ self._process_profilers = []
+ for pid, output_file in process_output_file_map.iteritems():
+ self._process_profilers.append(
+ _SingleProcessPerfProfiler(pid, output_file))
+
+ @classmethod
+ def name(cls):
+ return 'perf'
+
+ @classmethod
+ def is_supported(cls, options):
+ if (sys.platform != 'linux2'
+ or options.browser_type.startswith('android')
+ or options.browser_type.startswith('cros')):
+ return False
+ try:
+ return not subprocess.Popen(['perf', '--version'],
+ stderr=subprocess.STDOUT,
+ stdout=subprocess.PIPE).wait()
+ except OSError:
+ return False
+
+ def CollectProfile(self):
+ for single_process in self._process_profilers:
+ single_process.CollectProfile()

Powered by Google App Engine
This is Rietveld 408576698