Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/perf-jit.cc

Issue 360783006: Reland "Linux perf tool support update + refactoring." (r22118) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove perf support in Android Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/perf-jit.h ('k') | src/third_party/kernel/tools/perf/util/jitdump.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 #if defined(__linux__) && !defined(ANDROID)
29 #include <fcntl.h>
30 #include <unistd.h>
31 #include "src/third_party/kernel/tools/perf/util/jitdump.h"
32 #endif // defined(__linux__) && !defined(ANDROID)
33
34 #include "src/perf-jit.h"
35
36 namespace v8 {
37 namespace internal {
38
39 #if defined(__linux__) && !defined(ANDROID)
40
41 const char PerfJitLogger::kFilenameFormatString[] = "perfjit-%d.dump";
42
43 // Timestamp module name
44 const char PerfJitLogger::kTraceClockDevice[] = "/dev/trace_clock";
45
46 // Extra padding for the PID in the filename
47 const int PerfJitLogger::kFilenameBufferPadding = 16;
48
49
50 static clockid_t get_clockid(int fd) {
51 return ((~(clockid_t) (fd) << 3) | 3);
52 }
53
54
55 PerfJitLogger::PerfJitLogger()
56 : perf_output_handle_(NULL),
57 code_index_(0) {
58 // Open the perf JIT dump file.
59 int bufferSize = sizeof(kFilenameFormatString) + kFilenameBufferPadding;
60 ScopedVector<char> perf_dump_name(bufferSize);
61 int size = SNPrintF(
62 perf_dump_name,
63 kFilenameFormatString,
64 base::OS::GetCurrentProcessId());
65 CHECK_NE(size, -1);
66 perf_output_handle_ = base::OS::FOpen(perf_dump_name.start(),
67 base::OS::LogFileOpenMode);
68 CHECK_NE(perf_output_handle_, NULL);
69 setvbuf(perf_output_handle_, NULL, _IOFBF, kLogBufferSize);
70 clock_fd_ = open(kTraceClockDevice, O_RDONLY);
71 if (clock_fd_ == -1) {
72 FATAL("Could not get perf timestamp clock");
73 }
74 clock_id_ = get_clockid(clock_fd_);
75 if (kClockInvalid == clock_id_) {
76 FATAL("Could not get perf timestamp clock");
77 }
78
79 LogWriteHeader();
80 }
81
82
83 PerfJitLogger::~PerfJitLogger() {
84 fclose(perf_output_handle_);
85 close(clock_fd_);
86 perf_output_handle_ = NULL;
87 }
88
89
90 uint64_t PerfJitLogger::GetTimestamp() {
91 struct timespec ts;
92
93 clock_gettime(clock_id_, &ts);
94 return ((uint64_t) ts.tv_sec * kNsecPerSec) + ts.tv_nsec;
95 }
96
97
98 void PerfJitLogger::LogRecordedBuffer(Code* code,
99 SharedFunctionInfo*,
100 const char* name,
101 int length) {
102 ASSERT(code->instruction_start() == code->address() + Code::kHeaderSize);
103 ASSERT(perf_output_handle_ != NULL);
104
105 const char* code_name = name;
106 uint8_t* code_pointer = reinterpret_cast<uint8_t*>(code->instruction_start());
107 uint32_t code_size = code->instruction_size();
108
109 static const char string_terminator[] = "\0";
110
111 jr_code_load code_load;
112 code_load.p.id = JIT_CODE_LOAD;
113 code_load.p.total_size = sizeof(code_load) + length + 1 + code_size;
114 code_load.p.timestamp = GetTimestamp();
115 code_load.pid = static_cast<uint32_t>(base::OS::GetCurrentProcessId());
116 code_load.tid = static_cast<uint32_t>(base::OS::GetCurrentThreadId());
117 code_load.vma = 0x0; // Our addresses are absolute.
118 code_load.code_addr = reinterpret_cast<uint64_t>(code_pointer);
119 code_load.code_size = code_size;
120 code_load.code_index = code_index_;
121
122 code_index_++;
123
124 LogWriteBytes(reinterpret_cast<const char*>(&code_load), sizeof(code_load));
125 LogWriteBytes(code_name, length);
126 LogWriteBytes(string_terminator, 1);
127 LogWriteBytes(reinterpret_cast<const char*>(code_pointer), code_size);
128 }
129
130
131 void PerfJitLogger::CodeMoveEvent(Address from, Address to) {
132 // Code relocation not supported.
133 UNREACHABLE();
134 }
135
136
137 void PerfJitLogger::CodeDeleteEvent(Address from) {
138 // V8 does not send notification on code unload
139 }
140
141
142 void PerfJitLogger::SnapshotPositionEvent(Address addr, int pos) {
143 }
144
145
146 void PerfJitLogger::LogWriteBytes(const char* bytes, int size) {
147 size_t rv = fwrite(bytes, 1, size, perf_output_handle_);
148 ASSERT(static_cast<size_t>(size) == rv);
149 USE(rv);
150 }
151
152
153 void PerfJitLogger::LogWriteHeader() {
154 ASSERT(perf_output_handle_ != NULL);
155 jitheader header;
156 header.magic = JITHEADER_MAGIC;
157 header.version = JITHEADER_VERSION;
158 header.total_size = sizeof(jitheader);
159 header.pad1 = 0xdeadbeef;
160 header.elf_mach = GetElfMach();
161 header.pid = base::OS::GetCurrentProcessId();
162 header.timestamp =
163 static_cast<uint64_t>(base::OS::TimeCurrentMillis() * 1000.0);
164 LogWriteBytes(reinterpret_cast<const char*>(&header), sizeof(header));
165 }
166
167 #endif // defined(__linux__) && !defined(ANDROID)
168
169 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/perf-jit.h ('k') | src/third_party/kernel/tools/perf/util/jitdump.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698