Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5 | #include "src/log.h" |
| 6 | |
| 7 | #include <cstdarg> |
| 8 | #include <sstream> |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10 | #include "src/bailout-reason.h" |
| 11 | #include "src/base/platform/platform.h" |
| 12 | #include "src/bootstrapper.h" |
| 13 | #include "src/code-stubs.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 14 | #include "src/deoptimizer.h" |
| 15 | #include "src/global-handles.h" |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 16 | #include "src/interpreter/bytecodes.h" |
| 17 | #include "src/interpreter/interpreter.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 18 | #include "src/log-inl.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 19 | #include "src/log-utils.h" |
| 20 | #include "src/macro-assembler.h" |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 21 | #include "src/perf-jit.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 22 | #include "src/profiler/cpu-profiler.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 23 | #include "src/runtime-profiler.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 24 | #include "src/string-stream.h" |
| 25 | #include "src/vm-state-inl.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 26 | |
| 27 | namespace v8 { |
| 28 | namespace internal { |
| 29 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 30 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 31 | #define DECLARE_EVENT(ignore1, name) name, |
| 32 | static const char* const kLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = { |
| 33 | LOG_EVENTS_AND_TAGS_LIST(DECLARE_EVENT) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 34 | }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 35 | #undef DECLARE_EVENT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 36 | |
| 37 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 38 | #define CALL_LISTENERS(Call) \ |
| 39 | for (int i = 0; i < listeners_.length(); ++i) { \ |
| 40 | listeners_[i]->Call; \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 43 | #define PROFILER_LOG(Call) \ |
| 44 | do { \ |
| 45 | CpuProfiler* cpu_profiler = isolate_->cpu_profiler(); \ |
| 46 | if (cpu_profiler->is_profiling()) { \ |
| 47 | cpu_profiler->Call; \ |
| 48 | } \ |
| 49 | } while (false); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 50 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 51 | static const char* ComputeMarker(SharedFunctionInfo* shared, |
| 52 | AbstractCode* code) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 53 | switch (code->kind()) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 54 | case AbstractCode::FUNCTION: |
| 55 | case AbstractCode::INTERPRETED_FUNCTION: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 56 | return shared->optimization_disabled() ? "" : "~"; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 57 | case AbstractCode::OPTIMIZED_FUNCTION: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 58 | return "*"; |
| 59 | default: |
| 60 | return ""; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
| 64 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 65 | class CodeEventLogger::NameBuffer { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 66 | public: |
| 67 | NameBuffer() { Reset(); } |
| 68 | |
| 69 | void Reset() { |
| 70 | utf8_pos_ = 0; |
| 71 | } |
| 72 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 73 | void Init(Logger::LogEventsAndTags tag) { |
| 74 | Reset(); |
| 75 | AppendBytes(kLogEventsNames[tag]); |
| 76 | AppendByte(':'); |
| 77 | } |
| 78 | |
| 79 | void AppendName(Name* name) { |
| 80 | if (name->IsString()) { |
| 81 | AppendString(String::cast(name)); |
| 82 | } else { |
| 83 | Symbol* symbol = Symbol::cast(name); |
| 84 | AppendBytes("symbol("); |
| 85 | if (!symbol->name()->IsUndefined()) { |
| 86 | AppendBytes("\""); |
| 87 | AppendString(String::cast(symbol->name())); |
| 88 | AppendBytes("\" "); |
| 89 | } |
| 90 | AppendBytes("hash "); |
| 91 | AppendHex(symbol->Hash()); |
| 92 | AppendByte(')'); |
| 93 | } |
| 94 | } |
| 95 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 96 | void AppendString(String* str) { |
| 97 | if (str == NULL) return; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 98 | int uc16_length = Min(str->length(), kUtf16BufferSize); |
| 99 | String::WriteToFlat(str, utf16_buffer, 0, uc16_length); |
| 100 | int previous = unibrow::Utf16::kNoPreviousCharacter; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 101 | for (int i = 0; i < uc16_length && utf8_pos_ < kUtf8BufferSize; ++i) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 102 | uc16 c = utf16_buffer[i]; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 103 | if (c <= unibrow::Utf8::kMaxOneByteChar) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 104 | utf8_buffer_[utf8_pos_++] = static_cast<char>(c); |
| 105 | } else { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 106 | int char_length = unibrow::Utf8::Length(c, previous); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 107 | if (utf8_pos_ + char_length > kUtf8BufferSize) break; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 108 | unibrow::Utf8::Encode(utf8_buffer_ + utf8_pos_, c, previous); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 109 | utf8_pos_ += char_length; |
| 110 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 111 | previous = c; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | |
| 115 | void AppendBytes(const char* bytes, int size) { |
| 116 | size = Min(size, kUtf8BufferSize - utf8_pos_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 117 | MemCopy(utf8_buffer_ + utf8_pos_, bytes, size); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 118 | utf8_pos_ += size; |
| 119 | } |
| 120 | |
| 121 | void AppendBytes(const char* bytes) { |
| 122 | AppendBytes(bytes, StrLength(bytes)); |
| 123 | } |
| 124 | |
| 125 | void AppendByte(char c) { |
| 126 | if (utf8_pos_ >= kUtf8BufferSize) return; |
| 127 | utf8_buffer_[utf8_pos_++] = c; |
| 128 | } |
| 129 | |
| 130 | void AppendInt(int n) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 131 | int space = kUtf8BufferSize - utf8_pos_; |
| 132 | if (space <= 0) return; |
| 133 | Vector<char> buffer(utf8_buffer_ + utf8_pos_, space); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 134 | int size = SNPrintF(buffer, "%d", n); |
| 135 | if (size > 0 && utf8_pos_ + size <= kUtf8BufferSize) { |
| 136 | utf8_pos_ += size; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | void AppendHex(uint32_t n) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 141 | int space = kUtf8BufferSize - utf8_pos_; |
| 142 | if (space <= 0) return; |
| 143 | Vector<char> buffer(utf8_buffer_ + utf8_pos_, space); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 144 | int size = SNPrintF(buffer, "%x", n); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 145 | if (size > 0 && utf8_pos_ + size <= kUtf8BufferSize) { |
| 146 | utf8_pos_ += size; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | const char* get() { return utf8_buffer_; } |
| 151 | int size() const { return utf8_pos_; } |
| 152 | |
| 153 | private: |
| 154 | static const int kUtf8BufferSize = 512; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 155 | static const int kUtf16BufferSize = kUtf8BufferSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 156 | |
| 157 | int utf8_pos_; |
| 158 | char utf8_buffer_[kUtf8BufferSize]; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 159 | uc16 utf16_buffer[kUtf16BufferSize]; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 163 | CodeEventLogger::CodeEventLogger() : name_buffer_(new NameBuffer) { } |
| 164 | |
| 165 | CodeEventLogger::~CodeEventLogger() { delete name_buffer_; } |
| 166 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 167 | void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 168 | AbstractCode* code, const char* comment) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 169 | name_buffer_->Init(tag); |
| 170 | name_buffer_->AppendBytes(comment); |
| 171 | LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); |
| 172 | } |
| 173 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 174 | void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 175 | AbstractCode* code, Name* name) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 176 | name_buffer_->Init(tag); |
| 177 | name_buffer_->AppendName(name); |
| 178 | LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); |
| 179 | } |
| 180 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 181 | void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 182 | AbstractCode* code, |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 183 | SharedFunctionInfo* shared, Name* name) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 184 | name_buffer_->Init(tag); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 185 | name_buffer_->AppendBytes(ComputeMarker(shared, code)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 186 | name_buffer_->AppendName(name); |
| 187 | LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size()); |
| 188 | } |
| 189 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 190 | void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 191 | AbstractCode* code, |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 192 | SharedFunctionInfo* shared, Name* source, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 193 | int line, int column) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 194 | name_buffer_->Init(tag); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 195 | name_buffer_->AppendBytes(ComputeMarker(shared, code)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 196 | name_buffer_->AppendString(shared->DebugName()); |
| 197 | name_buffer_->AppendByte(' '); |
| 198 | if (source->IsString()) { |
| 199 | name_buffer_->AppendString(String::cast(source)); |
| 200 | } else { |
| 201 | name_buffer_->AppendBytes("symbol(hash "); |
| 202 | name_buffer_->AppendHex(Name::cast(source)->Hash()); |
| 203 | name_buffer_->AppendByte(')'); |
| 204 | } |
| 205 | name_buffer_->AppendByte(':'); |
| 206 | name_buffer_->AppendInt(line); |
| 207 | LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size()); |
| 208 | } |
| 209 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 210 | void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 211 | AbstractCode* code, int args_count) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 212 | name_buffer_->Init(tag); |
| 213 | name_buffer_->AppendInt(args_count); |
| 214 | LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); |
| 215 | } |
| 216 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 217 | void CodeEventLogger::RegExpCodeCreateEvent(AbstractCode* code, |
| 218 | String* source) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 219 | name_buffer_->Init(Logger::REG_EXP_TAG); |
| 220 | name_buffer_->AppendString(source); |
| 221 | LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); |
| 222 | } |
| 223 | |
| 224 | |
| 225 | // Linux perf tool logging support |
| 226 | class PerfBasicLogger : public CodeEventLogger { |
| 227 | public: |
| 228 | PerfBasicLogger(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 229 | ~PerfBasicLogger() override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 230 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 231 | void CodeMoveEvent(AbstractCode* from, Address to) override {} |
| 232 | void CodeDisableOptEvent(AbstractCode* code, |
| 233 | SharedFunctionInfo* shared) override {} |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 234 | |
| 235 | private: |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 236 | void LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo* shared, |
| 237 | const char* name, int length) override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 238 | |
| 239 | // Extension added to V8 log file name to get the low-level log name. |
| 240 | static const char kFilenameFormatString[]; |
| 241 | static const int kFilenameBufferPadding; |
| 242 | |
| 243 | // File buffer size of the low-level log. We don't use the default to |
| 244 | // minimize the associated overhead. |
| 245 | static const int kLogBufferSize = 2 * MB; |
| 246 | |
| 247 | FILE* perf_output_handle_; |
| 248 | }; |
| 249 | |
| 250 | const char PerfBasicLogger::kFilenameFormatString[] = "/tmp/perf-%d.map"; |
| 251 | // Extra space for the PID in the filename |
| 252 | const int PerfBasicLogger::kFilenameBufferPadding = 16; |
| 253 | |
| 254 | PerfBasicLogger::PerfBasicLogger() |
| 255 | : perf_output_handle_(NULL) { |
| 256 | // Open the perf JIT dump file. |
| 257 | int bufferSize = sizeof(kFilenameFormatString) + kFilenameBufferPadding; |
| 258 | ScopedVector<char> perf_dump_name(bufferSize); |
| 259 | int size = SNPrintF( |
| 260 | perf_dump_name, |
| 261 | kFilenameFormatString, |
| 262 | base::OS::GetCurrentProcessId()); |
| 263 | CHECK_NE(size, -1); |
| 264 | perf_output_handle_ = |
| 265 | base::OS::FOpen(perf_dump_name.start(), base::OS::LogFileOpenMode); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 266 | CHECK_NOT_NULL(perf_output_handle_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 267 | setvbuf(perf_output_handle_, NULL, _IOFBF, kLogBufferSize); |
| 268 | } |
| 269 | |
| 270 | |
| 271 | PerfBasicLogger::~PerfBasicLogger() { |
| 272 | fclose(perf_output_handle_); |
| 273 | perf_output_handle_ = NULL; |
| 274 | } |
| 275 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 276 | void PerfBasicLogger::LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo*, |
| 277 | const char* name, int length) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 278 | if (FLAG_perf_basic_prof_only_functions && |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 279 | (code->kind() != AbstractCode::FUNCTION && |
| 280 | code->kind() != AbstractCode::INTERPRETED_FUNCTION && |
| 281 | code->kind() != AbstractCode::OPTIMIZED_FUNCTION)) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 282 | return; |
| 283 | } |
| 284 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 285 | // Linux perf expects hex literals without a leading 0x, while some |
| 286 | // implementations of printf might prepend one when using the %p format |
| 287 | // for pointers, leading to wrongly formatted JIT symbols maps. |
| 288 | // |
| 289 | // Instead, we use V8PRIxPTR format string and cast pointer to uintpr_t, |
| 290 | // so that we have control over the exact output format. |
| 291 | base::OS::FPrint(perf_output_handle_, "%" V8PRIxPTR " %x %.*s\n", |
| 292 | reinterpret_cast<uintptr_t>(code->instruction_start()), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 293 | code->instruction_size(), length, name); |
| 294 | } |
| 295 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 296 | // Low-level logging support. |
| 297 | #define LL_LOG(Call) if (ll_logger_) ll_logger_->Call; |
| 298 | |
| 299 | class LowLevelLogger : public CodeEventLogger { |
| 300 | public: |
| 301 | explicit LowLevelLogger(const char* file_name); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 302 | ~LowLevelLogger() override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 303 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 304 | void CodeMoveEvent(AbstractCode* from, Address to) override; |
| 305 | void CodeDisableOptEvent(AbstractCode* code, |
| 306 | SharedFunctionInfo* shared) override {} |
| 307 | void SnapshotPositionEvent(HeapObject* obj, int pos); |
| 308 | void CodeMovingGCEvent() override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 309 | |
| 310 | private: |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 311 | void LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo* shared, |
| 312 | const char* name, int length) override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 313 | |
| 314 | // Low-level profiling event structures. |
| 315 | struct CodeCreateStruct { |
| 316 | static const char kTag = 'C'; |
| 317 | |
| 318 | int32_t name_size; |
| 319 | Address code_address; |
| 320 | int32_t code_size; |
| 321 | }; |
| 322 | |
| 323 | |
| 324 | struct CodeMoveStruct { |
| 325 | static const char kTag = 'M'; |
| 326 | |
| 327 | Address from_address; |
| 328 | Address to_address; |
| 329 | }; |
| 330 | |
| 331 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 332 | static const char kCodeMovingGCTag = 'G'; |
| 333 | |
| 334 | |
| 335 | // Extension added to V8 log file name to get the low-level log name. |
| 336 | static const char kLogExt[]; |
| 337 | |
| 338 | // File buffer size of the low-level log. We don't use the default to |
| 339 | // minimize the associated overhead. |
| 340 | static const int kLogBufferSize = 2 * MB; |
| 341 | |
| 342 | void LogCodeInfo(); |
| 343 | void LogWriteBytes(const char* bytes, int size); |
| 344 | |
| 345 | template <typename T> |
| 346 | void LogWriteStruct(const T& s) { |
| 347 | char tag = T::kTag; |
| 348 | LogWriteBytes(reinterpret_cast<const char*>(&tag), sizeof(tag)); |
| 349 | LogWriteBytes(reinterpret_cast<const char*>(&s), sizeof(s)); |
| 350 | } |
| 351 | |
| 352 | FILE* ll_output_handle_; |
| 353 | }; |
| 354 | |
| 355 | const char LowLevelLogger::kLogExt[] = ".ll"; |
| 356 | |
| 357 | LowLevelLogger::LowLevelLogger(const char* name) |
| 358 | : ll_output_handle_(NULL) { |
| 359 | // Open the low-level log file. |
| 360 | size_t len = strlen(name); |
| 361 | ScopedVector<char> ll_name(static_cast<int>(len + sizeof(kLogExt))); |
| 362 | MemCopy(ll_name.start(), name, len); |
| 363 | MemCopy(ll_name.start() + len, kLogExt, sizeof(kLogExt)); |
| 364 | ll_output_handle_ = |
| 365 | base::OS::FOpen(ll_name.start(), base::OS::LogFileOpenMode); |
| 366 | setvbuf(ll_output_handle_, NULL, _IOFBF, kLogBufferSize); |
| 367 | |
| 368 | LogCodeInfo(); |
| 369 | } |
| 370 | |
| 371 | |
| 372 | LowLevelLogger::~LowLevelLogger() { |
| 373 | fclose(ll_output_handle_); |
| 374 | ll_output_handle_ = NULL; |
| 375 | } |
| 376 | |
| 377 | |
| 378 | void LowLevelLogger::LogCodeInfo() { |
| 379 | #if V8_TARGET_ARCH_IA32 |
| 380 | const char arch[] = "ia32"; |
| 381 | #elif V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_64_BIT |
| 382 | const char arch[] = "x64"; |
| 383 | #elif V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT |
| 384 | const char arch[] = "x32"; |
| 385 | #elif V8_TARGET_ARCH_ARM |
| 386 | const char arch[] = "arm"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 387 | #elif V8_TARGET_ARCH_PPC |
| 388 | const char arch[] = "ppc"; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 389 | #elif V8_TARGET_ARCH_MIPS |
| 390 | const char arch[] = "mips"; |
| 391 | #elif V8_TARGET_ARCH_X87 |
| 392 | const char arch[] = "x87"; |
| 393 | #elif V8_TARGET_ARCH_ARM64 |
| 394 | const char arch[] = "arm64"; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 395 | #elif V8_TARGET_ARCH_S390 |
| 396 | const char arch[] = "s390"; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 397 | #else |
| 398 | const char arch[] = "unknown"; |
| 399 | #endif |
| 400 | LogWriteBytes(arch, sizeof(arch)); |
| 401 | } |
| 402 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 403 | void LowLevelLogger::LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo*, |
| 404 | const char* name, int length) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 405 | CodeCreateStruct event; |
| 406 | event.name_size = length; |
| 407 | event.code_address = code->instruction_start(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 408 | event.code_size = code->instruction_size(); |
| 409 | LogWriteStruct(event); |
| 410 | LogWriteBytes(name, length); |
| 411 | LogWriteBytes( |
| 412 | reinterpret_cast<const char*>(code->instruction_start()), |
| 413 | code->instruction_size()); |
| 414 | } |
| 415 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 416 | void LowLevelLogger::CodeMoveEvent(AbstractCode* from, Address to) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 417 | CodeMoveStruct event; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 418 | event.from_address = from->instruction_start(); |
| 419 | size_t header_size = from->instruction_start() - from->address(); |
| 420 | event.to_address = to + header_size; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 421 | LogWriteStruct(event); |
| 422 | } |
| 423 | |
| 424 | |
| 425 | void LowLevelLogger::LogWriteBytes(const char* bytes, int size) { |
| 426 | size_t rv = fwrite(bytes, 1, size, ll_output_handle_); |
| 427 | DCHECK(static_cast<size_t>(size) == rv); |
| 428 | USE(rv); |
| 429 | } |
| 430 | |
| 431 | |
| 432 | void LowLevelLogger::CodeMovingGCEvent() { |
| 433 | const char tag = kCodeMovingGCTag; |
| 434 | |
| 435 | LogWriteBytes(&tag, sizeof(tag)); |
| 436 | } |
| 437 | |
| 438 | |
| 439 | #define JIT_LOG(Call) if (jit_logger_) jit_logger_->Call; |
| 440 | |
| 441 | |
| 442 | class JitLogger : public CodeEventLogger { |
| 443 | public: |
| 444 | explicit JitLogger(JitCodeEventHandler code_event_handler); |
| 445 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 446 | void CodeMoveEvent(AbstractCode* from, Address to) override; |
| 447 | void CodeDisableOptEvent(AbstractCode* code, |
| 448 | SharedFunctionInfo* shared) override {} |
| 449 | void AddCodeLinePosInfoEvent(void* jit_handler_data, int pc_offset, |
| 450 | int position, |
| 451 | JitCodeEvent::PositionType position_type); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 452 | |
| 453 | void* StartCodePosInfoEvent(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 454 | void EndCodePosInfoEvent(AbstractCode* code, void* jit_handler_data); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 455 | |
| 456 | private: |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 457 | void LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo* shared, |
| 458 | const char* name, int length) override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 459 | |
| 460 | JitCodeEventHandler code_event_handler_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 461 | base::Mutex logger_mutex_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 462 | }; |
| 463 | |
| 464 | |
| 465 | JitLogger::JitLogger(JitCodeEventHandler code_event_handler) |
| 466 | : code_event_handler_(code_event_handler) { |
| 467 | } |
| 468 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 469 | void JitLogger::LogRecordedBuffer(AbstractCode* code, |
| 470 | SharedFunctionInfo* shared, const char* name, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 471 | int length) { |
| 472 | JitCodeEvent event; |
| 473 | memset(&event, 0, sizeof(event)); |
| 474 | event.type = JitCodeEvent::CODE_ADDED; |
| 475 | event.code_start = code->instruction_start(); |
| 476 | event.code_len = code->instruction_size(); |
| 477 | Handle<SharedFunctionInfo> shared_function_handle; |
| 478 | if (shared && shared->script()->IsScript()) { |
| 479 | shared_function_handle = Handle<SharedFunctionInfo>(shared); |
| 480 | } |
| 481 | event.script = ToApiHandle<v8::UnboundScript>(shared_function_handle); |
| 482 | event.name.str = name; |
| 483 | event.name.len = length; |
| 484 | code_event_handler_(&event); |
| 485 | } |
| 486 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 487 | void JitLogger::CodeMoveEvent(AbstractCode* from, Address to) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 488 | base::LockGuard<base::Mutex> guard(&logger_mutex_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 489 | |
| 490 | JitCodeEvent event; |
| 491 | event.type = JitCodeEvent::CODE_MOVED; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 492 | event.code_start = from->instruction_start(); |
| 493 | event.code_len = from->instruction_size(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 494 | |
| 495 | // Calculate the header size. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 496 | const size_t header_size = from->instruction_start() - from->address(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 497 | |
| 498 | // Calculate the new start address of the instructions. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 499 | event.new_code_start = to + header_size; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 500 | |
| 501 | code_event_handler_(&event); |
| 502 | } |
| 503 | |
| 504 | void JitLogger::AddCodeLinePosInfoEvent( |
| 505 | void* jit_handler_data, |
| 506 | int pc_offset, |
| 507 | int position, |
| 508 | JitCodeEvent::PositionType position_type) { |
| 509 | JitCodeEvent event; |
| 510 | memset(&event, 0, sizeof(event)); |
| 511 | event.type = JitCodeEvent::CODE_ADD_LINE_POS_INFO; |
| 512 | event.user_data = jit_handler_data; |
| 513 | event.line_info.offset = pc_offset; |
| 514 | event.line_info.pos = position; |
| 515 | event.line_info.position_type = position_type; |
| 516 | |
| 517 | code_event_handler_(&event); |
| 518 | } |
| 519 | |
| 520 | |
| 521 | void* JitLogger::StartCodePosInfoEvent() { |
| 522 | JitCodeEvent event; |
| 523 | memset(&event, 0, sizeof(event)); |
| 524 | event.type = JitCodeEvent::CODE_START_LINE_INFO_RECORDING; |
| 525 | |
| 526 | code_event_handler_(&event); |
| 527 | return event.user_data; |
| 528 | } |
| 529 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 530 | void JitLogger::EndCodePosInfoEvent(AbstractCode* code, |
| 531 | void* jit_handler_data) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 532 | JitCodeEvent event; |
| 533 | memset(&event, 0, sizeof(event)); |
| 534 | event.type = JitCodeEvent::CODE_END_LINE_INFO_RECORDING; |
| 535 | event.code_start = code->instruction_start(); |
| 536 | event.user_data = jit_handler_data; |
| 537 | |
| 538 | code_event_handler_(&event); |
| 539 | } |
| 540 | |
| 541 | |
| 542 | // The Profiler samples pc and sp values for the main thread. |
| 543 | // Each sample is appended to a circular buffer. |
| 544 | // An independent thread removes data and writes it to the log. |
| 545 | // This design minimizes the time spent in the sampler. |
| 546 | // |
| 547 | class Profiler: public base::Thread { |
| 548 | public: |
| 549 | explicit Profiler(Isolate* isolate); |
| 550 | void Engage(); |
| 551 | void Disengage(); |
| 552 | |
| 553 | // Inserts collected profiling data into buffer. |
| 554 | void Insert(TickSample* sample) { |
| 555 | if (paused_) |
| 556 | return; |
| 557 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 558 | if (Succ(head_) == static_cast<int>(base::NoBarrier_Load(&tail_))) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 559 | overflow_ = true; |
| 560 | } else { |
| 561 | buffer_[head_] = *sample; |
| 562 | head_ = Succ(head_); |
| 563 | buffer_semaphore_.Signal(); // Tell we have an element. |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | virtual void Run(); |
| 568 | |
| 569 | // Pause and Resume TickSample data collection. |
| 570 | void pause() { paused_ = true; } |
| 571 | void resume() { paused_ = false; } |
| 572 | |
| 573 | private: |
| 574 | // Waits for a signal and removes profiling data. |
| 575 | bool Remove(TickSample* sample) { |
| 576 | buffer_semaphore_.Wait(); // Wait for an element. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 577 | *sample = buffer_[base::NoBarrier_Load(&tail_)]; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 578 | bool result = overflow_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 579 | base::NoBarrier_Store(&tail_, static_cast<base::Atomic32>( |
| 580 | Succ(base::NoBarrier_Load(&tail_)))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 581 | overflow_ = false; |
| 582 | return result; |
| 583 | } |
| 584 | |
| 585 | // Returns the next index in the cyclic buffer. |
| 586 | int Succ(int index) { return (index + 1) % kBufferSize; } |
| 587 | |
| 588 | Isolate* isolate_; |
| 589 | // Cyclic buffer for communicating profiling samples |
| 590 | // between the signal handler and the worker thread. |
| 591 | static const int kBufferSize = 128; |
| 592 | TickSample buffer_[kBufferSize]; // Buffer storage. |
| 593 | int head_; // Index to the buffer head. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 594 | base::Atomic32 tail_; // Index to the buffer tail. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 595 | bool overflow_; // Tell whether a buffer overflow has occurred. |
| 596 | // Sempahore used for buffer synchronization. |
| 597 | base::Semaphore buffer_semaphore_; |
| 598 | |
| 599 | // Tells whether profiler is engaged, that is, processing thread is stated. |
| 600 | bool engaged_; |
| 601 | |
| 602 | // Tells whether worker thread should continue running. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 603 | base::Atomic32 running_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 604 | |
| 605 | // Tells whether we are currently recording tick samples. |
| 606 | bool paused_; |
| 607 | }; |
| 608 | |
| 609 | |
| 610 | // |
| 611 | // Ticker used to provide ticks to the profiler and the sliding state |
| 612 | // window. |
| 613 | // |
| 614 | class Ticker: public Sampler { |
| 615 | public: |
| 616 | Ticker(Isolate* isolate, int interval): |
| 617 | Sampler(isolate, interval), |
| 618 | profiler_(NULL) {} |
| 619 | |
| 620 | ~Ticker() { if (IsActive()) Stop(); } |
| 621 | |
| 622 | virtual void Tick(TickSample* sample) { |
| 623 | if (profiler_) profiler_->Insert(sample); |
| 624 | } |
| 625 | |
| 626 | void SetProfiler(Profiler* profiler) { |
| 627 | DCHECK(profiler_ == NULL); |
| 628 | profiler_ = profiler; |
| 629 | IncreaseProfilingDepth(); |
| 630 | if (!IsActive()) Start(); |
| 631 | } |
| 632 | |
| 633 | void ClearProfiler() { |
| 634 | profiler_ = NULL; |
| 635 | if (IsActive()) Stop(); |
| 636 | DecreaseProfilingDepth(); |
| 637 | } |
| 638 | |
| 639 | private: |
| 640 | Profiler* profiler_; |
| 641 | }; |
| 642 | |
| 643 | |
| 644 | // |
| 645 | // Profiler implementation. |
| 646 | // |
| 647 | Profiler::Profiler(Isolate* isolate) |
| 648 | : base::Thread(Options("v8:Profiler")), |
| 649 | isolate_(isolate), |
| 650 | head_(0), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 651 | overflow_(false), |
| 652 | buffer_semaphore_(0), |
| 653 | engaged_(false), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 654 | paused_(false) { |
| 655 | base::NoBarrier_Store(&tail_, 0); |
| 656 | base::NoBarrier_Store(&running_, 0); |
| 657 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 658 | |
| 659 | |
| 660 | void Profiler::Engage() { |
| 661 | if (engaged_) return; |
| 662 | engaged_ = true; |
| 663 | |
| 664 | std::vector<base::OS::SharedLibraryAddress> addresses = |
| 665 | base::OS::GetSharedLibraryAddresses(); |
| 666 | for (size_t i = 0; i < addresses.size(); ++i) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 667 | LOG(isolate_, |
| 668 | SharedLibraryEvent(addresses[i].library_path, addresses[i].start, |
| 669 | addresses[i].end, addresses[i].aslr_slide)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | // Start thread processing the profiler buffer. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 673 | base::NoBarrier_Store(&running_, 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 674 | Start(); |
| 675 | |
| 676 | // Register to get ticks. |
| 677 | Logger* logger = isolate_->logger(); |
| 678 | logger->ticker_->SetProfiler(this); |
| 679 | |
| 680 | logger->ProfilerBeginEvent(); |
| 681 | } |
| 682 | |
| 683 | |
| 684 | void Profiler::Disengage() { |
| 685 | if (!engaged_) return; |
| 686 | |
| 687 | // Stop receiving ticks. |
| 688 | isolate_->logger()->ticker_->ClearProfiler(); |
| 689 | |
| 690 | // Terminate the worker thread by setting running_ to false, |
| 691 | // inserting a fake element in the queue and then wait for |
| 692 | // the thread to terminate. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 693 | base::NoBarrier_Store(&running_, 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 694 | TickSample sample; |
| 695 | // Reset 'paused_' flag, otherwise semaphore may not be signalled. |
| 696 | resume(); |
| 697 | Insert(&sample); |
| 698 | Join(); |
| 699 | |
| 700 | LOG(isolate_, UncheckedStringEvent("profiler", "end")); |
| 701 | } |
| 702 | |
| 703 | |
| 704 | void Profiler::Run() { |
| 705 | TickSample sample; |
| 706 | bool overflow = Remove(&sample); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 707 | while (base::NoBarrier_Load(&running_)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 708 | LOG(isolate_, TickEvent(&sample, overflow)); |
| 709 | overflow = Remove(&sample); |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | |
| 714 | // |
| 715 | // Logger class implementation. |
| 716 | // |
| 717 | |
| 718 | Logger::Logger(Isolate* isolate) |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 719 | : isolate_(isolate), |
| 720 | ticker_(NULL), |
| 721 | profiler_(NULL), |
| 722 | log_events_(NULL), |
| 723 | is_logging_(false), |
| 724 | log_(new Log(this)), |
| 725 | perf_basic_logger_(NULL), |
| 726 | perf_jit_logger_(NULL), |
| 727 | ll_logger_(NULL), |
| 728 | jit_logger_(NULL), |
| 729 | listeners_(5), |
| 730 | is_initialized_(false) {} |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 731 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 732 | Logger::~Logger() { |
| 733 | delete log_; |
| 734 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 735 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 736 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 737 | void Logger::addCodeEventListener(CodeEventListener* listener) { |
| 738 | DCHECK(!hasCodeEventListener(listener)); |
| 739 | listeners_.Add(listener); |
| 740 | } |
| 741 | |
| 742 | |
| 743 | void Logger::removeCodeEventListener(CodeEventListener* listener) { |
| 744 | DCHECK(hasCodeEventListener(listener)); |
| 745 | listeners_.RemoveElement(listener); |
| 746 | } |
| 747 | |
| 748 | |
| 749 | bool Logger::hasCodeEventListener(CodeEventListener* listener) { |
| 750 | return listeners_.Contains(listener); |
| 751 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 752 | |
| 753 | |
| 754 | void Logger::ProfilerBeginEvent() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 755 | if (!log_->IsEnabled()) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 756 | Log::MessageBuilder msg(log_); |
| 757 | msg.Append("profiler,\"begin\",%d", kSamplingIntervalMs); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 758 | msg.WriteToLogFile(); |
| 759 | } |
| 760 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 761 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 762 | void Logger::StringEvent(const char* name, const char* value) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 763 | if (FLAG_log) UncheckedStringEvent(name, value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 767 | void Logger::UncheckedStringEvent(const char* name, const char* value) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 768 | if (!log_->IsEnabled()) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 769 | Log::MessageBuilder msg(log_); |
| 770 | msg.Append("%s,\"%s\"", name, value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 771 | msg.WriteToLogFile(); |
| 772 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 773 | |
| 774 | |
| 775 | void Logger::IntEvent(const char* name, int value) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 776 | if (FLAG_log) UncheckedIntEvent(name, value); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 780 | void Logger::IntPtrTEvent(const char* name, intptr_t value) { |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 781 | if (FLAG_log) UncheckedIntPtrTEvent(name, value); |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 785 | void Logger::UncheckedIntEvent(const char* name, int value) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 786 | if (!log_->IsEnabled()) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 787 | Log::MessageBuilder msg(log_); |
| 788 | msg.Append("%s,%d", name, value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 789 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 793 | void Logger::UncheckedIntPtrTEvent(const char* name, intptr_t value) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 794 | if (!log_->IsEnabled()) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 795 | Log::MessageBuilder msg(log_); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 796 | msg.Append("%s,%" V8PRIdPTR, name, value); |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 797 | msg.WriteToLogFile(); |
| 798 | } |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 799 | |
| 800 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 801 | void Logger::HandleEvent(const char* name, Object** location) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 802 | if (!log_->IsEnabled() || !FLAG_log_handles) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 803 | Log::MessageBuilder msg(log_); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 804 | msg.Append("%s,%p", name, location); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 805 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 809 | // ApiEvent is private so all the calls come from the Logger class. It is the |
| 810 | // caller's responsibility to ensure that log is enabled and that |
| 811 | // FLAG_log_api is true. |
| 812 | void Logger::ApiEvent(const char* format, ...) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 813 | DCHECK(log_->IsEnabled() && FLAG_log_api); |
| 814 | Log::MessageBuilder msg(log_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 815 | va_list ap; |
| 816 | va_start(ap, format); |
| 817 | msg.AppendVA(format, ap); |
| 818 | va_end(ap); |
| 819 | msg.WriteToLogFile(); |
| 820 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 821 | |
| 822 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 823 | void Logger::ApiSecurityCheck() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 824 | if (!log_->IsEnabled() || !FLAG_log_api) return; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 825 | ApiEvent("api,check-security"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 826 | } |
| 827 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 828 | void Logger::SharedLibraryEvent(const std::string& library_path, |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 829 | uintptr_t start, uintptr_t end, |
| 830 | intptr_t aslr_slide) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 831 | if (!log_->IsEnabled() || !FLAG_prof_cpp) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 832 | Log::MessageBuilder msg(log_); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 833 | msg.Append("shared-library,\"%s\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR |
| 834 | ",%" V8PRIdPTR, |
| 835 | library_path.c_str(), start, end, aslr_slide); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 836 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 840 | void Logger::CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta) { |
| 841 | PROFILER_LOG(CodeDeoptEvent(code, pc, fp_to_sp_delta)); |
| 842 | if (!log_->IsEnabled() || !FLAG_log_internal_timer_events) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 843 | Log::MessageBuilder msg(log_); |
| 844 | int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds()); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 845 | msg.Append("code-deopt,%d,%d", since_epoch, code->CodeSize()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 846 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 850 | void Logger::CurrentTimeEvent() { |
| 851 | if (!log_->IsEnabled()) return; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 852 | DCHECK(FLAG_log_timer_events || FLAG_prof_cpp); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 853 | Log::MessageBuilder msg(log_); |
| 854 | int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds()); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 855 | msg.Append("current-time,%d", since_epoch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 856 | msg.WriteToLogFile(); |
| 857 | } |
| 858 | |
| 859 | |
| 860 | void Logger::TimerEvent(Logger::StartEnd se, const char* name) { |
| 861 | if (!log_->IsEnabled()) return; |
| 862 | DCHECK(FLAG_log_internal_timer_events); |
| 863 | Log::MessageBuilder msg(log_); |
| 864 | int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds()); |
| 865 | const char* format = (se == START) ? "timer-event-start,\"%s\",%ld" |
| 866 | : "timer-event-end,\"%s\",%ld"; |
| 867 | msg.Append(format, name, since_epoch); |
| 868 | msg.WriteToLogFile(); |
| 869 | } |
| 870 | |
| 871 | |
| 872 | void Logger::EnterExternal(Isolate* isolate) { |
| 873 | LOG(isolate, TimerEvent(START, TimerEventExternal::name())); |
| 874 | DCHECK(isolate->current_vm_state() == JS); |
| 875 | isolate->set_current_vm_state(EXTERNAL); |
| 876 | } |
| 877 | |
| 878 | |
| 879 | void Logger::LeaveExternal(Isolate* isolate) { |
| 880 | LOG(isolate, TimerEvent(END, TimerEventExternal::name())); |
| 881 | DCHECK(isolate->current_vm_state() == EXTERNAL); |
| 882 | isolate->set_current_vm_state(JS); |
| 883 | } |
| 884 | |
| 885 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 886 | template <class TimerEvent> |
| 887 | void TimerEventScope<TimerEvent>::LogTimerEvent(Logger::StartEnd se) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 888 | Logger::CallEventLogger(isolate_, TimerEvent::name(), se, |
| 889 | TimerEvent::expose_to_api()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | |
| 893 | // Instantiate template methods. |
| 894 | #define V(TimerName, expose) \ |
| 895 | template void TimerEventScope<TimerEvent##TimerName>::LogTimerEvent( \ |
| 896 | Logger::StartEnd se); |
| 897 | TIMER_EVENTS_LIST(V) |
| 898 | #undef V |
| 899 | |
| 900 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 901 | namespace { |
| 902 | // Emits the source code of a regexp. Used by regexp events. |
| 903 | void LogRegExpSource(Handle<JSRegExp> regexp, Isolate* isolate, |
| 904 | Log::MessageBuilder* msg) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 905 | // Prints "/" + re.source + "/" + |
| 906 | // (re.global?"g":"") + (re.ignorecase?"i":"") + (re.multiline?"m":"") |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 907 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 908 | Handle<Object> source = |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 909 | JSReceiver::GetProperty(isolate, regexp, "source").ToHandleChecked(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 910 | if (!source->IsString()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 911 | msg->Append("no source"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 912 | return; |
| 913 | } |
| 914 | |
| 915 | switch (regexp->TypeTag()) { |
| 916 | case JSRegExp::ATOM: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 917 | msg->Append('a'); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 918 | break; |
| 919 | default: |
| 920 | break; |
| 921 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 922 | msg->Append('/'); |
| 923 | msg->AppendDetailed(*Handle<String>::cast(source), false); |
| 924 | msg->Append('/'); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 925 | |
| 926 | // global flag |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 927 | Handle<Object> global = |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 928 | JSReceiver::GetProperty(isolate, regexp, "global").ToHandleChecked(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 929 | if (global->IsTrue()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 930 | msg->Append('g'); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 931 | } |
| 932 | // ignorecase flag |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 933 | Handle<Object> ignorecase = |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 934 | JSReceiver::GetProperty(isolate, regexp, "ignoreCase").ToHandleChecked(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 935 | if (ignorecase->IsTrue()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 936 | msg->Append('i'); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 937 | } |
| 938 | // multiline flag |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 939 | Handle<Object> multiline = |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 940 | JSReceiver::GetProperty(isolate, regexp, "multiline").ToHandleChecked(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 941 | if (multiline->IsTrue()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 942 | msg->Append('m'); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 943 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 944 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 945 | } // namespace |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 946 | |
| 947 | |
| 948 | void Logger::RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 949 | if (!log_->IsEnabled() || !FLAG_log_regexp) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 950 | Log::MessageBuilder msg(log_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 951 | msg.Append("regexp-compile,"); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 952 | LogRegExpSource(regexp, isolate_, &msg); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 953 | msg.Append(in_cache ? ",hit" : ",miss"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 954 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 958 | void Logger::ApiNamedPropertyAccess(const char* tag, |
| 959 | JSObject* holder, |
| 960 | Object* name) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 961 | DCHECK(name->IsName()); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 962 | if (!log_->IsEnabled() || !FLAG_log_api) return; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 963 | String* class_name_obj = holder->class_name(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 964 | base::SmartArrayPointer<char> class_name = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 965 | class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 966 | if (name->IsString()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 967 | base::SmartArrayPointer<char> property_name = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 968 | String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 969 | ApiEvent("api,%s,\"%s\",\"%s\"", tag, class_name.get(), |
| 970 | property_name.get()); |
| 971 | } else { |
| 972 | Symbol* symbol = Symbol::cast(name); |
| 973 | uint32_t hash = symbol->Hash(); |
| 974 | if (symbol->name()->IsUndefined()) { |
| 975 | ApiEvent("api,%s,\"%s\",symbol(hash %x)", tag, class_name.get(), hash); |
| 976 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 977 | base::SmartArrayPointer<char> str = |
| 978 | String::cast(symbol->name()) |
| 979 | ->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 980 | ApiEvent("api,%s,\"%s\",symbol(\"%s\" hash %x)", tag, class_name.get(), |
| 981 | str.get(), hash); |
| 982 | } |
| 983 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | void Logger::ApiIndexedPropertyAccess(const char* tag, |
| 987 | JSObject* holder, |
| 988 | uint32_t index) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 989 | if (!log_->IsEnabled() || !FLAG_log_api) return; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 990 | String* class_name_obj = holder->class_name(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 991 | base::SmartArrayPointer<char> class_name = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 992 | class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 993 | ApiEvent("api,%s,\"%s\",%u", tag, class_name.get(), index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 994 | } |
| 995 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 996 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 997 | void Logger::ApiObjectAccess(const char* tag, JSObject* object) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 998 | if (!log_->IsEnabled() || !FLAG_log_api) return; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 999 | String* class_name_obj = object->class_name(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1000 | base::SmartArrayPointer<char> class_name = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1001 | class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1002 | ApiEvent("api,%s,\"%s\"", tag, class_name.get()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | |
| 1006 | void Logger::ApiEntryCall(const char* name) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1007 | if (!log_->IsEnabled() || !FLAG_log_api) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1008 | ApiEvent("api,%s", name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | |
| 1012 | void Logger::NewEvent(const char* name, void* object, size_t size) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1013 | if (!log_->IsEnabled() || !FLAG_log) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1014 | Log::MessageBuilder msg(log_); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1015 | msg.Append("new,%s,%p,%u", name, object, static_cast<unsigned int>(size)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1016 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | |
| 1020 | void Logger::DeleteEvent(const char* name, void* object) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1021 | if (!log_->IsEnabled() || !FLAG_log) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1022 | Log::MessageBuilder msg(log_); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1023 | msg.Append("delete,%s,%p", name, object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1024 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1028 | void Logger::CallbackEventInternal(const char* prefix, Name* name, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1029 | Address entry_point) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1030 | if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 1031 | Log::MessageBuilder msg(log_); |
| 1032 | msg.Append("%s,%s,-2,", |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1033 | kLogEventsNames[CODE_CREATION_EVENT], |
| 1034 | kLogEventsNames[CALLBACK_TAG]); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1035 | msg.AppendAddress(entry_point); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1036 | if (name->IsString()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1037 | base::SmartArrayPointer<char> str = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1038 | String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 1039 | msg.Append(",1,\"%s%s\"", prefix, str.get()); |
| 1040 | } else { |
| 1041 | Symbol* symbol = Symbol::cast(name); |
| 1042 | if (symbol->name()->IsUndefined()) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1043 | msg.Append(",1,symbol(hash %x)", symbol->Hash()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1044 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1045 | base::SmartArrayPointer<char> str = |
| 1046 | String::cast(symbol->name()) |
| 1047 | ->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1048 | msg.Append(",1,symbol(\"%s%s\" hash %x)", prefix, str.get(), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1049 | symbol->Hash()); |
| 1050 | } |
| 1051 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1052 | msg.WriteToLogFile(); |
| 1053 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1054 | |
| 1055 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1056 | void Logger::CallbackEvent(Name* name, Address entry_point) { |
| 1057 | PROFILER_LOG(CallbackEvent(name, entry_point)); |
| 1058 | CallbackEventInternal("", name, entry_point); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1062 | void Logger::GetterCallbackEvent(Name* name, Address entry_point) { |
| 1063 | PROFILER_LOG(GetterCallbackEvent(name, entry_point)); |
| 1064 | CallbackEventInternal("get ", name, entry_point); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1068 | void Logger::SetterCallbackEvent(Name* name, Address entry_point) { |
| 1069 | PROFILER_LOG(SetterCallbackEvent(name, entry_point)); |
| 1070 | CallbackEventInternal("set ", name, entry_point); |
| 1071 | } |
| 1072 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1073 | static void AppendCodeCreateHeader(Log::MessageBuilder* msg, |
| 1074 | Logger::LogEventsAndTags tag, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1075 | AbstractCode* code) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1076 | DCHECK(msg); |
| 1077 | msg->Append("%s,%s,%d,", |
| 1078 | kLogEventsNames[Logger::CODE_CREATION_EVENT], |
| 1079 | kLogEventsNames[tag], |
| 1080 | code->kind()); |
| 1081 | msg->AppendAddress(code->address()); |
| 1082 | msg->Append(",%d,", code->ExecutableSize()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1083 | } |
| 1084 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1085 | void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1086 | const char* comment) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1087 | PROFILER_LOG(CodeCreateEvent(tag, code, comment)); |
| 1088 | |
| 1089 | if (!is_logging_code_events()) return; |
| 1090 | CALL_LISTENERS(CodeCreateEvent(tag, code, comment)); |
| 1091 | |
| 1092 | if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 1093 | Log::MessageBuilder msg(log_); |
| 1094 | AppendCodeCreateHeader(&msg, tag, code); |
| 1095 | msg.AppendDoubleQuotedString(comment); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1096 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1099 | void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1100 | Name* name) { |
| 1101 | PROFILER_LOG(CodeCreateEvent(tag, code, name)); |
| 1102 | |
| 1103 | if (!is_logging_code_events()) return; |
| 1104 | CALL_LISTENERS(CodeCreateEvent(tag, code, name)); |
| 1105 | |
| 1106 | if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 1107 | Log::MessageBuilder msg(log_); |
| 1108 | AppendCodeCreateHeader(&msg, tag, code); |
| 1109 | if (name->IsString()) { |
| 1110 | msg.Append('"'); |
| 1111 | msg.AppendDetailed(String::cast(name), false); |
| 1112 | msg.Append('"'); |
| 1113 | } else { |
| 1114 | msg.AppendSymbolName(Symbol::cast(name)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1115 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1116 | msg.WriteToLogFile(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1117 | } |
| 1118 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1119 | void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1120 | SharedFunctionInfo* shared, Name* name) { |
| 1121 | PROFILER_LOG(CodeCreateEvent(tag, code, shared, name)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1122 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1123 | if (!is_logging_code_events()) return; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1124 | CALL_LISTENERS(CodeCreateEvent(tag, code, shared, name)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1125 | |
| 1126 | if (!FLAG_log_code || !log_->IsEnabled()) return; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1127 | if (code == AbstractCode::cast( |
| 1128 | isolate_->builtins()->builtin(Builtins::kCompileLazy))) { |
| 1129 | return; |
| 1130 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1131 | |
| 1132 | Log::MessageBuilder msg(log_); |
| 1133 | AppendCodeCreateHeader(&msg, tag, code); |
| 1134 | if (name->IsString()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1135 | base::SmartArrayPointer<char> str = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1136 | String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 1137 | msg.Append("\"%s\"", str.get()); |
| 1138 | } else { |
| 1139 | msg.AppendSymbolName(Symbol::cast(name)); |
| 1140 | } |
| 1141 | msg.Append(','); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1142 | msg.AppendAddress(shared->address()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1143 | msg.Append(",%s", ComputeMarker(shared, code)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1144 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1148 | // Although, it is possible to extract source and line from |
| 1149 | // the SharedFunctionInfo object, we left it to caller |
| 1150 | // to leave logging functions free from heap allocations. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1151 | void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1152 | SharedFunctionInfo* shared, Name* source, int line, |
| 1153 | int column) { |
| 1154 | PROFILER_LOG(CodeCreateEvent(tag, code, shared, source, line, column)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1155 | |
| 1156 | if (!is_logging_code_events()) return; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1157 | CALL_LISTENERS(CodeCreateEvent(tag, code, shared, source, line, column)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1158 | |
| 1159 | if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 1160 | Log::MessageBuilder msg(log_); |
| 1161 | AppendCodeCreateHeader(&msg, tag, code); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1162 | base::SmartArrayPointer<char> name = |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1163 | shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1164 | msg.Append("\"%s ", name.get()); |
| 1165 | if (source->IsString()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1166 | base::SmartArrayPointer<char> sourcestr = String::cast(source)->ToCString( |
| 1167 | DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1168 | msg.Append("%s", sourcestr.get()); |
| 1169 | } else { |
| 1170 | msg.AppendSymbolName(Symbol::cast(source)); |
| 1171 | } |
| 1172 | msg.Append(":%d:%d\",", line, column); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1173 | msg.AppendAddress(shared->address()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1174 | msg.Append(",%s", ComputeMarker(shared, code)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1175 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1178 | void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1179 | int args_count) { |
| 1180 | PROFILER_LOG(CodeCreateEvent(tag, code, args_count)); |
| 1181 | |
| 1182 | if (!is_logging_code_events()) return; |
| 1183 | CALL_LISTENERS(CodeCreateEvent(tag, code, args_count)); |
| 1184 | |
| 1185 | if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 1186 | Log::MessageBuilder msg(log_); |
| 1187 | AppendCodeCreateHeader(&msg, tag, code); |
| 1188 | msg.Append("\"args_count: %d\"", args_count); |
| 1189 | msg.WriteToLogFile(); |
| 1190 | } |
| 1191 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1192 | void Logger::CodeDisableOptEvent(AbstractCode* code, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1193 | SharedFunctionInfo* shared) { |
| 1194 | PROFILER_LOG(CodeDisableOptEvent(code, shared)); |
| 1195 | |
| 1196 | if (!is_logging_code_events()) return; |
| 1197 | CALL_LISTENERS(CodeDisableOptEvent(code, shared)); |
| 1198 | |
| 1199 | if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 1200 | Log::MessageBuilder msg(log_); |
| 1201 | msg.Append("%s,", kLogEventsNames[CODE_DISABLE_OPT_EVENT]); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1202 | base::SmartArrayPointer<char> name = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1203 | shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 1204 | msg.Append("\"%s\",", name.get()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1205 | msg.Append("\"%s\"", GetBailoutReason(shared->disable_optimization_reason())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1206 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1210 | void Logger::CodeMovingGCEvent() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1211 | PROFILER_LOG(CodeMovingGCEvent()); |
| 1212 | |
| 1213 | if (!is_logging_code_events()) return; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1214 | if (!log_->IsEnabled() || !FLAG_ll_prof) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1215 | CALL_LISTENERS(CodeMovingGCEvent()); |
| 1216 | base::OS::SignalCodeMovingGC(); |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1217 | } |
| 1218 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1219 | void Logger::RegExpCodeCreateEvent(AbstractCode* code, String* source) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1220 | PROFILER_LOG(RegExpCodeCreateEvent(code, source)); |
| 1221 | |
| 1222 | if (!is_logging_code_events()) return; |
| 1223 | CALL_LISTENERS(RegExpCodeCreateEvent(code, source)); |
| 1224 | |
| 1225 | if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 1226 | Log::MessageBuilder msg(log_); |
| 1227 | AppendCodeCreateHeader(&msg, REG_EXP_TAG, code); |
| 1228 | msg.Append('"'); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1229 | msg.AppendDetailed(source, false); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1230 | msg.Append('"'); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1231 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1234 | void Logger::CodeMoveEvent(AbstractCode* from, Address to) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1235 | PROFILER_LOG(CodeMoveEvent(from, to)); |
| 1236 | |
| 1237 | if (!is_logging_code_events()) return; |
| 1238 | CALL_LISTENERS(CodeMoveEvent(from, to)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1239 | MoveEventInternal(CODE_MOVE_EVENT, from->address(), to); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1242 | void Logger::CodeLinePosInfoAddPositionEvent(void* jit_handler_data, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1243 | int pc_offset, int position) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1244 | JIT_LOG(AddCodeLinePosInfoEvent(jit_handler_data, |
| 1245 | pc_offset, |
| 1246 | position, |
| 1247 | JitCodeEvent::POSITION)); |
| 1248 | } |
| 1249 | |
| 1250 | |
| 1251 | void Logger::CodeLinePosInfoAddStatementPositionEvent(void* jit_handler_data, |
| 1252 | int pc_offset, |
| 1253 | int position) { |
| 1254 | JIT_LOG(AddCodeLinePosInfoEvent(jit_handler_data, |
| 1255 | pc_offset, |
| 1256 | position, |
| 1257 | JitCodeEvent::STATEMENT_POSITION)); |
| 1258 | } |
| 1259 | |
| 1260 | |
| 1261 | void Logger::CodeStartLinePosInfoRecordEvent(PositionsRecorder* pos_recorder) { |
| 1262 | if (jit_logger_ != NULL) { |
| 1263 | pos_recorder->AttachJITHandlerData(jit_logger_->StartCodePosInfoEvent()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1264 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1265 | } |
| 1266 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1267 | void Logger::CodeEndLinePosInfoRecordEvent(AbstractCode* code, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1268 | void* jit_handler_data) { |
| 1269 | JIT_LOG(EndCodePosInfoEvent(code, jit_handler_data)); |
| 1270 | } |
| 1271 | |
| 1272 | |
| 1273 | void Logger::CodeNameEvent(Address addr, int pos, const char* code_name) { |
| 1274 | if (code_name == NULL) return; // Not a code object. |
| 1275 | Log::MessageBuilder msg(log_); |
| 1276 | msg.Append("%s,%d,", kLogEventsNames[SNAPSHOT_CODE_NAME_EVENT], pos); |
| 1277 | msg.AppendDoubleQuotedString(code_name); |
| 1278 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1282 | void Logger::SharedFunctionInfoMoveEvent(Address from, Address to) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1283 | if (!is_logging_code_events()) return; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1284 | MoveEventInternal(SHARED_FUNC_MOVE_EVENT, from, to); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1288 | void Logger::MoveEventInternal(LogEventsAndTags event, |
| 1289 | Address from, |
| 1290 | Address to) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1291 | if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 1292 | Log::MessageBuilder msg(log_); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1293 | msg.Append("%s,", kLogEventsNames[event]); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1294 | msg.AppendAddress(from); |
| 1295 | msg.Append(','); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1296 | msg.AppendAddress(to); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1297 | msg.WriteToLogFile(); |
| 1298 | } |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1299 | |
| 1300 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1301 | void Logger::ResourceEvent(const char* name, const char* tag) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1302 | if (!log_->IsEnabled() || !FLAG_log) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1303 | Log::MessageBuilder msg(log_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1304 | msg.Append("%s,%s,", name, tag); |
| 1305 | |
| 1306 | uint32_t sec, usec; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1307 | if (base::OS::GetUserTime(&sec, &usec) != -1) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1308 | msg.Append("%d,%d,", sec, usec); |
| 1309 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1310 | msg.Append("%.0f", base::OS::TimeCurrentMillis()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1311 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1315 | void Logger::SuspectReadEvent(Name* name, Object* obj) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1316 | if (!log_->IsEnabled() || !FLAG_log_suspect) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1317 | Log::MessageBuilder msg(log_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1318 | String* class_name = obj->IsJSObject() |
| 1319 | ? JSObject::cast(obj)->class_name() |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1320 | : isolate_->heap()->empty_string(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1321 | msg.Append("suspect-read,"); |
| 1322 | msg.Append(class_name); |
| 1323 | msg.Append(','); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1324 | if (name->IsString()) { |
| 1325 | msg.Append('"'); |
| 1326 | msg.Append(String::cast(name)); |
| 1327 | msg.Append('"'); |
| 1328 | } else { |
| 1329 | msg.AppendSymbolName(Symbol::cast(name)); |
| 1330 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1331 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | |
| 1335 | void Logger::HeapSampleBeginEvent(const char* space, const char* kind) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1336 | if (!log_->IsEnabled() || !FLAG_log_gc) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1337 | Log::MessageBuilder msg(log_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1338 | // Using non-relative system time in order to be able to synchronize with |
| 1339 | // external memory profiling events (e.g. DOM memory size). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1340 | msg.Append("heap-sample-begin,\"%s\",\"%s\",%.0f", space, kind, |
| 1341 | base::OS::TimeCurrentMillis()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1342 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | |
| 1346 | void Logger::HeapSampleEndEvent(const char* space, const char* kind) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1347 | if (!log_->IsEnabled() || !FLAG_log_gc) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1348 | Log::MessageBuilder msg(log_); |
| 1349 | msg.Append("heap-sample-end,\"%s\",\"%s\"", space, kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1350 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | |
| 1354 | void Logger::HeapSampleItemEvent(const char* type, int number, int bytes) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1355 | if (!log_->IsEnabled() || !FLAG_log_gc) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1356 | Log::MessageBuilder msg(log_); |
| 1357 | msg.Append("heap-sample-item,%s,%d,%d", type, number, bytes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1358 | msg.WriteToLogFile(); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1362 | void Logger::DebugTag(const char* call_site_tag) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1363 | if (!log_->IsEnabled() || !FLAG_log) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1364 | Log::MessageBuilder msg(log_); |
| 1365 | msg.Append("debug-tag,%s", call_site_tag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1366 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1367 | } |
| 1368 | |
| 1369 | |
| 1370 | void Logger::DebugEvent(const char* event_type, Vector<uint16_t> parameter) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1371 | if (!log_->IsEnabled() || !FLAG_log) return; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1372 | StringBuilder s(parameter.length() + 1); |
| 1373 | for (int i = 0; i < parameter.length(); ++i) { |
| 1374 | s.AddCharacter(static_cast<char>(parameter[i])); |
| 1375 | } |
| 1376 | char* parameter_string = s.Finalize(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1377 | Log::MessageBuilder msg(log_); |
| 1378 | msg.Append("debug-queue-event,%s,%15.3f,%s", event_type, |
| 1379 | base::OS::TimeCurrentMillis(), parameter_string); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1380 | DeleteArray(parameter_string); |
| 1381 | msg.WriteToLogFile(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1385 | void Logger::TickEvent(TickSample* sample, bool overflow) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1386 | if (!log_->IsEnabled() || !FLAG_prof_cpp) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1387 | Log::MessageBuilder msg(log_); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1388 | msg.Append("%s,", kLogEventsNames[TICK_EVENT]); |
| 1389 | msg.AppendAddress(sample->pc); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1390 | msg.Append(",%d", static_cast<int>(timer_.Elapsed().InMicroseconds())); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1391 | if (sample->has_external_callback) { |
| 1392 | msg.Append(",1,"); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1393 | msg.AppendAddress(sample->external_callback_entry); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1394 | } else { |
| 1395 | msg.Append(",0,"); |
| 1396 | msg.AppendAddress(sample->tos); |
| 1397 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1398 | msg.Append(",%d", static_cast<int>(sample->state)); |
| 1399 | if (overflow) { |
| 1400 | msg.Append(",overflow"); |
| 1401 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1402 | for (unsigned i = 0; i < sample->frames_count; ++i) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1403 | msg.Append(','); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1404 | msg.AppendAddress(sample->stack[i]); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1405 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1406 | msg.WriteToLogFile(); |
| 1407 | } |
| 1408 | |
| 1409 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1410 | void Logger::StopProfiler() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1411 | if (!log_->IsEnabled()) return; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1412 | if (profiler_ != NULL) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1413 | profiler_->pause(); |
| 1414 | is_logging_ = false; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1415 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | |
| 1419 | // This function can be called when Log's mutex is acquired, |
| 1420 | // either from main or Profiler's thread. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1421 | void Logger::LogFailure() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1422 | StopProfiler(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1426 | class EnumerateOptimizedFunctionsVisitor: public OptimizedFunctionVisitor { |
| 1427 | public: |
| 1428 | EnumerateOptimizedFunctionsVisitor(Handle<SharedFunctionInfo>* sfis, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1429 | Handle<AbstractCode>* code_objects, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1430 | int* count) |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1431 | : sfis_(sfis), code_objects_(code_objects), count_(count) {} |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1432 | |
| 1433 | virtual void EnterContext(Context* context) {} |
| 1434 | virtual void LeaveContext(Context* context) {} |
| 1435 | |
| 1436 | virtual void VisitFunction(JSFunction* function) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1437 | SharedFunctionInfo* sfi = SharedFunctionInfo::cast(function->shared()); |
| 1438 | Object* maybe_script = sfi->script(); |
| 1439 | if (maybe_script->IsScript() |
| 1440 | && !Script::cast(maybe_script)->HasValidSource()) return; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1441 | if (sfis_ != NULL) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1442 | sfis_[*count_] = Handle<SharedFunctionInfo>(sfi); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1443 | } |
| 1444 | if (code_objects_ != NULL) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1445 | DCHECK(function->abstract_code()->kind() == |
| 1446 | AbstractCode::OPTIMIZED_FUNCTION); |
| 1447 | code_objects_[*count_] = Handle<AbstractCode>(function->abstract_code()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1448 | } |
| 1449 | *count_ = *count_ + 1; |
| 1450 | } |
| 1451 | |
| 1452 | private: |
| 1453 | Handle<SharedFunctionInfo>* sfis_; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1454 | Handle<AbstractCode>* code_objects_; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1455 | int* count_; |
| 1456 | }; |
| 1457 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1458 | static int EnumerateCompiledFunctions(Heap* heap, |
| 1459 | Handle<SharedFunctionInfo>* sfis, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1460 | Handle<AbstractCode>* code_objects) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1461 | HeapIterator iterator(heap); |
| 1462 | DisallowHeapAllocation no_gc; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1463 | int compiled_funcs_count = 0; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1464 | |
| 1465 | // Iterate the heap to find shared function info objects and record |
| 1466 | // the unoptimized code for them. |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1467 | for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1468 | if (!obj->IsSharedFunctionInfo()) continue; |
| 1469 | SharedFunctionInfo* sfi = SharedFunctionInfo::cast(obj); |
| 1470 | if (sfi->is_compiled() |
| 1471 | && (!sfi->script()->IsScript() |
| 1472 | || Script::cast(sfi->script())->HasValidSource())) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1473 | if (sfis != NULL) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1474 | sfis[compiled_funcs_count] = Handle<SharedFunctionInfo>(sfi); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1475 | } |
| 1476 | if (code_objects != NULL) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1477 | code_objects[compiled_funcs_count] = |
| 1478 | Handle<AbstractCode>(sfi->abstract_code()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1479 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1480 | ++compiled_funcs_count; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1481 | } |
| 1482 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1483 | |
| 1484 | // Iterate all optimized functions in all contexts. |
| 1485 | EnumerateOptimizedFunctionsVisitor visitor(sfis, |
| 1486 | code_objects, |
| 1487 | &compiled_funcs_count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1488 | Deoptimizer::VisitAllOptimizedFunctions(heap->isolate(), &visitor); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1489 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1490 | return compiled_funcs_count; |
| 1491 | } |
| 1492 | |
| 1493 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1494 | void Logger::LogCodeObject(Object* object) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1495 | AbstractCode* code_object = AbstractCode::cast(object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1496 | LogEventsAndTags tag = Logger::STUB_TAG; |
| 1497 | const char* description = "Unknown code from the snapshot"; |
| 1498 | switch (code_object->kind()) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1499 | case AbstractCode::FUNCTION: |
| 1500 | case AbstractCode::INTERPRETED_FUNCTION: |
| 1501 | case AbstractCode::OPTIMIZED_FUNCTION: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1502 | return; // We log this later using LogCompiledFunctions. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1503 | case AbstractCode::BYTECODE_HANDLER: |
| 1504 | return; // We log it later by walking the dispatch table. |
| 1505 | case AbstractCode::BINARY_OP_IC: // fall through |
| 1506 | case AbstractCode::COMPARE_IC: // fall through |
| 1507 | case AbstractCode::TO_BOOLEAN_IC: // fall through |
| 1508 | |
| 1509 | case AbstractCode::STUB: |
| 1510 | description = |
| 1511 | CodeStub::MajorName(CodeStub::GetMajorKey(code_object->GetCode())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1512 | if (description == NULL) |
| 1513 | description = "A stub from the snapshot"; |
| 1514 | tag = Logger::STUB_TAG; |
| 1515 | break; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1516 | case AbstractCode::REGEXP: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1517 | description = "Regular expression code"; |
| 1518 | tag = Logger::REG_EXP_TAG; |
| 1519 | break; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1520 | case AbstractCode::BUILTIN: |
| 1521 | description = |
| 1522 | isolate_->builtins()->name(code_object->GetCode()->builtin_index()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1523 | tag = Logger::BUILTIN_TAG; |
| 1524 | break; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1525 | case AbstractCode::HANDLER: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1526 | description = "An IC handler from the snapshot"; |
| 1527 | tag = Logger::HANDLER_TAG; |
| 1528 | break; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1529 | case AbstractCode::KEYED_LOAD_IC: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1530 | description = "A keyed load IC from the snapshot"; |
| 1531 | tag = Logger::KEYED_LOAD_IC_TAG; |
| 1532 | break; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1533 | case AbstractCode::LOAD_IC: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1534 | description = "A load IC from the snapshot"; |
| 1535 | tag = Logger::LOAD_IC_TAG; |
| 1536 | break; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1537 | case AbstractCode::CALL_IC: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1538 | description = "A call IC from the snapshot"; |
| 1539 | tag = Logger::CALL_IC_TAG; |
| 1540 | break; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1541 | case AbstractCode::STORE_IC: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1542 | description = "A store IC from the snapshot"; |
| 1543 | tag = Logger::STORE_IC_TAG; |
| 1544 | break; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1545 | case AbstractCode::KEYED_STORE_IC: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1546 | description = "A keyed store IC from the snapshot"; |
| 1547 | tag = Logger::KEYED_STORE_IC_TAG; |
| 1548 | break; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1549 | case AbstractCode::WASM_FUNCTION: |
| 1550 | description = "A Wasm function"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1551 | tag = Logger::STUB_TAG; |
| 1552 | break; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1553 | case AbstractCode::JS_TO_WASM_FUNCTION: |
| 1554 | description = "A JavaScript to Wasm adapter"; |
| 1555 | tag = Logger::STUB_TAG; |
| 1556 | break; |
| 1557 | case AbstractCode::WASM_TO_JS_FUNCTION: |
| 1558 | description = "A Wasm to JavaScript adapter"; |
| 1559 | tag = Logger::STUB_TAG; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1560 | break; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1561 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1562 | PROFILE(isolate_, CodeCreateEvent(tag, code_object, description)); |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1566 | void Logger::LogCodeObjects() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1567 | Heap* heap = isolate_->heap(); |
| 1568 | heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1569 | "Logger::LogCodeObjects"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1570 | HeapIterator iterator(heap); |
| 1571 | DisallowHeapAllocation no_gc; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1572 | for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
| 1573 | if (obj->IsCode()) LogCodeObject(obj); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1574 | if (obj->IsBytecodeArray()) LogCodeObject(obj); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1575 | } |
| 1576 | } |
| 1577 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1578 | void Logger::LogBytecodeHandlers() { |
| 1579 | if (!FLAG_ignition) return; |
| 1580 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1581 | const interpreter::OperandScale kOperandScales[] = { |
| 1582 | #define VALUE(Name, _) interpreter::OperandScale::k##Name, |
| 1583 | OPERAND_SCALE_LIST(VALUE) |
| 1584 | #undef VALUE |
| 1585 | }; |
| 1586 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1587 | const int last_index = static_cast<int>(interpreter::Bytecode::kLast); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1588 | interpreter::Interpreter* interpreter = isolate_->interpreter(); |
| 1589 | for (auto operand_scale : kOperandScales) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1590 | for (int index = 0; index <= last_index; ++index) { |
| 1591 | interpreter::Bytecode bytecode = interpreter::Bytecodes::FromByte(index); |
| 1592 | if (interpreter::Bytecodes::BytecodeHasHandler(bytecode, operand_scale)) { |
| 1593 | Code* code = interpreter->GetBytecodeHandler(bytecode, operand_scale); |
| 1594 | std::string bytecode_name = |
| 1595 | interpreter::Bytecodes::ToString(bytecode, operand_scale); |
| 1596 | CodeCreateEvent(Logger::BYTECODE_HANDLER_TAG, AbstractCode::cast(code), |
| 1597 | bytecode_name.c_str()); |
| 1598 | } |
| 1599 | } |
| 1600 | } |
| 1601 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1602 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1603 | void Logger::LogExistingFunction(Handle<SharedFunctionInfo> shared, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1604 | Handle<AbstractCode> code) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1605 | Handle<String> func_name(shared->DebugName()); |
| 1606 | if (shared->script()->IsScript()) { |
| 1607 | Handle<Script> script(Script::cast(shared->script())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1608 | int line_num = Script::GetLineNumber(script, shared->start_position()) + 1; |
| 1609 | int column_num = |
| 1610 | Script::GetColumnNumber(script, shared->start_position()) + 1; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1611 | if (script->name()->IsString()) { |
| 1612 | Handle<String> script_name(String::cast(script->name())); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1613 | if (line_num > 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1614 | PROFILE(isolate_, |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1615 | CodeCreateEvent( |
| 1616 | Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script), |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1617 | *code, *shared, *script_name, line_num, column_num)); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1618 | } else { |
| 1619 | // Can't distinguish eval and script here, so always use Script. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1620 | PROFILE(isolate_, CodeCreateEvent(Logger::ToNativeByScript( |
| 1621 | Logger::SCRIPT_TAG, *script), |
| 1622 | *code, *shared, *script_name)); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1623 | } |
| 1624 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1625 | PROFILE(isolate_, |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1626 | CodeCreateEvent( |
| 1627 | Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script), |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1628 | *code, *shared, isolate_->heap()->empty_string(), line_num, |
| 1629 | column_num)); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1630 | } |
| 1631 | } else if (shared->IsApiFunction()) { |
| 1632 | // API function. |
| 1633 | FunctionTemplateInfo* fun_data = shared->get_api_func_data(); |
| 1634 | Object* raw_call_data = fun_data->call_code(); |
| 1635 | if (!raw_call_data->IsUndefined()) { |
| 1636 | CallHandlerInfo* call_data = CallHandlerInfo::cast(raw_call_data); |
| 1637 | Object* callback_obj = call_data->callback(); |
| 1638 | Address entry_point = v8::ToCData<Address>(callback_obj); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1639 | #if USES_FUNCTION_DESCRIPTORS |
| 1640 | entry_point = *FUNCTION_ENTRYPOINT_ADDRESS(entry_point); |
| 1641 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1642 | PROFILE(isolate_, CallbackEvent(*func_name, entry_point)); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1643 | } |
| 1644 | } else { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1645 | PROFILE(isolate_, CodeCreateEvent(Logger::LAZY_COMPILE_TAG, *code, *shared, |
| 1646 | *func_name)); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1647 | } |
| 1648 | } |
| 1649 | |
| 1650 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1651 | void Logger::LogCompiledFunctions() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1652 | Heap* heap = isolate_->heap(); |
| 1653 | heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1654 | "Logger::LogCompiledFunctions"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1655 | HandleScope scope(isolate_); |
| 1656 | const int compiled_funcs_count = EnumerateCompiledFunctions(heap, NULL, NULL); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1657 | ScopedVector< Handle<SharedFunctionInfo> > sfis(compiled_funcs_count); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1658 | ScopedVector<Handle<AbstractCode> > code_objects(compiled_funcs_count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1659 | EnumerateCompiledFunctions(heap, sfis.start(), code_objects.start()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1660 | |
| 1661 | // During iteration, there can be heap allocation due to |
| 1662 | // GetScriptLineNumber call. |
| 1663 | for (int i = 0; i < compiled_funcs_count; ++i) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1664 | if (code_objects[i].is_identical_to(isolate_->builtins()->CompileLazy())) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1665 | continue; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1666 | LogExistingFunction(sfis[i], code_objects[i]); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1667 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1668 | } |
| 1669 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1670 | |
| 1671 | void Logger::LogAccessorCallbacks() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1672 | Heap* heap = isolate_->heap(); |
| 1673 | heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1674 | "Logger::LogAccessorCallbacks"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1675 | HeapIterator iterator(heap); |
| 1676 | DisallowHeapAllocation no_gc; |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1677 | for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1678 | if (!obj->IsAccessorInfo()) continue; |
| 1679 | AccessorInfo* ai = AccessorInfo::cast(obj); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1680 | if (!ai->name()->IsName()) continue; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1681 | Address getter_entry = v8::ToCData<Address>(ai->getter()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1682 | Name* name = Name::cast(ai->name()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1683 | if (getter_entry != 0) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1684 | #if USES_FUNCTION_DESCRIPTORS |
| 1685 | getter_entry = *FUNCTION_ENTRYPOINT_ADDRESS(getter_entry); |
| 1686 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1687 | PROFILE(isolate_, GetterCallbackEvent(name, getter_entry)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1688 | } |
| 1689 | Address setter_entry = v8::ToCData<Address>(ai->setter()); |
| 1690 | if (setter_entry != 0) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1691 | #if USES_FUNCTION_DESCRIPTORS |
| 1692 | setter_entry = *FUNCTION_ENTRYPOINT_ADDRESS(setter_entry); |
| 1693 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1694 | PROFILE(isolate_, SetterCallbackEvent(name, setter_entry)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1695 | } |
| 1696 | } |
| 1697 | } |
| 1698 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1699 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1700 | static void AddIsolateIdIfNeeded(std::ostream& os, // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1701 | Isolate* isolate) { |
| 1702 | if (FLAG_logfile_per_isolate) os << "isolate-" << isolate << "-"; |
| 1703 | } |
| 1704 | |
| 1705 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1706 | static void PrepareLogFileName(std::ostream& os, // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1707 | Isolate* isolate, const char* file_name) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1708 | int dir_separator_count = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1709 | for (const char* p = file_name; *p; p++) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1710 | if (base::OS::isDirectorySeparator(*p)) dir_separator_count++; |
| 1711 | } |
| 1712 | |
| 1713 | for (const char* p = file_name; *p; p++) { |
| 1714 | if (dir_separator_count == 0) { |
| 1715 | AddIsolateIdIfNeeded(os, isolate); |
| 1716 | dir_separator_count--; |
| 1717 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1718 | if (*p == '%') { |
| 1719 | p++; |
| 1720 | switch (*p) { |
| 1721 | case '\0': |
| 1722 | // If there's a % at the end of the string we back up |
| 1723 | // one character so we can escape the loop properly. |
| 1724 | p--; |
| 1725 | break; |
| 1726 | case 'p': |
| 1727 | os << base::OS::GetCurrentProcessId(); |
| 1728 | break; |
| 1729 | case 't': |
| 1730 | // %t expands to the current time in milliseconds. |
| 1731 | os << static_cast<int64_t>(base::OS::TimeCurrentMillis()); |
| 1732 | break; |
| 1733 | case '%': |
| 1734 | // %% expands (contracts really) to %. |
| 1735 | os << '%'; |
| 1736 | break; |
| 1737 | default: |
| 1738 | // All other %'s expand to themselves. |
| 1739 | os << '%' << *p; |
| 1740 | break; |
| 1741 | } |
| 1742 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1743 | if (base::OS::isDirectorySeparator(*p)) dir_separator_count--; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1744 | os << *p; |
| 1745 | } |
| 1746 | } |
| 1747 | } |
| 1748 | |
| 1749 | |
| 1750 | bool Logger::SetUp(Isolate* isolate) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1751 | // Tests and EnsureInitialize() can call this twice in a row. It's harmless. |
| 1752 | if (is_initialized_) return true; |
| 1753 | is_initialized_ = true; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1754 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1755 | std::ostringstream log_file_name; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1756 | PrepareLogFileName(log_file_name, isolate, FLAG_logfile); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1757 | log_->Initialize(log_file_name.str().c_str()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1758 | |
| 1759 | |
| 1760 | if (FLAG_perf_basic_prof) { |
| 1761 | perf_basic_logger_ = new PerfBasicLogger(); |
| 1762 | addCodeEventListener(perf_basic_logger_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1763 | } |
| 1764 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1765 | if (FLAG_perf_prof) { |
| 1766 | perf_jit_logger_ = new PerfJitLogger(); |
| 1767 | addCodeEventListener(perf_jit_logger_); |
| 1768 | } |
| 1769 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1770 | if (FLAG_ll_prof) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1771 | ll_logger_ = new LowLevelLogger(log_file_name.str().c_str()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1772 | addCodeEventListener(ll_logger_); |
| 1773 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1774 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1775 | ticker_ = new Ticker(isolate, kSamplingIntervalMs); |
| 1776 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1777 | if (Log::InitLogAtStart()) { |
| 1778 | is_logging_ = true; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1779 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1780 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1781 | if (FLAG_log_internal_timer_events || FLAG_prof_cpp) timer_.Start(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1782 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1783 | if (FLAG_prof_cpp) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1784 | profiler_ = new Profiler(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1785 | is_logging_ = true; |
| 1786 | profiler_->Engage(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1789 | return true; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1793 | void Logger::SetCodeEventHandler(uint32_t options, |
| 1794 | JitCodeEventHandler event_handler) { |
| 1795 | if (jit_logger_) { |
| 1796 | removeCodeEventListener(jit_logger_); |
| 1797 | delete jit_logger_; |
| 1798 | jit_logger_ = NULL; |
| 1799 | } |
| 1800 | |
| 1801 | if (event_handler) { |
| 1802 | jit_logger_ = new JitLogger(event_handler); |
| 1803 | addCodeEventListener(jit_logger_); |
| 1804 | if (options & kJitCodeEventEnumExisting) { |
| 1805 | HandleScope scope(isolate_); |
| 1806 | LogCodeObjects(); |
| 1807 | LogCompiledFunctions(); |
| 1808 | } |
| 1809 | } |
| 1810 | } |
| 1811 | |
| 1812 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1813 | Sampler* Logger::sampler() { |
| 1814 | return ticker_; |
| 1815 | } |
| 1816 | |
| 1817 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1818 | FILE* Logger::TearDown() { |
| 1819 | if (!is_initialized_) return NULL; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1820 | is_initialized_ = false; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1821 | |
| 1822 | // Stop the profiler before closing the file. |
| 1823 | if (profiler_ != NULL) { |
| 1824 | profiler_->Disengage(); |
| 1825 | delete profiler_; |
| 1826 | profiler_ = NULL; |
| 1827 | } |
| 1828 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1829 | delete ticker_; |
| 1830 | ticker_ = NULL; |
| 1831 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1832 | if (perf_basic_logger_) { |
| 1833 | removeCodeEventListener(perf_basic_logger_); |
| 1834 | delete perf_basic_logger_; |
| 1835 | perf_basic_logger_ = NULL; |
| 1836 | } |
| 1837 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1838 | if (perf_jit_logger_) { |
| 1839 | removeCodeEventListener(perf_jit_logger_); |
| 1840 | delete perf_jit_logger_; |
| 1841 | perf_jit_logger_ = NULL; |
| 1842 | } |
| 1843 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1844 | if (ll_logger_) { |
| 1845 | removeCodeEventListener(ll_logger_); |
| 1846 | delete ll_logger_; |
| 1847 | ll_logger_ = NULL; |
| 1848 | } |
| 1849 | |
| 1850 | if (jit_logger_) { |
| 1851 | removeCodeEventListener(jit_logger_); |
| 1852 | delete jit_logger_; |
| 1853 | jit_logger_ = NULL; |
| 1854 | } |
| 1855 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1856 | return log_->Close(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1857 | } |
| 1858 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1859 | } // namespace internal |
| 1860 | } // namespace v8 |