blob: 25cc3b36866f6595b0debe00392659f74b7903a4 [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);
69
70 static const uint32_t kElfMachIA32 = 3;
71 static const uint32_t kElfMachX64 = 62;
72 static const uint32_t kElfMachARM = 40;
73 static const uint32_t kElfMachMIPS = 10;
74
75 uint32_t GetElfMach() {
76#if V8_TARGET_ARCH_IA32
77 return kElfMachIA32;
78#elif V8_TARGET_ARCH_X64
79 return kElfMachX64;
80#elif V8_TARGET_ARCH_ARM
81 return kElfMachARM;
82#elif V8_TARGET_ARCH_MIPS
83 return kElfMachMIPS;
84#else
85 UNIMPLEMENTED();
86 return 0;
87#endif
88 }
89
90 // Per-process singleton file. We assume that there is one main isolate;
91 // to determine when it goes away, we keep reference count.
92 static base::LazyRecursiveMutex file_mutex_;
93 static FILE* perf_output_handle_;
94 static uint64_t reference_count_;
95 static void* marker_address_;
96 static uint64_t code_index_;
97};
98
99#else
100
101// PerfJitLogger is only implemented on Linux
102class PerfJitLogger : public CodeEventLogger {
103 public:
104 void CodeMoveEvent(AbstractCode* from, Address to) override {
105 UNIMPLEMENTED();
106 }
107
108 void CodeDisableOptEvent(AbstractCode* code,
109 SharedFunctionInfo* shared) override {
110 UNIMPLEMENTED();
111 }
112
113 void LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo* shared,
114 const char* name, int length) override {
115 UNIMPLEMENTED();
116 }
117};
118
119#endif // V8_OS_LINUX
120} // namespace internal
121} // namespace v8
122#endif