Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Unified Diff: tools/convert_perf_script_to_tracing_json_test.py

Issue 226933002: Convert 'perf script' output to about:tracing json. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/convert_perf_script_to_tracing_json_test.py
diff --git a/tools/convert_perf_script_to_tracing_json_test.py b/tools/convert_perf_script_to_tracing_json_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..5325f8d8b8f6c7050be2f0676b007223412d749b
--- /dev/null
+++ b/tools/convert_perf_script_to_tracing_json_test.py
@@ -0,0 +1,240 @@
+#!/usr/bin/python
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import convert_perf_script_to_tracing_json
+import unittest
+
+class TestConverScript(unittest.TestCase):
+ def test_extract_function_name_basic(self):
+ line = (' 1835025 WebCore::NodeEventContext::handleLocalEvents' +
+ '(WebCore::Event*) const (/chrome)')
+ self.assertEqual(
+ convert_perf_script_to_tracing_json.extract_function_name(line),
+ 'WebCore::NodeEventContext::handleLocalEvents')
+
+ def test_extract_function_name_basic_extra_spaces(self):
+ line = (' 1835025 WebCore::NodeEventContext::handleLocalEvents(' +
+ 'WebCore::Event*) const (/chrome) ')
+ self.assertEqual(
+ convert_perf_script_to_tracing_json.extract_function_name(line),
+ 'WebCore::NodeEventContext::handleLocalEvents')
+
+ def test_extract_function_name_kallsyms(self):
+ line = ' ffffffff815de882 ([kernel.kallsyms])'
+ self.assertEqual(
+ convert_perf_script_to_tracing_json.extract_function_name(line),
+ 'ffffffff815de882')
+
+ def test_extract_function_name_perf_map_file(self):
+ line = ' 3559d450634e (/tmp/perf-15260.map)'
+ self.assertEqual(
+ convert_perf_script_to_tracing_json.extract_function_name(line),
+ '3559d450634e')
+
+ def test_extract_function_name_non_virtual_thunk(self):
+ line = (' 32dd68d non-virtual thunk to ' +
+ 'content::RenderWidgetCompositor::Animate(base::TimeTicks) (/chrome)')
+ self.assertEqual(
+ convert_perf_script_to_tracing_json.extract_function_name(line),
+ 'content::RenderWidgetCompositor::Animate')
+
+ def test_extract_function_name_anonymous_namespace(self):
+ line = (' 32dd68d (anonymous namespace)::' +
+ 'RenderWidgetCompositor::Animate(base::TimeTicks) (/chrome)')
+ self.assertEqual(
+ convert_perf_script_to_tracing_json.extract_function_name(line),
+ 'RenderWidgetCompositor::Animate')
+
+ # FIXME: What's the right answer here?
+ def test_extract_function_name_complex_templates(self):
+ line = (' 12a4908 base::internal::InvokeHelper<true, void, ' +
+ 'base::internal::RunnableAdapter<void (cc::ThreadProxy::*)(' +
+ 'scoped_ptr<cc::ThreadProxy::BeginMainFrameAndCommitState, ' +
+ 'base::DefaultDeleter<cc::ThreadProxy::BeginMainFrameAndCommitState>' +
+ ' >)>, void ()(base::WeakPtr<cc::ThreadProxy> const&, ' +
+ 'scoped_ptr<cc::ThreadProxy::BeginMainFrameAndCommitState, ' +
+ 'base::DefaultDeleter<cc::ThreadProxy::BeginMainFrameAndCommitState> ' +
+ '>)>::MakeItSo(base::internal::RunnableAdapter<void ' +
+ '(cc::ThreadProxy::*)(scoped_ptr<cc::ThreadProxy::' +
+ 'BeginMainFrameAndCommitState, base::DefaultDeleter<cc::ThreadProxy::' +
+ 'BeginMainFrameAndCommitState> >)>, base::WeakPtr<cc::ThreadProxy> ' +
+ 'const&, scoped_ptr<cc::ThreadProxy::BeginMainFrameAndCommitState, ' +
+ 'base::DefaultDeleter<cc::ThreadProxy::BeginMainFrameAndCommitState> >)' +
+ ' (/chrome)')
+ self.assertEqual(
+ convert_perf_script_to_tracing_json.extract_function_name(line),
+ ('base::internal::InvokeHelper<true, void, base::internal::' +
+ 'RunnableAdapter<void (cc::ThreadProxy::*)(scoped_ptr<cc::ThreadProxy' +
+ '::BeginMainFrameAndCommitState, base::DefaultDeleter<cc::ThreadProxy' +
+ '::BeginMainFrameAndCommitState> >)>, void ()(base::WeakPtr<cc::' +
+ 'ThreadProxy> const&, scoped_ptr<cc::ThreadProxy::' +
+ 'BeginMainFrameAndCommitState, base::DefaultDeleter<cc::ThreadProxy' +
+ '::BeginMainFrameAndCommitState> >)>::MakeItSo(base::internal::' +
+ 'RunnableAdapter<void (cc::ThreadProxy::*)'))
+
+ def test_collapse_perf_script_output(self):
+ lines = [
+ '# this is a comment',
+ 'HTMLParserThrea 15260 cycles: ',
+ ' ffffffff8109e0fb ([kernel.kallsyms])',
+ ' ffffffff815de882 ([kernel.kallsyms])',
+ ' a5b836 content::ContentMain(a::b const&) (/chrome)',
+ ' 4279c9 ChromeMain (/chrome)',
+ ' 7fca67cce76d __libc_start_main (/libc-2.15.so)',
+ '',
+ ]
+ collapsed_lines = (
+ convert_perf_script_to_tracing_json.collapse_perf_script_output(lines))
+ stack = ('__libc_start_main;ChromeMain;content::ContentMain;' +
+ 'ffffffff815de882;ffffffff8109e0fb')
+ self.assertEqual(collapsed_lines, {
+ '15260': {
+ stack: 1,
+ }
+ })
+
+ def test_compute_tree_basic(self):
+ stack = ('__libc_start_main;ChromeMain;content::ContentMain;' +
+ 'ffffffff815de882;ffffffff8109e0fb')
+ collapsed_lines = {
+ '15260': {
+ stack: 1,
+ }
+ }
+ self.assertEqual(
+ convert_perf_script_to_tracing_json.compute_tree(collapsed_lines), (
+ {
+ '__libc_start_main;15260': {
+ 'start_time': 0, 'children': {
+ 'ChromeMain;15260': {
+ 'start_time': 0, 'children': {
+ 'content::ContentMain;15260': {
+ 'start_time': 0, 'children': {
+ 'ffffffff815de882;15260': {
+ 'start_time': 0, 'children': {
+ 'ffffffff8109e0fb;15260': {
+ 'start_time': 0,
+ 'children': {},
+ 'end_time': 1
+ }
+ },
+ 'end_time': 1
+ }
+ },
+ 'end_time': 1
+ }
+ },
+ 'end_time': 1
+ }
+ },
+ 'end_time': 1
+ }
+ },
+ 1,
+ {'15260': 1}
+ ))
+
+ def test_compute_tree_same_stack_different_threads(self):
+ stack = ('__libc_start_main;ChromeMain;content::ContentMain;' +
+ 'ffffffff815de882;ffffffff8109e0fb')
+ collapsed_lines = {
+ '15260': {
+ stack: 1,
+ },
+ '1234': {
+ stack: 1,
+ },
+ }
+ self.assertEqual(
+ convert_perf_script_to_tracing_json.compute_tree(collapsed_lines), (
+ {
+ '__libc_start_main;15260': {
+ 'start_time': 0, 'children': {
+ 'ChromeMain;15260': {
+ 'start_time': 0, 'children': {
+ 'content::ContentMain;15260': {
+ 'start_time': 0, 'children': {
+ 'ffffffff815de882;15260': {
+ 'start_time': 0, 'children': {
+ 'ffffffff8109e0fb;15260': {
+ 'start_time': 0, 'children': {}, 'end_time': 1
+ }
+ },
+ 'end_time': 1
+ }
+ },
+ 'end_time': 1
+ }
+ },
+ 'end_time': 1
+ }
+ },
+ 'end_time': 1
+ },
+ '__libc_start_main;1234': {
+ 'start_time': 0, 'children': {
+ 'ChromeMain;1234': {
+ 'start_time': 0, 'children': {
+ 'content::ContentMain;1234': {
+ 'start_time': 0, 'children': {
+ 'ffffffff815de882;1234': {
+ 'start_time': 0, 'children': {
+ 'ffffffff8109e0fb;1234': {
+ 'start_time': 0, 'children': {}, 'end_time': 1
+ }
+ },
+ 'end_time': 1
+ }
+ },
+ 'end_time': 1
+ }
+ },
+ 'end_time': 1
+ }
+ },
+ 'end_time': 1
+ },
+ },
+ 2,
+ {'15260': 1, '1234': 1}
+ ))
+
+ def test_stringified_json_output(self):
+ lines = [
+ '# this is a comment',
+ 'HTMLParserThrea 15260 cycles: ',
+ ' ffffffff8109e0fb ([kernel.kallsyms])',
+ ' ffffffff815de882 ([kernel.kallsyms])',
+ ' a5b836 c::ContentMain(a::b const&) (/chrome)',
+ ' 4279c9 ChromeMain (/chrome)',
+ ' 7fca67cce76d __libc_start_main (/libc-2.15.so)',
+ '',
+ ]
+ self.assertEqual(
+ convert_perf_script_to_tracing_json.stringified_json_output(lines),
+ '[' +
+ '{"tid":"15260","ph":"B","pid":1,"name":"__libc_start_main","ts":0},' +
+ '{"tid":"15260","ph":"B","pid":1,"name":"ChromeMain","ts":0},' +
+ '{"tid":"15260","ph":"B","pid":1,"name":"c::ContentMain","ts":0},' +
+ '{"tid":"15260","ph":"B","pid":1,"name":"ffffffff815de882","ts":0},' +
+ '{"name":"ffffffff8109e0fb","args":{' +
+ '"process percent":"100.00%","thread percent":"100.00%"},' +
+ '"pid":1,"ts":0,"tid":"15260","dur":1,"ph":"X"},' +
+ '{"name":"ffffffff815de882","args":{' +
+ '"process percent":"100.00%","thread percent":"100.00%"},' +
+ '"pid":1,"ts":1,"tid":"15260","ph":"E"},' +
+ '{"name":"c::ContentMain","args":{' +
+ '"process percent":"100.00%","thread percent":"100.00%"},' +
+ '"pid":1,"ts":1,"tid":"15260","ph":"E"},' +
+ '{"name":"ChromeMain","args":{' +
+ '"process percent":"100.00%","thread percent":"100.00%"},' +
+ '"pid":1,"ts":1,"tid":"15260","ph":"E"},' +
+ '{"name":"__libc_start_main","args":{' +
+ '"process percent":"100.00%","thread percent":"100.00%"},' +
+ '"pid":1,"ts":1,"tid":"15260","ph":"E"}' +
+ ']')
+
+if __name__ == '__main__':
+ unittest.main()
« tools/convert_perf_script_to_tracing_json.py ('K') | « tools/convert_perf_script_to_tracing_json.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698