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

Side by Side 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, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import convert_perf_script_to_tracing_json
7 import unittest
8
9 class TestConverScript(unittest.TestCase):
10 def test_extract_function_name_basic(self):
11 line = (' 1835025 WebCore::NodeEventContext::handleLocalEvents' +
12 '(WebCore::Event*) const (/chrome)')
13 self.assertEqual(
14 convert_perf_script_to_tracing_json.extract_function_name(line),
15 'WebCore::NodeEventContext::handleLocalEvents')
16
17 def test_extract_function_name_basic_extra_spaces(self):
18 line = (' 1835025 WebCore::NodeEventContext::handleLocalEvents(' +
19 'WebCore::Event*) const (/chrome) ')
20 self.assertEqual(
21 convert_perf_script_to_tracing_json.extract_function_name(line),
22 'WebCore::NodeEventContext::handleLocalEvents')
23
24 def test_extract_function_name_kallsyms(self):
25 line = ' ffffffff815de882 ([kernel.kallsyms])'
26 self.assertEqual(
27 convert_perf_script_to_tracing_json.extract_function_name(line),
28 'ffffffff815de882')
29
30 def test_extract_function_name_perf_map_file(self):
31 line = ' 3559d450634e (/tmp/perf-15260.map)'
32 self.assertEqual(
33 convert_perf_script_to_tracing_json.extract_function_name(line),
34 '3559d450634e')
35
36 def test_extract_function_name_non_virtual_thunk(self):
37 line = (' 32dd68d non-virtual thunk to ' +
38 'content::RenderWidgetCompositor::Animate(base::TimeTicks) (/chrome)')
39 self.assertEqual(
40 convert_perf_script_to_tracing_json.extract_function_name(line),
41 'content::RenderWidgetCompositor::Animate')
42
43 def test_extract_function_name_anonymous_namespace(self):
44 line = (' 32dd68d (anonymous namespace)::' +
45 'RenderWidgetCompositor::Animate(base::TimeTicks) (/chrome)')
46 self.assertEqual(
47 convert_perf_script_to_tracing_json.extract_function_name(line),
48 'RenderWidgetCompositor::Animate')
49
50 # FIXME: What's the right answer here?
51 def test_extract_function_name_complex_templates(self):
52 line = (' 12a4908 base::internal::InvokeHelper<true, void, ' +
53 'base::internal::RunnableAdapter<void (cc::ThreadProxy::*)(' +
54 'scoped_ptr<cc::ThreadProxy::BeginMainFrameAndCommitState, ' +
55 'base::DefaultDeleter<cc::ThreadProxy::BeginMainFrameAndCommitState>' +
56 ' >)>, void ()(base::WeakPtr<cc::ThreadProxy> const&, ' +
57 'scoped_ptr<cc::ThreadProxy::BeginMainFrameAndCommitState, ' +
58 'base::DefaultDeleter<cc::ThreadProxy::BeginMainFrameAndCommitState> ' +
59 '>)>::MakeItSo(base::internal::RunnableAdapter<void ' +
60 '(cc::ThreadProxy::*)(scoped_ptr<cc::ThreadProxy::' +
61 'BeginMainFrameAndCommitState, base::DefaultDeleter<cc::ThreadProxy::' +
62 'BeginMainFrameAndCommitState> >)>, base::WeakPtr<cc::ThreadProxy> ' +
63 'const&, scoped_ptr<cc::ThreadProxy::BeginMainFrameAndCommitState, ' +
64 'base::DefaultDeleter<cc::ThreadProxy::BeginMainFrameAndCommitState> >)' +
65 ' (/chrome)')
66 self.assertEqual(
67 convert_perf_script_to_tracing_json.extract_function_name(line),
68 ('base::internal::InvokeHelper<true, void, base::internal::' +
69 'RunnableAdapter<void (cc::ThreadProxy::*)(scoped_ptr<cc::ThreadProxy' +
70 '::BeginMainFrameAndCommitState, base::DefaultDeleter<cc::ThreadProxy' +
71 '::BeginMainFrameAndCommitState> >)>, void ()(base::WeakPtr<cc::' +
72 'ThreadProxy> const&, scoped_ptr<cc::ThreadProxy::' +
73 'BeginMainFrameAndCommitState, base::DefaultDeleter<cc::ThreadProxy' +
74 '::BeginMainFrameAndCommitState> >)>::MakeItSo(base::internal::' +
75 'RunnableAdapter<void (cc::ThreadProxy::*)'))
76
77 def test_collapse_perf_script_output(self):
78 lines = [
79 '# this is a comment',
80 'HTMLParserThrea 15260 cycles: ',
81 ' ffffffff8109e0fb ([kernel.kallsyms])',
82 ' ffffffff815de882 ([kernel.kallsyms])',
83 ' a5b836 content::ContentMain(a::b const&) (/chrome)',
84 ' 4279c9 ChromeMain (/chrome)',
85 ' 7fca67cce76d __libc_start_main (/libc-2.15.so)',
86 '',
87 ]
88 collapsed_lines = (
89 convert_perf_script_to_tracing_json.collapse_perf_script_output(lines))
90 stack = ('__libc_start_main;ChromeMain;content::ContentMain;' +
91 'ffffffff815de882;ffffffff8109e0fb')
92 self.assertEqual(collapsed_lines, {
93 '15260': {
94 stack: 1,
95 }
96 })
97
98 def test_compute_tree_basic(self):
99 stack = ('__libc_start_main;ChromeMain;content::ContentMain;' +
100 'ffffffff815de882;ffffffff8109e0fb')
101 collapsed_lines = {
102 '15260': {
103 stack: 1,
104 }
105 }
106 self.assertEqual(
107 convert_perf_script_to_tracing_json.compute_tree(collapsed_lines), (
108 {
109 '__libc_start_main;15260': {
110 'start_time': 0, 'children': {
111 'ChromeMain;15260': {
112 'start_time': 0, 'children': {
113 'content::ContentMain;15260': {
114 'start_time': 0, 'children': {
115 'ffffffff815de882;15260': {
116 'start_time': 0, 'children': {
117 'ffffffff8109e0fb;15260': {
118 'start_time': 0,
119 'children': {},
120 'end_time': 1
121 }
122 },
123 'end_time': 1
124 }
125 },
126 'end_time': 1
127 }
128 },
129 'end_time': 1
130 }
131 },
132 'end_time': 1
133 }
134 },
135 1,
136 {'15260': 1}
137 ))
138
139 def test_compute_tree_same_stack_different_threads(self):
140 stack = ('__libc_start_main;ChromeMain;content::ContentMain;' +
141 'ffffffff815de882;ffffffff8109e0fb')
142 collapsed_lines = {
143 '15260': {
144 stack: 1,
145 },
146 '1234': {
147 stack: 1,
148 },
149 }
150 self.assertEqual(
151 convert_perf_script_to_tracing_json.compute_tree(collapsed_lines), (
152 {
153 '__libc_start_main;15260': {
154 'start_time': 0, 'children': {
155 'ChromeMain;15260': {
156 'start_time': 0, 'children': {
157 'content::ContentMain;15260': {
158 'start_time': 0, 'children': {
159 'ffffffff815de882;15260': {
160 'start_time': 0, 'children': {
161 'ffffffff8109e0fb;15260': {
162 'start_time': 0, 'children': {}, 'end_time': 1
163 }
164 },
165 'end_time': 1
166 }
167 },
168 'end_time': 1
169 }
170 },
171 'end_time': 1
172 }
173 },
174 'end_time': 1
175 },
176 '__libc_start_main;1234': {
177 'start_time': 0, 'children': {
178 'ChromeMain;1234': {
179 'start_time': 0, 'children': {
180 'content::ContentMain;1234': {
181 'start_time': 0, 'children': {
182 'ffffffff815de882;1234': {
183 'start_time': 0, 'children': {
184 'ffffffff8109e0fb;1234': {
185 'start_time': 0, 'children': {}, 'end_time': 1
186 }
187 },
188 'end_time': 1
189 }
190 },
191 'end_time': 1
192 }
193 },
194 'end_time': 1
195 }
196 },
197 'end_time': 1
198 },
199 },
200 2,
201 {'15260': 1, '1234': 1}
202 ))
203
204 def test_stringified_json_output(self):
205 lines = [
206 '# this is a comment',
207 'HTMLParserThrea 15260 cycles: ',
208 ' ffffffff8109e0fb ([kernel.kallsyms])',
209 ' ffffffff815de882 ([kernel.kallsyms])',
210 ' a5b836 c::ContentMain(a::b const&) (/chrome)',
211 ' 4279c9 ChromeMain (/chrome)',
212 ' 7fca67cce76d __libc_start_main (/libc-2.15.so)',
213 '',
214 ]
215 self.assertEqual(
216 convert_perf_script_to_tracing_json.stringified_json_output(lines),
217 '[' +
218 '{"tid":"15260","ph":"B","pid":1,"name":"__libc_start_main","ts":0},' +
219 '{"tid":"15260","ph":"B","pid":1,"name":"ChromeMain","ts":0},' +
220 '{"tid":"15260","ph":"B","pid":1,"name":"c::ContentMain","ts":0},' +
221 '{"tid":"15260","ph":"B","pid":1,"name":"ffffffff815de882","ts":0},' +
222 '{"name":"ffffffff8109e0fb","args":{' +
223 '"process percent":"100.00%","thread percent":"100.00%"},' +
224 '"pid":1,"ts":0,"tid":"15260","dur":1,"ph":"X"},' +
225 '{"name":"ffffffff815de882","args":{' +
226 '"process percent":"100.00%","thread percent":"100.00%"},' +
227 '"pid":1,"ts":1,"tid":"15260","ph":"E"},' +
228 '{"name":"c::ContentMain","args":{' +
229 '"process percent":"100.00%","thread percent":"100.00%"},' +
230 '"pid":1,"ts":1,"tid":"15260","ph":"E"},' +
231 '{"name":"ChromeMain","args":{' +
232 '"process percent":"100.00%","thread percent":"100.00%"},' +
233 '"pid":1,"ts":1,"tid":"15260","ph":"E"},' +
234 '{"name":"__libc_start_main","args":{' +
235 '"process percent":"100.00%","thread percent":"100.00%"},' +
236 '"pid":1,"ts":1,"tid":"15260","ph":"E"}' +
237 ']')
238
239 if __name__ == '__main__':
240 unittest.main()
OLDNEW
« 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