Commit 361d69df authored by Mikhail Khokhlov's avatar Mikhail Khokhlov Committed by Commit Bot

[tools/perf] Guess trace processor path when running on bots

Build directories on bots follow more or less unified naming scheme,
so it's possible to guess the path to the trace processor.

Bug: 1028612
Change-Id: I6065fc2bac2ca23dcdf9363b4defb43b7cb8d22d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1936314
Commit-Queue: Mikhail Khokhlov <khokhlov@google.com>
Reviewed-by: default avatarJuan Antonio Navarro Pérez <perezju@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719560}
parent b00e3fc0
...@@ -16,6 +16,7 @@ import sys ...@@ -16,6 +16,7 @@ import sys
from py_utils import cloud_storage from py_utils import cloud_storage
from core import path_util
from core.results_processor import formatters from core.results_processor import formatters
from core.results_processor import util from core.results_processor import util
from core.results_processor import trace_processor from core.results_processor import trace_processor
...@@ -70,10 +71,10 @@ def ArgumentParser(standalone=False): ...@@ -70,10 +71,10 @@ def ArgumentParser(standalone=False):
'How to interpret the testPath attribute.', 'How to interpret the testPath attribute.',
'Available options: %(choices)s. Default: %(default)s.')) 'Available options: %(choices)s. Default: %(default)s.'))
group.add_argument( group.add_argument(
'--trace-processor-path', default=trace_processor.DEFAULT_TP_PATH, '--trace-processor-path',
help=Sentences( help=Sentences(
'Path to trace processor shell.', 'Path to trace processor shell.',
'Default: %(default)s.')) 'Default: try to guess based on common build directory names.'))
group.add_argument( group.add_argument(
'--upload-results', action='store_true', '--upload-results', action='store_true',
help='Upload generated artifacts to cloud storage.') help='Upload generated artifacts to cloud storage.')
...@@ -144,6 +145,9 @@ def ProcessOptions(options): ...@@ -144,6 +145,9 @@ def ProcessOptions(options):
if 'none' in options.output_formats: if 'none' in options.output_formats:
options.output_formats.remove('none') options.output_formats.remove('none')
if not options.trace_processor_path:
options.trace_processor_path = _GuessTraceProcessorPath()
def _CreateTopLevelParser(standalone): def _CreateTopLevelParser(standalone):
"""Create top level parser, and group for result options.""" """Create top level parser, and group for result options."""
...@@ -171,5 +175,28 @@ def _DefaultOutputDir(): ...@@ -171,5 +175,28 @@ def _DefaultOutputDir():
return os.getcwd() return os.getcwd()
def _GuessTraceProcessorPath():
"""Return path to trace processor binary.
When we run on bots, there's only one build directory, so we just return
the path to trace processor binary located in that directory. Otherwise
we don't guess, but leave it to the user to supply a path.
"""
build_dirs = ['build', 'out', 'xcodebuild']
build_types = ['Debug', 'Debug_x64', 'Release', 'Release_x64', 'Default']
candidate_paths = []
for build_dir in build_dirs:
for build_type in build_types:
candidate_path = os.path.join(
path_util.GetChromiumSrcDir(), build_dir, build_type,
trace_processor.TP_BINARY_NAME)
if os.path.isfile(candidate_path):
candidate_paths.append(candidate_path)
if len(candidate_paths) == 1:
return candidate_paths[0]
else:
return None
def Sentences(*args): def Sentences(*args):
return ' '.join(s for s in args if s) return ' '.join(s for s in args if s)
...@@ -46,6 +46,8 @@ class ProcessOptionsTestCase(unittest.TestCase): ...@@ -46,6 +46,8 @@ class ProcessOptionsTestCase(unittest.TestCase):
mock.patch(module('_DefaultOutputDir'), mock.patch(module('_DefaultOutputDir'),
return_value='/path/to/output_dir').start() return_value='/path/to/output_dir').start()
mock.patch(module('path_util.GetChromiumSrcDir'),
return_value='/path/to/chromium').start()
def tearDown(self): def tearDown(self):
mock.patch.stopall() mock.patch.stopall()
...@@ -135,6 +137,32 @@ class TestProcessOptions(ProcessOptionsTestCase): ...@@ -135,6 +137,32 @@ class TestProcessOptions(ProcessOptionsTestCase):
'--output-format', 'html', '--output-format', 'csv']) '--output-format', 'html', '--output-format', 'csv'])
self.assertEqual(options.output_formats, ['csv', 'html']) self.assertEqual(options.output_formats, ['csv', 'html'])
def testTraceProcessorPath_noBuildDir(self):
options = self.ParseArgs([])
self.assertIsNone(options.trace_processor_path)
def testTraceProcessorPath_oneBuildDir(self):
def isfile(path):
return path == '/path/to/chromium/out/Release/trace_processor_shell'
with mock.patch(module('os.path.isfile')) as isfile_patch:
isfile_patch.side_effect = isfile
options = self.ParseArgs([])
self.assertEqual(options.trace_processor_path,
'/path/to/chromium/out/Release/trace_processor_shell')
def testTraceProcessorPath_twoBuildDirs(self):
def isfile(path):
return path in ['/path/to/chromium/out/Release/trace_processor_shell',
'/path/to/chromium/out/Debug/trace_processor_shell']
with mock.patch(module('os.path.isfile')) as isfile_patch:
isfile_patch.side_effect = isfile
options = self.ParseArgs([])
self.assertIsNone(options.trace_processor_path)
class StandaloneTestProcessOptions(ProcessOptionsTestCase): class StandaloneTestProcessOptions(ProcessOptionsTestCase):
def setUp(self): def setUp(self):
......
...@@ -8,12 +8,10 @@ import os ...@@ -8,12 +8,10 @@ import os
import shutil import shutil
import subprocess import subprocess
from core import path_util
from py_utils import tempfile_ext from py_utils import tempfile_ext
DEFAULT_TP_PATH = os.path.join( TP_BINARY_NAME = 'trace_processor_shell'
path_util.GetChromiumSrcDir(), 'out', 'Debug', 'trace_processor_shell')
EXPORT_JSON_QUERY_TEMPLATE = 'select export_json(%s)\n' EXPORT_JSON_QUERY_TEMPLATE = 'select export_json(%s)\n'
...@@ -23,6 +21,9 @@ def _SqlString(s): ...@@ -23,6 +21,9 @@ def _SqlString(s):
def ConvertProtoTracesToJson(trace_processor_path, proto_files, json_path): def ConvertProtoTracesToJson(trace_processor_path, proto_files, json_path):
if trace_processor_path is None:
raise RuntimeError('Trace processor executable is not supplied. '
'Please use the --trace-processor-path flag.')
if not os.path.isfile(trace_processor_path): if not os.path.isfile(trace_processor_path):
raise RuntimeError("Can't find trace processor executable at %s" % raise RuntimeError("Can't find trace processor executable at %s" %
trace_processor_path) trace_processor_path)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment