OLD | NEW |
1 # Copyright 2016 the V8 project authors. All rights reserved. | 1 # Copyright 2016 the V8 project authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import linux_perf_report as ipr | 5 import linux_perf_report as ipr |
6 import StringIO | 6 import StringIO |
7 import unittest | 7 import unittest |
8 | 8 |
9 | 9 |
10 PERF_SCRIPT_OUTPUT = """ | 10 PERF_SCRIPT_OUTPUT = """ |
(...skipping 22 matching lines...) Expand all Loading... |
33 01234567 hello | 33 01234567 hello |
34 abcdef76 v8::internal::Compiler | 34 abcdef76 v8::internal::Compiler |
35 00000000 Stub:CEntryStub | 35 00000000 Stub:CEntryStub |
36 76543210 world | 36 76543210 world |
37 11111111 BytecodeHandler:nope | 37 11111111 BytecodeHandler:nope |
38 | 38 |
39 00000000 Lost | 39 00000000 Lost |
40 11111111 Builtin:InterpreterEntryTrampoline | 40 11111111 Builtin:InterpreterEntryTrampoline |
41 22222222 bar | 41 22222222 bar |
42 | 42 |
| 43 00000000 hello |
| 44 11111111 LazyCompile:~Foo |
| 45 |
43 11111111 Builtin:InterpreterEntryTrampoline | 46 11111111 Builtin:InterpreterEntryTrampoline |
44 22222222 bar | 47 22222222 bar |
45 """ | 48 """ |
46 | 49 |
47 | 50 |
48 class LinuxPerfReportTest(unittest.TestCase): | 51 class LinuxPerfReportTest(unittest.TestCase): |
49 def test_collapsed_callchains_generator(self): | 52 def test_collapsed_callchains_generator(self): |
50 perf_stream = StringIO.StringIO(PERF_SCRIPT_OUTPUT) | 53 perf_stream = StringIO.StringIO(PERF_SCRIPT_OUTPUT) |
51 callchains = list(ipr.collapsed_callchains_generator(perf_stream)) | 54 callchains = list(ipr.collapsed_callchains_generator(perf_stream)) |
52 self.assertListEqual(callchains, [ | 55 self.assertListEqual(callchains, [ |
53 ["foo", "BytecodeHandler:bar"], | 56 ['firstSymbol', 'secondSymbol', '[other]'], |
54 ["foo", "BytecodeHandler:bar"], | 57 ["foo", "BytecodeHandler:bar", "[interpreter]"], |
55 ["beep", "BytecodeHandler:bar"], | 58 ["foo", "BytecodeHandler:bar", "[interpreter]"], |
| 59 ["beep", "BytecodeHandler:bar", "[interpreter]"], |
| 60 ["hello", "v8::internal::Compiler", "Stub:CEntryStub", "[compiler]"], |
| 61 ["Lost", "[misattributed]"], |
| 62 ["hello", "LazyCompile:~Foo", "[jit]"], |
56 ["[entry trampoline]"], | 63 ["[entry trampoline]"], |
57 ]) | 64 ]) |
58 | 65 |
59 def test_collapsed_callchains_generator_show_other(self): | 66 def test_collapsed_callchains_generator_hide_other(self): |
60 perf_stream = StringIO.StringIO(PERF_SCRIPT_OUTPUT) | 67 perf_stream = StringIO.StringIO(PERF_SCRIPT_OUTPUT) |
61 callchains = list(ipr.collapsed_callchains_generator(perf_stream, | 68 callchains = list(ipr.collapsed_callchains_generator(perf_stream, |
62 show_all=True)) | 69 hide_other=True, |
| 70 hide_compiler=True, |
| 71 hide_jit=True)) |
63 self.assertListEqual(callchains, [ | 72 self.assertListEqual(callchains, [ |
64 ['firstSymbol', 'secondSymbol', '[other]'], | 73 ["foo", "BytecodeHandler:bar", "[interpreter]"], |
65 ["foo", "BytecodeHandler:bar"], | 74 ["foo", "BytecodeHandler:bar", "[interpreter]"], |
66 ["foo", "BytecodeHandler:bar"], | 75 ["beep", "BytecodeHandler:bar", "[interpreter]"], |
67 ["beep", "BytecodeHandler:bar"], | |
68 ["hello", "v8::internal::Compiler", "[compiler]"], | |
69 ["Lost", "[misattributed]"], | 76 ["Lost", "[misattributed]"], |
70 ["[entry trampoline]"], | 77 ["[entry trampoline]"], |
71 ]) | 78 ]) |
72 | 79 |
73 def test_calculate_samples_count_per_callchain(self): | 80 def test_calculate_samples_count_per_callchain(self): |
74 counters = ipr.calculate_samples_count_per_callchain([ | 81 counters = ipr.calculate_samples_count_per_callchain([ |
75 ["foo", "BytecodeHandler:bar"], | 82 ["foo", "BytecodeHandler:bar"], |
76 ["foo", "BytecodeHandler:bar"], | 83 ["foo", "BytecodeHandler:bar"], |
77 ["beep", "BytecodeHandler:bar"], | 84 ["beep", "BytecodeHandler:bar"], |
78 ["hello", "v8::internal::Compiler", "[compiler]"], | 85 ["hello", "v8::internal::Compiler", "[compiler]"], |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 perf_stream = StringIO.StringIO(""" | 125 perf_stream = StringIO.StringIO(""" |
119 0000 foo(bar) | 126 0000 foo(bar) |
120 1234 BytecodeHandler:first | 127 1234 BytecodeHandler:first |
121 5678 a::random::call<to>(something, else) | 128 5678 a::random::call<to>(something, else) |
122 9abc BytecodeHandler:second | 129 9abc BytecodeHandler:second |
123 def0 otherIrrelevant(stuff) | 130 def0 otherIrrelevant(stuff) |
124 1111 entrypoint | 131 1111 entrypoint |
125 """) | 132 """) |
126 callchains = list(ipr.collapsed_callchains_generator(perf_stream, False)) | 133 callchains = list(ipr.collapsed_callchains_generator(perf_stream, False)) |
127 self.assertListEqual(callchains, [ | 134 self.assertListEqual(callchains, [ |
128 ["foo", "BytecodeHandler:first"], | 135 ["foo", "BytecodeHandler:first", "[interpreter]"], |
129 ]) | 136 ]) |
130 | 137 |
131 def test_compiler_symbols_regex(self): | 138 def test_compiler_symbols_regex(self): |
132 compiler_symbols = [ | 139 compiler_symbols = [ |
133 "v8::internal::Parser", | 140 "v8::internal::Parser", |
134 "v8::internal::(anonymous namespace)::Compile", | 141 "v8::internal::(anonymous namespace)::Compile", |
135 "v8::internal::Compiler::foo", | 142 "v8::internal::Compiler::foo", |
136 ] | 143 ] |
137 for compiler_symbol in compiler_symbols: | 144 for compiler_symbol in compiler_symbols: |
138 self.assertTrue(ipr.COMPILER_SYMBOLS_RE.match(compiler_symbol)) | 145 self.assertTrue(ipr.COMPILER_SYMBOLS_RE.match(compiler_symbol)) |
139 | 146 |
| 147 def test_jit_code_symbols_regex(self): |
| 148 jit_code_symbols = [ |
| 149 "LazyCompile:~Foo blah.js", |
| 150 "Eval:*", |
| 151 "Script:*Bar tmp.js", |
| 152 ] |
| 153 for jit_code_symbol in jit_code_symbols: |
| 154 self.assertTrue(ipr.JIT_CODE_SYMBOLS_RE.match(jit_code_symbol)) |
| 155 |
140 def test_strip_function_parameters(self): | 156 def test_strip_function_parameters(self): |
141 def should_match(signature, name): | 157 def should_match(signature, name): |
142 self.assertEqual(ipr.strip_function_parameters(signature), name) | 158 self.assertEqual(ipr.strip_function_parameters(signature), name) |
143 | 159 |
144 should_match("foo(bar)", "foo"), | 160 should_match("foo(bar)", "foo"), |
145 should_match("Foo(foomatic::(anonymous)::bar(baz))", "Foo"), | 161 should_match("Foo(foomatic::(anonymous)::bar(baz))", "Foo"), |
146 should_match("v8::(anonymous ns)::bar<thing(with, parentheses)>(baz, poe)", | 162 should_match("v8::(anonymous ns)::bar<thing(with, parentheses)>(baz, poe)", |
147 "v8::(anonymous ns)::bar<thing(with, parentheses)>") | 163 "v8::(anonymous ns)::bar<thing(with, parentheses)>") |
| 164 |
| 165 if __name__ == '__main__': |
| 166 unittest.main() |
OLD | NEW |