| Index: tools/telemetry/telemetry/core/platform/profiler/sample_profiler.py
|
| diff --git a/tools/telemetry/telemetry/core/platform/profiler/sample_profiler.py b/tools/telemetry/telemetry/core/platform/profiler/sample_profiler.py
|
| index 608b59d2b718db7cbfa2e62cfdfd603131eb2425..c8fd866f40ef9cfd8221095c2792a973969b5695 100644
|
| --- a/tools/telemetry/telemetry/core/platform/profiler/sample_profiler.py
|
| +++ b/tools/telemetry/telemetry/core/platform/profiler/sample_profiler.py
|
| @@ -11,29 +11,18 @@ from telemetry.core import util
|
| from telemetry.core.platform import profiler
|
|
|
|
|
| -class SampleProfiler(profiler.Profiler):
|
| -
|
| - def __init__(self, browser_backend, pid, output_path):
|
| - super(SampleProfiler, self).__init__(output_path)
|
| - self._browser_backend = browser_backend
|
| +class _SingleProcessSampleProfiler(object):
|
| + """An internal class for using iprofiler for a given process."""
|
| + def __init__(self, pid, output_path):
|
| + self._output_path = output_path
|
| self._tmp_output_file = tempfile.NamedTemporaryFile('w', 0)
|
| self._proc = subprocess.Popen(
|
| - ['sample', str(pid), '-mayDie', '-file', self.output_path],
|
| + ['sample', str(pid), '-mayDie', '-file', self._output_path],
|
| stdout=self._tmp_output_file, stderr=subprocess.STDOUT)
|
| def IsStarted():
|
| return 'Sampling process' in self._GetStdOut()
|
| util.WaitFor(IsStarted, 120)
|
|
|
| - @classmethod
|
| - def name(cls):
|
| - return 'sample'
|
| -
|
| - @classmethod
|
| - def is_supported(cls, options):
|
| - return (sys.platform == 'darwin'
|
| - and not options.browser_type.startswith('android')
|
| - and not options.browser_type.startswith('cros'))
|
| -
|
| def CollectProfile(self):
|
| self._proc.send_signal(signal.SIGINT)
|
| exit_code = self._proc.wait()
|
| @@ -47,7 +36,7 @@ class SampleProfiler(profiler.Profiler):
|
| self._tmp_output_file.close()
|
|
|
| print 'To view the profile, run:'
|
| - print ' open -a TextEdit %s' % self.output_path
|
| + print ' open -a TextEdit %s' % self._output_path
|
|
|
| def _GetStdOut(self):
|
| self._tmp_output_file.flush()
|
| @@ -56,3 +45,29 @@ class SampleProfiler(profiler.Profiler):
|
| return f.read()
|
| except IOError:
|
| return ''
|
| +
|
| +
|
| +class SampleProfiler(profiler.Profiler):
|
| +
|
| + def __init__(self, browser_backend, platform_backend, output_path):
|
| + super(SampleProfiler, 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(
|
| + _SingleProcessSampleProfiler(pid, output_file))
|
| +
|
| + @classmethod
|
| + def name(cls):
|
| + return 'sample'
|
| +
|
| + @classmethod
|
| + def is_supported(cls, options):
|
| + return (sys.platform == 'darwin'
|
| + and not options.browser_type.startswith('android')
|
| + and not options.browser_type.startswith('cros'))
|
| +
|
| + def CollectProfile(self):
|
| + for single_process in self._process_profilers:
|
| + single_process.CollectProfile()
|
|
|