Line data Source code
1 : // Copyright 2016 the V8 project authors. All rights reserved.
2 : // Redistribution and use in source and binary forms, with or without
3 : // modification, are permitted provided that the following conditions are
4 : // met:
5 : //
6 : // * Redistributions of source code must retain the above copyright
7 : // notice, this list of conditions and the following disclaimer.
8 : // * Redistributions in binary form must reproduce the above
9 : // copyright notice, this list of conditions and the following
10 : // disclaimer in the documentation and/or other materials provided
11 : // with the distribution.
12 : // * Neither the name of Google Inc. nor the names of its
13 : // contributors may be used to endorse or promote products derived
14 : // from this software without specific prior written permission.
15 : //
16 : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 : // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 : // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 : // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 : // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 : // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 : // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 : // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 :
28 : #ifndef V8_PERF_JIT_H_
29 : #define V8_PERF_JIT_H_
30 :
31 : #include "src/log.h"
32 :
33 : namespace v8 {
34 : namespace internal {
35 :
36 : #if V8_OS_LINUX
37 :
38 : // Linux perf tool logging support
39 : class PerfJitLogger : public CodeEventLogger {
40 : public:
41 : PerfJitLogger();
42 : virtual ~PerfJitLogger();
43 :
44 : void CodeMoveEvent(AbstractCode* from, Address to) override;
45 0 : void CodeDisableOptEvent(AbstractCode* code,
46 0 : SharedFunctionInfo* shared) override {}
47 :
48 : private:
49 : void OpenJitDumpFile();
50 : void CloseJitDumpFile();
51 : void* OpenMarkerFile(int fd);
52 : void CloseMarkerFile(void* marker_address);
53 :
54 : uint64_t GetTimestamp();
55 : void LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo* shared,
56 : const char* name, int length) override;
57 :
58 : // Extension added to V8 log file name to get the low-level log name.
59 : static const char kFilenameFormatString[];
60 : static const int kFilenameBufferPadding;
61 :
62 : // File buffer size of the low-level log. We don't use the default to
63 : // minimize the associated overhead.
64 : static const int kLogBufferSize = 2 * MB;
65 :
66 : void LogWriteBytes(const char* bytes, int size);
67 : void LogWriteHeader();
68 : void LogWriteDebugInfo(Code* code, SharedFunctionInfo* shared);
69 : void LogWriteUnwindingInfo(Code* code);
70 :
71 : static const uint32_t kElfMachIA32 = 3;
72 : static const uint32_t kElfMachX64 = 62;
73 : static const uint32_t kElfMachARM = 40;
74 : static const uint32_t kElfMachMIPS = 10;
75 : static const uint32_t kElfMachARM64 = 183;
76 :
77 : uint32_t GetElfMach() {
78 : #if V8_TARGET_ARCH_IA32
79 : return kElfMachIA32;
80 : #elif V8_TARGET_ARCH_X64
81 : return kElfMachX64;
82 : #elif V8_TARGET_ARCH_ARM
83 : return kElfMachARM;
84 : #elif V8_TARGET_ARCH_MIPS
85 : return kElfMachMIPS;
86 : #elif V8_TARGET_ARCH_ARM64
87 : return kElfMachARM64;
88 : #else
89 : UNIMPLEMENTED();
90 : return 0;
91 : #endif
92 : }
93 :
94 : #if V8_TARGET_ARCH_32_BIT
95 : static const int kElfHeaderSize = 0x34;
96 : #elif V8_TARGET_ARCH_64_BIT
97 : static const int kElfHeaderSize = 0x40;
98 : #else
99 : #error Unknown target architecture pointer size
100 : #endif
101 :
102 : // Per-process singleton file. We assume that there is one main isolate;
103 : // to determine when it goes away, we keep reference count.
104 : static base::LazyRecursiveMutex file_mutex_;
105 : static FILE* perf_output_handle_;
106 : static uint64_t reference_count_;
107 : static void* marker_address_;
108 : static uint64_t code_index_;
109 : };
110 :
111 : #else
112 :
113 : // PerfJitLogger is only implemented on Linux
114 : class PerfJitLogger : public CodeEventLogger {
115 : public:
116 : void CodeMoveEvent(AbstractCode* from, Address to) override {
117 : UNIMPLEMENTED();
118 : }
119 :
120 : void CodeDisableOptEvent(AbstractCode* code,
121 : SharedFunctionInfo* shared) override {
122 : UNIMPLEMENTED();
123 : }
124 :
125 : void LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo* shared,
126 : const char* name, int length) override {
127 : UNIMPLEMENTED();
128 : }
129 : };
130 :
131 : #endif // V8_OS_LINUX
132 : } // namespace internal
133 : } // namespace v8
134 : #endif
|