diff options
Diffstat (limited to 'simpleperf/runtest/runtest.py')
-rw-r--r-- | simpleperf/runtest/runtest.py | 107 |
1 files changed, 27 insertions, 80 deletions
diff --git a/simpleperf/runtest/runtest.py b/simpleperf/runtest/runtest.py index 77fc5669..a1b4520b 100644 --- a/simpleperf/runtest/runtest.py +++ b/simpleperf/runtest/runtest.py @@ -279,18 +279,20 @@ class Runner(object): def __init__(self, target, perf_path): self.target = target + self.is32 = target.endswith('32') self.perf_path = perf_path self.use_callgraph = False self.sampler = 'cpu-cycles' def record(self, test_executable_name, record_file, additional_options=[]): call_args = [self.perf_path, 'record'] - call_args += ['--duration', '1'] + call_args += ['--duration', '2'] call_args += ['-e', '%s:u' % self.sampler] if self.use_callgraph: call_args += ['-f', '1000', '-g'] call_args += ['-o', record_file] call_args += additional_options + test_executable_name += '32' if self.is32 else '64' call_args += [test_executable_name] self._call(call_args) @@ -310,8 +312,9 @@ class HostRunner(Runner): """Run perf test on host.""" - def __init__(self, perf_path): - super(HostRunner, self).__init__('host', perf_path) + def __init__(self, target): + perf_path = 'simpleperf32' if target.endswith('32') else 'simpleperf' + super(HostRunner, self).__init__(target, perf_path) def _call(self, args, output_file=None): output_fh = None @@ -326,17 +329,21 @@ class DeviceRunner(Runner): """Run perf test on device.""" - def __init__(self, perf_path): + def __init__(self, target): self.tmpdir = '/data/local/tmp/' - super(DeviceRunner, self).__init__('device', self.tmpdir + perf_path) + perf_path = 'simpleperf32' if target.endswith('32') else 'simpleperf' + super(DeviceRunner, self).__init__(target, self.tmpdir + perf_path) self._download(os.environ['OUT'] + '/system/xbin/' + perf_path, self.tmpdir) + lib = 'lib' if self.is32 else 'lib64' + self._download(os.environ['OUT'] + '/system/' + lib + '/libsimpleperf_inplace_sampler.so', + self.tmpdir) def _call(self, args, output_file=None): output_fh = None if output_file is not None: output_fh = open(output_file, 'w') args_with_adb = ['adb', 'shell'] - args_with_adb.extend(args) + args_with_adb.append('export LD_LIBRARY_PATH=' + self.tmpdir + ' && ' + ' '.join(args)) subprocess.check_call(args_with_adb, stdout=output_fh) if output_fh is not None: output_fh.close() @@ -346,8 +353,8 @@ class DeviceRunner(Runner): subprocess.check_call(args) def record(self, test_executable_name, record_file, additional_options=[]): - self._download(os.environ['OUT'] + '/system/bin/' + test_executable_name, - self.tmpdir) + self._download(os.environ['OUT'] + '/system/bin/' + test_executable_name + + ('32' if self.is32 else '64'), self.tmpdir) super(DeviceRunner, self).record(self.tmpdir + test_executable_name, self.tmpdir + record_file, additional_options) @@ -528,75 +535,14 @@ class ReportAnalyzer(object): return result -def runtest(host, device, normal, callgraph, use_inplace_sampler, selected_tests): - tests = load_config_file(os.path.dirname(os.path.realpath(__file__)) + \ - '/runtest.conf') - host_runner = HostRunner('simpleperf') - device_runner = DeviceRunner('simpleperf') - report_analyzer = ReportAnalyzer() - for test in tests: - if selected_tests is not None: - if test.test_name not in selected_tests: - continue - if host and normal: - host_runner.record(test.executable_name, 'perf.data') - host_runner.report('perf.data', 'perf.report', - additional_options = test.report_options) - result = report_analyzer.check_report_file( - test, 'perf.report', False) - print 'test %s on host %s' % ( - test.test_name, 'Succeeded' if result else 'Failed') - if not result: - exit(1) - - if device and normal: - device_runner.record(test.executable_name, 'perf.data') - device_runner.report('perf.data', 'perf.report', - additional_options = test.report_options) - result = report_analyzer.check_report_file(test, 'perf.report', False) - print 'test %s on device %s' % ( - test.test_name, 'Succeeded' if result else 'Failed') - if not result: - exit(1) - - if host and callgraph: - host_runner.record( - test.executable_name, - 'perf_g.data', - additional_options=['-g', '-f', '1000']) - host_runner.report( - 'perf_g.data', - 'perf_g.report', - additional_options=['-g', 'callee'] + test.report_options) - result = report_analyzer.check_report_file(test, 'perf_g.report', True) - print 'call-graph test %s on host %s' % ( - test.test_name, 'Succeeded' if result else 'Failed') - if not result: - exit(1) - - if device and callgraph: - # Decrease sampling frequency by -f 1000 to avoid losing records - # while recording call-graph. - device_runner.record( - test.executable_name, - 'perf_g.data', - additional_options=['-g', '-f', '1000']) - device_runner.report( - 'perf_g.data', - 'perf_g.report', - additional_options=['-g', 'callee'] + test.report_options) - result = report_analyzer.check_report_file(test, 'perf_g.report', True) - print 'call-graph test %s on device %s' % ( - test.test_name, 'Succeeded' if result else 'Failed') - if not result: - exit(1) - - def build_runner(target, use_callgraph, sampler): - if target == 'host': - runner = HostRunner('simpleperf') + if target == 'host32' and use_callgraph: + print "Current 64bit linux host doesn't support `simpleperf32 record -g`" + return None + if target.startswith('host'): + runner = HostRunner(target) else: - runner = DeviceRunner('simpleperf') + runner = DeviceRunner(target) runner.use_callgraph = use_callgraph runner.sampler = sampler return runner @@ -611,7 +557,7 @@ def test_with_runner(runner, tests): runner.report('perf.data', 'perf.report') symbols = report_analyzer._read_report_file('perf.report', runner.use_callgraph) result = False - if len(symbols) == 1 and symbols[0].name == 'fake_elf[+0]': + if len(symbols) == 1 and symbols[0].name.find('FakeFunction()') != -1: result = True else: runner.report('perf.data', 'perf.report', additional_options = test.report_options) @@ -639,20 +585,21 @@ def runtest(target_options, use_callgraph_options, sampler_options, selected_tes for use_callgraph in use_callgraph_options: for sampler in sampler_options: runner = build_runner(target, use_callgraph, sampler) - test_with_runner(runner, tests) + if runner is not None: + test_with_runner(runner, tests) def main(): - target_options = ['host', 'target'] + target_options = ['host64', 'host32', 'device64', 'device32'] use_callgraph_options = [False, True] sampler_options = ['cpu-cycles', 'inplace-sampler'] selected_tests = None i = 1 while i < len(sys.argv): if sys.argv[i] == '--host': - use_callgraph_options = ['host'] + target_options = ['host64', 'host32'] elif sys.argv[i] == '--device': - use_callgraph_options = ['device'] + target_options = ['device64', 'device32'] elif sys.argv[i] == '--normal': use_callgraph_options = [False] elif sys.argv[i] == '--callgraph': |