Chromium Code Reviews| 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 ab4c918eb4831a746e1b9518b401a14bbdd62aa7..6e4365659aa90f16d689ab120e0d33cd9e2ec5ab 100644 |
| --- a/tools/telemetry/telemetry/core/platform/profiler/perf_profiler.py |
| +++ b/tools/telemetry/telemetry/core/platform/profiler/perf_profiler.py |
| @@ -3,6 +3,8 @@ |
| # found in the LICENSE file. |
| import logging |
| +import os |
| +import re |
| import signal |
| import subprocess |
| import sys |
| @@ -40,6 +42,7 @@ class _SingleProcessPerfProfiler(object): |
| self._tmp_output_file.close() |
| print 'To view the profile, run:' |
| print ' perf report -i %s' % self._output_file |
| + return self._output_file |
| def _GetStdOut(self): |
| self._tmp_output_file.flush() |
| @@ -79,5 +82,29 @@ class PerfProfiler(profiler.Profiler): |
| return False |
| def CollectProfile(self): |
| + output_files = [] |
| for single_process in self._process_profilers: |
| - single_process.CollectProfile() |
| + output_files.append(single_process.CollectProfile()) |
| + return output_files |
| + |
| + @classmethod |
| + def GetTopSamples(cls, file_name, number): |
|
nduca
2013/07/23 06:01:27
wdyt about unit test for this? not the full profil
nduca
2013/07/23 06:01:27
docstring would be good too about what is returned
tonyg
2013/07/23 18:41:21
Good idea. Done.
tonyg
2013/07/23 18:41:21
Done.
|
| + report = subprocess.Popen( |
| + ['perf', 'report', '--show-total-period', '-U', '-t', '^', '-i', |
| + file_name], |
| + stdout=subprocess.PIPE, stderr=open(os.devnull, 'w')).communicate()[0] |
| + period_by_function = {} |
| + for line in report.split('\n'): |
| + if not line or line.startswith('#'): |
| + continue |
| + fields = line.split('^') |
| + if len(fields) != 5: |
| + continue |
| + period = int(fields[1]) |
| + function = fields[4].partition(' ')[2] |
| + function = re.sub('<.*>', '', function) # Strip template params. |
| + function = re.sub('[(].*[)]', '', function) # Strip function params. |
| + period_by_function[function] = period |
| + if len(period_by_function) == number: |
| + break |
| + return period_by_function |