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 bytecode_dispatches_report as bdr | 5 import bytecode_dispatches_report as bdr |
6 import unittest | 6 import unittest |
7 | 7 |
8 | 8 |
9 class BytecodeDispatchesReportTest(unittest.TestCase): | 9 class BytecodeDispatchesReportTest(unittest.TestCase): |
10 def test_find_top_counters(self): | 10 def test_find_top_counters(self): |
11 top_counters = bdr.find_top_bytecode_dispatch_pairs({ | 11 top_counters = bdr.find_top_bytecode_dispatch_pairs({ |
12 "a": {"a": 10, "b": 8, "c": 99}, | 12 "a": {"a": (10, 0.3), "b": (8, 0.3), "c": (99, 0.3)}, |
13 "b": {"a": 1, "b": 4, "c": 1}, | 13 "b": {"a": (1, 0.3), "b": (4, 0.3), "c": (1, 0.3)}, |
14 "c": {"a": 42, "b": 3, "c": 7}}, 5) | 14 "c": {"a": (42, 0.3), "b": (3, 0.3), "c": (7, 0.3)}}, 5) |
15 self.assertListEqual(top_counters, [ | 15 self.assertListEqual(top_counters, [ |
16 ('a', 'c', 99), | 16 ('a', 'c', 99), |
17 ('c', 'a', 42), | 17 ('c', 'a', 42), |
18 ('a', 'a', 10), | 18 ('a', 'a', 10), |
19 ('a', 'b', 8), | 19 ('a', 'b', 8), |
20 ('c', 'c', 7)]) | 20 ('c', 'c', 7)]) |
21 | 21 |
22 def test_build_counters_matrix(self): | 22 def test_build_counters_matrix(self): |
23 counters_matrix, xlabels, ylabels = bdr.build_counters_matrix({ | 23 counters_matrix, xlabels, ylabels = bdr.build_counters_matrix({ |
24 "a": {"a": 10, "b": 8, "c": 7}, | 24 "a": {"a": (10, 0.3), "b": (8, 0.3), "c": (7, 0.3)}, |
25 "b": {"a": 1, "c": 4}, | 25 "b": {"a": (1, 0.5), "c": (4, 0.5)}, |
26 "c": {"a": 42, "b": 12, "c": 99}}) | 26 "c": {"a": (42, 0.3), "b": (12, 0.3), "c": (99, 0.3)}}) |
27 self.assertTrue((counters_matrix == [[42, 12, 99], | 27 self.assertTrue((counters_matrix == [[42, 12, 99], |
28 [ 1, 0, 4], | 28 [ 1, 0, 4], |
29 [10, 8, 7]]).all()) | 29 [10, 8, 7]]).all()) |
30 self.assertListEqual(xlabels, ['a', 'b', 'c']) | 30 self.assertListEqual(xlabels, ['a', 'b', 'c']) |
31 self.assertListEqual(ylabels, ['c', 'b', 'a']) | 31 self.assertListEqual(ylabels, ['c', 'b', 'a']) |
32 | 32 |
33 def test_find_top_bytecodes(self): | 33 def test_find_top_bytecodes(self): |
34 top_dispatch_sources = bdr.find_top_bytecodes({ | 34 top_dispatch_sources = bdr.find_top_bytecodes({ |
35 "a": {"a": 10, "b": 8, "c": 7}, | 35 'a': 25, |
36 "b": {"a": 1, "c": 4}, | 36 'b': 5, |
37 "c": {"a": 42, "b": 12, "c": 99} | 37 'c': 153 |
38 }) | 38 }) |
39 self.assertListEqual(top_dispatch_sources, [ | 39 self.assertListEqual(top_dispatch_sources, [ |
40 ('c', 153), | 40 ('c', 153), |
41 ('a', 25), | 41 ('a', 25), |
42 ('b', 5) | 42 ('b', 5) |
43 ]) | 43 ]) |
44 | 44 |
45 def test_find_top_dispatch_sources(self): | 45 def test_find_top_dispatch_sources(self): |
46 top_dispatch_sources = bdr.find_top_dispatch_sources({ | 46 d = { |
47 "a": {"a": 10, "b": 8, "c": 7}, | 47 "a": {"a": (10, 0.3), "b": (8, 0.4), "c": (7, 0.3)}, |
48 "b": {"a": 1, "c": 4}, | 48 "b": {"a": (1, 0.5), "c": (4, 0.5)}, |
49 "c": {"a": 42, "b": 12, "c": 99} | 49 "c": {"a": (42, 0.3), "b": (12, 0.3), "c": (99, 0.3)} |
50 }, "b", 10) | 50 } |
| 51 top_dispatch_sources = bdr.find_top_dispatch_sources(d, "b", 10, False) |
51 self.assertListEqual(top_dispatch_sources, [ | 52 self.assertListEqual(top_dispatch_sources, [ |
52 ("c", 12), | 53 ("c", (12, 0.3)), |
53 ("a", 8) | 54 ("a", (8, 0.4)) |
54 ]) | 55 ]) |
| 56 top_dispatch_sources = bdr.find_top_dispatch_sources(d, "b", 10, True) |
| 57 self.assertListEqual(top_dispatch_sources, [ |
| 58 ("a", (8, 0.4)), |
| 59 ("c", (12, 0.3)) |
| 60 ]) |
OLD | NEW |