| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 uint64_t address_; | 83 uint64_t address_; |
| 84 uint64_t entry_count_; | 84 uint64_t entry_count_; |
| 85 // Followed by entry_count_ instances of PerfJitDebugEntry. | 85 // Followed by entry_count_ instances of PerfJitDebugEntry. |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 const char PerfJitLogger::kFilenameFormatString[] = "./jit-%d.dump"; | 88 const char PerfJitLogger::kFilenameFormatString[] = "./jit-%d.dump"; |
| 89 | 89 |
| 90 // Extra padding for the PID in the filename | 90 // Extra padding for the PID in the filename |
| 91 const int PerfJitLogger::kFilenameBufferPadding = 16; | 91 const int PerfJitLogger::kFilenameBufferPadding = 16; |
| 92 | 92 |
| 93 base::LazyRecursiveMutex PerfJitLogger::file_mutex_; |
| 94 // The following static variables are protected by PerfJitLogger::file_mutex_. |
| 95 uint64_t PerfJitLogger::reference_count_ = 0; |
| 96 void* PerfJitLogger::marker_address_ = nullptr; |
| 97 uint64_t PerfJitLogger::code_index_ = 0; |
| 98 FILE* PerfJitLogger::perf_output_handle_ = nullptr; |
| 99 |
| 93 void PerfJitLogger::OpenJitDumpFile() { | 100 void PerfJitLogger::OpenJitDumpFile() { |
| 94 // Open the perf JIT dump file. | 101 // Open the perf JIT dump file. |
| 95 perf_output_handle_ = nullptr; | 102 perf_output_handle_ = nullptr; |
| 96 | 103 |
| 97 int bufferSize = sizeof(kFilenameFormatString) + kFilenameBufferPadding; | 104 int bufferSize = sizeof(kFilenameFormatString) + kFilenameBufferPadding; |
| 98 ScopedVector<char> perf_dump_name(bufferSize); | 105 ScopedVector<char> perf_dump_name(bufferSize); |
| 99 int size = SNPrintF(perf_dump_name, kFilenameFormatString, | 106 int size = SNPrintF(perf_dump_name, kFilenameFormatString, |
| 100 base::OS::GetCurrentProcessId()); | 107 base::OS::GetCurrentProcessId()); |
| 101 CHECK_NE(size, -1); | 108 CHECK_NE(size, -1); |
| 102 | 109 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 130 return (marker_address == MAP_FAILED) ? nullptr : marker_address; | 137 return (marker_address == MAP_FAILED) ? nullptr : marker_address; |
| 131 } | 138 } |
| 132 | 139 |
| 133 void PerfJitLogger::CloseMarkerFile(void* marker_address) { | 140 void PerfJitLogger::CloseMarkerFile(void* marker_address) { |
| 134 if (marker_address == nullptr) return; | 141 if (marker_address == nullptr) return; |
| 135 long page_size = sysconf(_SC_PAGESIZE); // NOLINT(runtime/int) | 142 long page_size = sysconf(_SC_PAGESIZE); // NOLINT(runtime/int) |
| 136 if (page_size == -1) return; | 143 if (page_size == -1) return; |
| 137 munmap(marker_address, page_size); | 144 munmap(marker_address, page_size); |
| 138 } | 145 } |
| 139 | 146 |
| 140 PerfJitLogger::PerfJitLogger() | 147 PerfJitLogger::PerfJitLogger() { |
| 141 : perf_output_handle_(nullptr), code_index_(0), marker_address_(nullptr) { | 148 base::LockGuard<base::RecursiveMutex> guard_file(file_mutex_.Pointer()); |
| 142 OpenJitDumpFile(); | 149 |
| 143 if (perf_output_handle_ == nullptr) return; | 150 reference_count_++; |
| 144 LogWriteHeader(); | 151 // If this is the first logger, open the file and write the header. |
| 152 if (reference_count_ == 1) { |
| 153 OpenJitDumpFile(); |
| 154 if (perf_output_handle_ == nullptr) return; |
| 155 LogWriteHeader(); |
| 156 } |
| 145 } | 157 } |
| 146 | 158 |
| 147 PerfJitLogger::~PerfJitLogger() { CloseJitDumpFile(); } | 159 PerfJitLogger::~PerfJitLogger() { |
| 160 base::LockGuard<base::RecursiveMutex> guard_file(file_mutex_.Pointer()); |
| 161 |
| 162 reference_count_--; |
| 163 // If this was the last logger, close the file. |
| 164 if (reference_count_ == 0) { |
| 165 CloseJitDumpFile(); |
| 166 } |
| 167 } |
| 148 | 168 |
| 149 uint64_t PerfJitLogger::GetTimestamp() { | 169 uint64_t PerfJitLogger::GetTimestamp() { |
| 150 struct timespec ts; | 170 struct timespec ts; |
| 151 int result = clock_gettime(CLOCK_MONOTONIC, &ts); | 171 int result = clock_gettime(CLOCK_MONOTONIC, &ts); |
| 152 DCHECK_EQ(0, result); | 172 DCHECK_EQ(0, result); |
| 153 USE(result); | 173 USE(result); |
| 154 static const uint64_t kNsecPerSec = 1000000000; | 174 static const uint64_t kNsecPerSec = 1000000000; |
| 155 return (ts.tv_sec * kNsecPerSec) + ts.tv_nsec; | 175 return (ts.tv_sec * kNsecPerSec) + ts.tv_nsec; |
| 156 } | 176 } |
| 157 | 177 |
| 158 void PerfJitLogger::LogRecordedBuffer(AbstractCode* abstract_code, | 178 void PerfJitLogger::LogRecordedBuffer(AbstractCode* abstract_code, |
| 159 SharedFunctionInfo* shared, | 179 SharedFunctionInfo* shared, |
| 160 const char* name, int length) { | 180 const char* name, int length) { |
| 161 if (perf_output_handle_ == nullptr) return; | |
| 162 if (FLAG_perf_basic_prof_only_functions && | 181 if (FLAG_perf_basic_prof_only_functions && |
| 163 (abstract_code->kind() != AbstractCode::FUNCTION && | 182 (abstract_code->kind() != AbstractCode::FUNCTION && |
| 164 abstract_code->kind() != AbstractCode::INTERPRETED_FUNCTION && | 183 abstract_code->kind() != AbstractCode::INTERPRETED_FUNCTION && |
| 165 abstract_code->kind() != AbstractCode::OPTIMIZED_FUNCTION)) { | 184 abstract_code->kind() != AbstractCode::OPTIMIZED_FUNCTION)) { |
| 166 return; | 185 return; |
| 167 } | 186 } |
| 168 | 187 |
| 188 base::LockGuard<base::RecursiveMutex> guard_file(file_mutex_.Pointer()); |
| 189 |
| 190 if (perf_output_handle_ == nullptr) return; |
| 191 |
| 169 // We only support non-interpreted functions. | 192 // We only support non-interpreted functions. |
| 170 if (!abstract_code->IsCode()) return; | 193 if (!abstract_code->IsCode()) return; |
| 171 Code* code = abstract_code->GetCode(); | 194 Code* code = abstract_code->GetCode(); |
| 172 DCHECK(code->instruction_start() == code->address() + Code::kHeaderSize); | 195 DCHECK(code->instruction_start() == code->address() + Code::kHeaderSize); |
| 173 | 196 |
| 174 // Debug info has to be emitted first. | 197 // Debug info has to be emitted first. |
| 175 if (FLAG_perf_prof_debug_info) { | 198 if (FLAG_perf_prof_debug_info && shared != nullptr) { |
| 176 LogWriteDebugInfo(code, shared); | 199 LogWriteDebugInfo(code, shared); |
| 177 } | 200 } |
| 178 | 201 |
| 179 const char* code_name = name; | 202 const char* code_name = name; |
| 180 uint8_t* code_pointer = reinterpret_cast<uint8_t*>(code->instruction_start()); | 203 uint8_t* code_pointer = reinterpret_cast<uint8_t*>(code->instruction_start()); |
| 181 uint32_t code_size = code->is_crankshafted() ? code->safepoint_table_offset() | 204 uint32_t code_size = code->is_crankshafted() ? code->safepoint_table_offset() |
| 182 : code->instruction_size(); | 205 : code->instruction_size(); |
| 183 | 206 |
| 184 static const char string_terminator[] = "\0"; | 207 static const char string_terminator[] = "\0"; |
| 185 | 208 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 header.time_stamp_ = | 327 header.time_stamp_ = |
| 305 static_cast<uint64_t>(base::OS::TimeCurrentMillis() * 1000.0); | 328 static_cast<uint64_t>(base::OS::TimeCurrentMillis() * 1000.0); |
| 306 header.flags_ = 0; | 329 header.flags_ = 0; |
| 307 | 330 |
| 308 LogWriteBytes(reinterpret_cast<const char*>(&header), sizeof(header)); | 331 LogWriteBytes(reinterpret_cast<const char*>(&header), sizeof(header)); |
| 309 } | 332 } |
| 310 | 333 |
| 311 #endif // V8_OS_LINUX | 334 #endif // V8_OS_LINUX |
| 312 } // namespace internal | 335 } // namespace internal |
| 313 } // namespace v8 | 336 } // namespace v8 |
| OLD | NEW |