Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import ignition_perf_report as ipr | |
| 6 import StringIO | |
| 7 import unittest | |
| 8 | |
| 9 | |
| 10 ## perf script test output. | |
| 11 | |
| 12 PERF_SCRIPT_OUTPUT = """ | |
| 13 # This line is a comment | |
| 14 # This should be ignored too | |
| 15 # | |
| 16 # cdefab01 aRandomSymbol::Name(to, be, ignored) | |
| 17 | |
| 18 00000000 firstSymbol | |
| 19 00000123 secondSymbol | |
| 20 | |
| 21 01234567 foo | |
| 22 abcdef76 BytecodeHandler:bar | |
| 23 76543210 baz | |
| 24 | |
| 25 # Indentation shouldn't matter (neither should this line) | |
| 26 | |
| 27 01234567 foo | |
| 28 abcdef76 BytecodeHandler:bar | |
| 29 76543210 baz | |
| 30 | |
| 31 01234567 beep | |
| 32 abcdef76 BytecodeHandler:bar | |
| 33 76543210 baz | |
| 34 | |
| 35 01234567 hello | |
| 36 abcdef76 Builtin:CompileLazy | |
| 37 76543210 world | |
| 38 11111111 BytecodeHandler:nope | |
| 39 """ | |
| 40 | |
| 41 ## hide_compile_time = False test data. | |
| 42 | |
| 43 PERF_SCRIPT_YIELDED_CALLCHAINS = [ | |
| 44 ["foo", "BytecodeHandler:bar"], | |
| 45 ["foo", "BytecodeHandler:bar"], | |
| 46 ["beep", "BytecodeHandler:bar"], | |
| 47 ["hello", "Builtin:CompileLazy", "world", "BytecodeHandler:nope"], | |
| 48 ] | |
| 49 | |
| 50 | |
| 51 CALLCHAINS_COUNTERS = [ | |
| 52 ('BytecodeHandler:bar;foo', 2), | |
| 53 ('BytecodeHandler:bar;beep', 1), | |
| 54 ('BytecodeHandler:nope;world;Builtin:CompileLazy;hello', 1), | |
| 55 ] | |
| 56 | |
| 57 | |
| 58 HANDLER_SAMPLE_COUNTERS = [ | |
| 59 ("bar", 3), | |
| 60 ("nope", 1), | |
| 61 ] | |
| 62 | |
| 63 | |
| 64 ## hide_compile_time = True test data. | |
| 65 | |
| 66 PERF_SCRIPT_YIELDED_CALLCHAINS_HIDE_COMPILE = [ | |
| 67 ["foo", "BytecodeHandler:bar"], | |
| 68 ["foo", "BytecodeHandler:bar"], | |
| 69 ["beep", "BytecodeHandler:bar"], | |
| 70 ] | |
| 71 | |
| 72 | |
| 73 CALLCHAINS_COUNTERS_HIDE_COMPILE = [ | |
| 74 ('BytecodeHandler:bar;foo', 2), | |
| 75 ('BytecodeHandler:bar;beep', 1), | |
| 76 ] | |
| 77 | |
| 78 | |
| 79 HANDLER_SAMPLE_COUNTERS_HIDE_COMPILE = [ | |
| 80 ("bar", 3), | |
| 81 ] | |
| 82 | |
| 83 ## Regex test cases. | |
| 84 | |
| 85 COMPILER_SYMBOLS = [ | |
| 86 "Builtin:CompileLazy", | |
| 87 "Builtin:CompileOptimizedConcurrent", | |
| 88 "LazyCompile:foo", | |
| 89 "v8::internal::Compile::foo", | |
| 90 ] | |
| 91 | |
| 92 | |
| 93 SYMBOLS_AND_NAMES = [ | |
| 94 ("foo::(anonymous namespace)::bar(baz)", "foo::(anonymous namespace)::bar"), | |
| 95 ("foo::bar<baz<beep>, blop>(hello, world)", "foo::bar<baz<beep>, blop>"), | |
| 96 ("hello(world)", "hello"), | |
| 97 ] | |
| 98 | |
| 99 | |
| 100 class IgnitionPerfReportTest(unittest.TestCase): | |
|
rmcilroy
2016/03/11 11:26:49
Are these tests run on the bots? If not they are p
| |
| 101 def testYieldCollapsedCallchains(self): | |
| 102 perf_stream = StringIO.StringIO(PERF_SCRIPT_OUTPUT) | |
| 103 callchains = list(ipr.yield_collapsed_callchains(perf_stream, False)) | |
| 104 self.assertListEqual(callchains, PERF_SCRIPT_YIELDED_CALLCHAINS) | |
| 105 | |
| 106 def testYieldCollapsedCallchainsHideCompile(self): | |
| 107 perf_stream = StringIO.StringIO(PERF_SCRIPT_OUTPUT) | |
| 108 callchains = list(ipr.yield_collapsed_callchains(perf_stream, True)) | |
| 109 self.assertListEqual(callchains, | |
| 110 PERF_SCRIPT_YIELDED_CALLCHAINS_HIDE_COMPILE) | |
| 111 | |
| 112 def testCountCallchains(self): | |
| 113 counters = ipr.count_callchains(PERF_SCRIPT_YIELDED_CALLCHAINS) | |
| 114 self.assertItemsEqual(counters, CALLCHAINS_COUNTERS) | |
|
rmcilroy
2016/03/11 11:26:49
nit - could you make CALLCHAINS_COUNTERS a constan
Stefano Sanfilippo
2016/03/11 16:33:51
I'd prefer to keep them all outside, in case we ad
rmcilroy
2016/03/14 12:26:52
I disagree - the tests should be easy to reason ab
Stefano Sanfilippo
2016/03/14 13:14:20
I see. Done.
| |
| 115 | |
| 116 def testCountCallchainsHideCompile(self): | |
| 117 counters = ipr.count_callchains(PERF_SCRIPT_YIELDED_CALLCHAINS_HIDE_COMPILE) | |
| 118 self.assertItemsEqual(counters, CALLCHAINS_COUNTERS_HIDE_COMPILE) | |
| 119 | |
| 120 def testCountHandlerSamples(self): | |
| 121 counters = ipr.count_handler_samples(PERF_SCRIPT_YIELDED_CALLCHAINS) | |
| 122 self.assertItemsEqual(counters, HANDLER_SAMPLE_COUNTERS) | |
| 123 | |
| 124 def testCountHandlerSamplesHideCompile(self): | |
| 125 counters = ipr.count_handler_samples( | |
| 126 PERF_SCRIPT_YIELDED_CALLCHAINS_HIDE_COMPILE) | |
| 127 self.assertItemsEqual(counters, HANDLER_SAMPLE_COUNTERS_HIDE_COMPILE) | |
| 128 | |
| 129 def testCompilerSymbolsRegex(self): | |
| 130 for compiler_symbol in COMPILER_SYMBOLS: | |
| 131 self.assertTrue(ipr.COMPILER_SYMBOLS_RE.match(compiler_symbol)) | |
| 132 | |
| 133 def testSymbolNameRegex(self): | |
| 134 for symbol, name in SYMBOLS_AND_NAMES: | |
| 135 self.assertEqual(ipr.SYMBOL_NAME_RE.match(symbol).group(1), name) | |
| OLD | NEW |