blob: 6efa4bbd6b65c3d559ceba6afdbf092c964bf99e [file] [log] [blame]
Ben Murdochda12d292016-06-02 14:46:10 +01001// 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
33namespace v8 {
34namespace internal {
35
36#if V8_OS_LINUX
37
38// Linux perf tool logging support
39class PerfJitLogger : public CodeEventLogger {
40 public:
41 PerfJitLogger();
42 virtual ~PerfJitLogger();
43
44 void CodeMoveEvent(AbstractCode* from, Address to) override;
45 void CodeDisableOptEvent(AbstractCode* code,
46 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);
Ben Murdoch61f157c2016-09-16 13:49:30 +010069 void LogWriteUnwindingInfo(Code* code);
Ben Murdochda12d292016-06-02 14:46:10 +010070
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;
Ben Murdoch61f157c2016-09-16 13:49:30 +010075 static const uint32_t kElfMachARM64 = 183;
Ben Murdochda12d292016-06-02 14:46:10 +010076
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;
Ben Murdoch61f157c2016-09-16 13:49:30 +010086#elif V8_TARGET_ARCH_ARM64
87 return kElfMachARM64;
Ben Murdochda12d292016-06-02 14:46:10 +010088#else
89 UNIMPLEMENTED();
90 return 0;
91#endif
92 }
93
94 // Per-process singleton file. We assume that there is one main isolate;
95 // to determine when it goes away, we keep reference count.
96 static base::LazyRecursiveMutex file_mutex_;
97 static FILE* perf_output_handle_;
98 static uint64_t reference_count_;
99 static void* marker_address_;
100 static uint64_t code_index_;
101};
102
103#else
104
105// PerfJitLogger is only implemented on Linux
106class PerfJitLogger : public CodeEventLogger {
107 public:
108 void CodeMoveEvent(AbstractCode* from, Address to) override {
109 UNIMPLEMENTED();
110 }
111
112 void CodeDisableOptEvent(AbstractCode* code,
113 SharedFunctionInfo* shared) override {
114 UNIMPLEMENTED();
115 }
116
117 void LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo* shared,
118 const char* name, int length) override {
119 UNIMPLEMENTED();
120 }
121};
122
123#endif // V8_OS_LINUX
124} // namespace internal
125} // namespace v8
126#endif