Commit 809b0b11 authored by Changwan Ryu's avatar Changwan Ryu Committed by Commit Bot

Add an argument to show file name and line in the output

Showing file name and line in the output can be useful in searching the
file name directly from your IDE.

Bug: 1015236
Change-Id: If6f3ad0d4e84af9942e0e7d3b3fdb53925a391a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1949106Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Commit-Queue: Changwan Ryu <changwan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721256}
parent 9211d6dd
...@@ -81,7 +81,8 @@ class StackAddressInterpreter(object): ...@@ -81,7 +81,8 @@ class StackAddressInterpreter(object):
lib_path: The path to the WebView library. lib_path: The path to the WebView library.
Returns: Returns:
A list of (address, function_name). A list of (address, function_info) where function_info is the function
name, plus file name and line if args.show_file_line is set.
""" """
stack_input_path = os.path.join(self.tmp_dir, 'stack_input.txt') stack_input_path = os.path.join(self.tmp_dir, 'stack_input.txt')
with open(stack_input_path, 'w') as f: with open(stack_input_path, 'w') as f:
...@@ -103,8 +104,11 @@ class StackAddressInterpreter(object): ...@@ -103,8 +104,11 @@ class StackAddressInterpreter(object):
for line in stack_output: for line in stack_output:
m = pattern.match(line) m = pattern.match(line)
if m: if m:
# We haven't yet seen a case where |file_name_line| could be useful. function_info = m.group('function')
address_function_pairs.append((m.group('address'), m.group('function'))) if self.args.show_file_line:
function_info += " | " + m.group('file_name_line')
address_function_pairs.append((m.group('address'), function_info))
return address_function_pairs return address_function_pairs
...@@ -159,7 +163,7 @@ class SimplePerfRunner(object): ...@@ -159,7 +163,7 @@ class SimplePerfRunner(object):
logging.info("Extracted %d addresses", len(addresses)) logging.info("Extracted %d addresses", len(addresses))
address_function_pairs = self.address_interpreter.Interpret( address_function_pairs = self.address_interpreter.Interpret(
addresses, lib_path) addresses, lib_path)
lines = SimplePerfRunner.ReplaceAddressesWithFunctionNames( lines = SimplePerfRunner.ReplaceAddressesWithFunctionInfos(
lines, address_function_pairs, lib_name) lines, address_function_pairs, lib_name)
with open(self.args.report_path, 'w') as f: with open(self.args.report_path, 'w') as f:
...@@ -218,7 +222,7 @@ class SimplePerfRunner(object): ...@@ -218,7 +222,7 @@ class SimplePerfRunner(object):
return addresses return addresses
@staticmethod @staticmethod
def ReplaceAddressesWithFunctionNames(lines, address_function_pairs, def ReplaceAddressesWithFunctionInfos(lines, address_function_pairs,
lib_name): lib_name):
"""Replaces the addresses with function names. """Replaces the addresses with function names.
...@@ -260,6 +264,8 @@ def main(raw_args): ...@@ -260,6 +264,8 @@ def main(raw_args):
' Try `app_profiler.py record -h` for more ' ' Try `app_profiler.py record -h` for more '
' information. Note that not setting this defaults' ' information. Note that not setting this defaults'
' to the default record options.')) ' to the default record options.'))
parser.add_argument('--show-file-line', action='store_true',
help='Show file name and lines in the result.')
script_common.AddDeviceArguments(parser) script_common.AddDeviceArguments(parser)
logging_common.AddLoggingArguments(parser) logging_common.AddLoggingArguments(parser)
......
...@@ -57,6 +57,16 @@ _EXAMPLE_INTERPRETER_OUTPUT = [ ...@@ -57,6 +57,16 @@ _EXAMPLE_INTERPRETER_OUTPUT = [
('viz::GLRenderer::SetUseProgram(viz::ProgramKey const&, ' ('viz::GLRenderer::SetUseProgram(viz::ProgramKey const&, '
'gfx::ColorSpace const&, gfx::ColorSpace const&)'))] 'gfx::ColorSpace const&, gfx::ColorSpace const&)'))]
_EXAMPLE_INTERPRETER_OUTPUT_WITH_FILE_NAME_LINE = [
('83a4db8',
('mojo::core::ports::(anonymous namespace)::UpdateTLS('
'mojo::core::ports::PortLocker*, mojo::core::ports::PortLocker*)'
' | ../../mojo/core/ports/port_locker.cc:26:3')),
('83db114',
('viz::GLRenderer::SetUseProgram(viz::ProgramKey const&, '
'gfx::ColorSpace const&, gfx::ColorSpace const&)'
' | ../../components/viz/service/display/gl_renderer.cc:3267:14'))]
_MOCK_ORIGINAL_REPORT = [ _MOCK_ORIGINAL_REPORT = [
'"442": {"l": 28, "f": "libwebviewchromium.so[+3db7d84]"},', '"442": {"l": 28, "f": "libwebviewchromium.so[+3db7d84]"},',
'"443": {"l": 28, "f": "libwebviewchromium.so[+3db7a5c]"},'] '"443": {"l": 28, "f": "libwebviewchromium.so[+3db7a5c]"},']
...@@ -88,7 +98,8 @@ class _RunSimpleperfTest(unittest.TestCase): ...@@ -88,7 +98,8 @@ class _RunSimpleperfTest(unittest.TestCase):
def setUp(self): def setUp(self):
self.tmp_dir = '/tmp' # the actual directory won't be used in this test. self.tmp_dir = '/tmp' # the actual directory won't be used in this test.
self.args = mock.Mock( self.args = mock.Mock(
report_path=os.path.join(self.tmp_dir, 'report.html')) report_path=os.path.join(self.tmp_dir, 'report.html'),
show_file_line=False)
self.device = mock.Mock() self.device = mock.Mock()
self.stack_address_interpreter = StackAddressInterpreter(self.args, self.stack_address_interpreter = StackAddressInterpreter(self.args,
...@@ -105,6 +116,16 @@ class _RunSimpleperfTest(unittest.TestCase): ...@@ -105,6 +116,16 @@ class _RunSimpleperfTest(unittest.TestCase):
_ADDRESSES, _WEBVIEW_LIB_PATH)) _ADDRESSES, _WEBVIEW_LIB_PATH))
self._AssertFileLines(mock_open, _EXAMPLE_STACK_SCRIPT_INPUT) self._AssertFileLines(mock_open, _EXAMPLE_STACK_SCRIPT_INPUT)
@mock.patch('run_simpleperf.open', new_callable=mock.mock_open)
def testStackAddressInterpreterWithFileNameLine(self, mock_open):
self.args.show_file_line = True
StackAddressInterpreter.RunStackScript = mock.Mock(
return_value=_EXAMPLE_STACK_SCRIPT_OUTPUT)
self.assertEquals(_EXAMPLE_INTERPRETER_OUTPUT_WITH_FILE_NAME_LINE,
self.stack_address_interpreter.Interpret(
_ADDRESSES, _WEBVIEW_LIB_PATH))
self._AssertFileLines(mock_open, _EXAMPLE_STACK_SCRIPT_INPUT)
def testSimplePerfRunner_CollectAddresses(self): def testSimplePerfRunner_CollectAddresses(self):
addresses = self.simple_perf_runner.CollectAddresses( addresses = self.simple_perf_runner.CollectAddresses(
_MOCK_ORIGINAL_REPORT, 'libwebviewchromium.so') _MOCK_ORIGINAL_REPORT, 'libwebviewchromium.so')
...@@ -112,7 +133,7 @@ class _RunSimpleperfTest(unittest.TestCase): ...@@ -112,7 +133,7 @@ class _RunSimpleperfTest(unittest.TestCase):
def testSimplePerfRunner_ReplaceAddresses(self): def testSimplePerfRunner_ReplaceAddresses(self):
postprocessed_report = ( postprocessed_report = (
self.simple_perf_runner.ReplaceAddressesWithFunctionNames( self.simple_perf_runner.ReplaceAddressesWithFunctionInfos(
_MOCK_ORIGINAL_REPORT, _MOCK_ADDRESS_FUNCTION_NAME_PAIRS, _MOCK_ORIGINAL_REPORT, _MOCK_ADDRESS_FUNCTION_NAME_PAIRS,
'libwebviewchromium.so')) 'libwebviewchromium.so'))
self.assertEquals(_MOCK_FINAL_REPORT, postprocessed_report) self.assertEquals(_MOCK_FINAL_REPORT, postprocessed_report)
......
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