• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5import StringIO
6import unittest
7import linux_perf_bytecode_annotate as bytecode_annotate
8
9
10PERF_SCRIPT_OUTPUT = """
11# This line is a comment
12# This should be ignored too
13#
14#    cdefab01  aRandomSymbol::Name(to, be, ignored)
15
16   00000000 firstSymbol
17   00000123 secondSymbol
18
19   01234567 foo
20   abcdef76 BytecodeHandler:bar+0x12
21   76543210 baz
22   abcdef76 BytecodeHandler:bar+0x16
23   76543210 baz
24
25   01234567 foo
26   abcdef76 BytecodeHandler:foo+0x1
27   76543210 baz
28   abcdef76 BytecodeHandler:bar+0x2
29   76543210 bar
30
31   abcdef76 BytecodeHandler:bar+0x19
32
33   abcdef76 BytecodeHandler:bar+0x12
34
35   abcdef76 BytecodeHandler:bar+0x12
36"""
37
38
39D8_CODEGEN_OUTPUT = """
40kind = BYTECODE_HANDLER
41name = foo
42compiler = turbofan
43Instructions (size = 3)
440x3101394a3c0     0  55             push rbp
450x3101394a3c1     1  ffe3           jmp rbx
46
47kind = BYTECODE_HANDLER
48name = bar
49compiler = turbofan
50Instructions (size = 5)
510x3101394b3c0     0  55             push rbp
520x3101394b3c1     1  4883c428       REX.W addq rsp,0x28
53# Unexpected comment
540x3101394b3c5     5  ffe3           jmp rbx
55
56kind = BYTECODE_HANDLER
57name = baz
58compiler = turbofan
59Instructions (size = 5)
600x3101394c3c0     0  55             push rbp
610x3101394c3c1     1  4883c428       REX.W addq rsp,0x28
620x3101394c3c5     5  ffe3           jmp rbx
63"""
64
65
66class LinuxPerfBytecodeAnnotateTest(unittest.TestCase):
67
68  def test_bytecode_offset_generator(self):
69    perf_stream = StringIO.StringIO(PERF_SCRIPT_OUTPUT)
70    offsets = list(
71        bytecode_annotate.bytecode_offset_generator(perf_stream, "bar"))
72    self.assertListEqual(offsets, [18, 25, 18, 18])
73
74  def test_bytecode_disassembly_generator(self):
75    codegen_stream = StringIO.StringIO(D8_CODEGEN_OUTPUT)
76    disassembly = list(
77        bytecode_annotate.bytecode_disassembly_generator(codegen_stream, "bar"))
78    self.assertListEqual(disassembly, [
79        "0x3101394b3c0     0  55             push rbp",
80        "0x3101394b3c1     1  4883c428       REX.W addq rsp,0x28",
81        "0x3101394b3c5     5  ffe3           jmp rbx"])
82
83
84if __name__ == "__main__":
85  unittest.main()
86