Chromium Code Reviews| Index: src/log.cc |
| diff --git a/src/log.cc b/src/log.cc |
| index afd8f7de77ce55bd28b085611b5b13b795936eb1..2eaa3472a7e076a1b99277ee13f89eaefc513e10 100644 |
| --- a/src/log.cc |
| +++ b/src/log.cc |
| @@ -447,6 +447,7 @@ Logger::Logger(Isolate* isolate) |
| log_(new Log(this)), |
| ll_logger_(NULL), |
| jit_logger_(NULL), |
| + code_logger_(NULL), |
| name_buffer_(new NameBuffer), |
| address_to_name_map_(NULL), |
| is_initialized_(false), |
| @@ -942,13 +943,63 @@ void Logger::DeleteEventStatic(const char* name, void* object) { |
| } |
| -void Logger::CallbackEventInternal(const char* prefix, Name* name, |
| - Address entry_point) { |
| - if (!log_->IsEnabled() || !FLAG_log_code) return; |
| +class CodeEventLogger { |
|
yurys
2013/07/18 18:05:05
I'd rather extract EventDispatcher into a separate
|
| + public: |
| + explicit CodeEventLogger(Log* log) : log_(log) { } |
| + void CallbackEvent(const char* prefix, Name* name, Address entry_point); |
| + void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| + Code* code, |
| + const char* comment); |
| + void CodeCreateEvent(Logger::LogEventsAndTags tag, Code* code, Name* name); |
| + void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| + Code* code, |
| + SharedFunctionInfo* shared, |
| + CompilationInfo* info, |
| + Name* name); |
| + void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| + Code* code, |
| + SharedFunctionInfo* shared, |
| + CompilationInfo* info, |
| + Name* source, int line); |
| + void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| + Code* code, |
| + int args_count); |
| + void RegExpCodeCreateEvent(Code* code, String* source); |
| + void CodeMoveEvent(Logger::LogEventsAndTags event, Address from, Address to); |
| + void CodeDeleteEvent(Logger::LogEventsAndTags event, Address from); |
| + |
| + private: |
| + class CodeCreateMessageBuilder : public Log::MessageBuilder { |
| + public: |
| + CodeCreateMessageBuilder(Log* log, |
| + Logger::LogEventsAndTags tag, |
| + Code* code) |
| + : Log::MessageBuilder(log) { |
| + Append("%s,%s,%d,", |
| + kLogEventsNames[Logger::CODE_CREATION_EVENT], |
| + kLogEventsNames[tag], |
| + code->kind()); |
| + AppendAddress(code->address()); |
| + Append(",%d,", code->ExecutableSize()); |
| + } |
| + }; |
| + |
| + Log* log_; |
| +}; |
| + |
| + |
| +#define CODE_LOG(Call)\ |
| + if (log_->IsEnabled() && code_logger_)\ |
| + code_logger_->Call; |
| + |
| + |
| +void CodeEventLogger::CallbackEvent(const char* prefix, |
| + Name* name, |
| + Address entry_point) { |
| Log::MessageBuilder msg(log_); |
| msg.Append("%s,%s,-2,", |
| - kLogEventsNames[CODE_CREATION_EVENT], |
| - kLogEventsNames[CALLBACK_TAG]); |
| + kLogEventsNames[Logger::CODE_CREATION_EVENT], |
| + kLogEventsNames[Logger::CALLBACK_TAG]); |
| msg.AppendAddress(entry_point); |
| if (name->IsString()) { |
| SmartArrayPointer<char> str = |
| @@ -970,20 +1021,17 @@ void Logger::CallbackEventInternal(const char* prefix, Name* name, |
| void Logger::CallbackEvent(Name* name, Address entry_point) { |
| - if (!log_->IsEnabled() || !FLAG_log_code) return; |
| - CallbackEventInternal("", name, entry_point); |
| + CODE_LOG(CallbackEvent("", name, entry_point)); |
| } |
| void Logger::GetterCallbackEvent(Name* name, Address entry_point) { |
| - if (!log_->IsEnabled() || !FLAG_log_code) return; |
| - CallbackEventInternal("get ", name, entry_point); |
| + CODE_LOG(CallbackEvent("get ", name, entry_point)); |
| } |
| void Logger::SetterCallbackEvent(Name* name, Address entry_point) { |
| - if (!log_->IsEnabled() || !FLAG_log_code) return; |
| - CallbackEventInternal("set ", name, entry_point); |
| + CODE_LOG(CallbackEvent("set ", name, entry_point)); |
| } |
| @@ -1006,9 +1054,9 @@ void Logger::AppendName(Name* name) { |
| void Logger::InitNameBuffer(LogEventsAndTags tag) { |
| - name_buffer_->Reset(); |
| - name_buffer_->AppendBytes(kLogEventsNames[tag]); |
| - name_buffer_->AppendByte(':'); |
| + name_buffer_->Reset(); |
| + name_buffer_->AppendBytes(kLogEventsNames[tag]); |
| + name_buffer_->AppendByte(':'); |
| } |
| @@ -1025,19 +1073,6 @@ void Logger::LogRecordedBuffer(Code* code, SharedFunctionInfo* shared) { |
| } |
| -static void AppendCodeCreateHeader(Log::MessageBuilder* msg, |
| - Logger::LogEventsAndTags tag, |
| - Code* code) { |
| - ASSERT(msg); |
| - msg->Append("%s,%s,%d,", |
| - kLogEventsNames[Logger::CODE_CREATION_EVENT], |
| - kLogEventsNames[tag], |
| - code->kind()); |
| - msg->AppendAddress(code->address()); |
| - msg->Append(",%d,", code->ExecutableSize()); |
| -} |
| - |
| - |
| void Logger::CodeCreateEvent(LogEventsAndTags tag, |
| Code* code, |
| const char* comment) { |
| @@ -1047,10 +1082,14 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag, |
| name_buffer_->AppendBytes(comment); |
| LogRecordedBuffer(code, NULL); |
| } |
| + CODE_LOG(CodeCreateEvent(tag, code, comment)); |
| +} |
| - if (!FLAG_log_code || !log_->IsEnabled()) return; |
| - Log::MessageBuilder msg(log_); |
| - AppendCodeCreateHeader(&msg, tag, code); |
| + |
| +void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
| + Code* code, |
| + const char* comment) { |
| + CodeCreateMessageBuilder msg(log_, tag, code); |
| msg.AppendDoubleQuotedString(comment); |
| msg.Append('\n'); |
| msg.WriteToLogFile(); |
| @@ -1066,10 +1105,14 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag, |
| AppendName(name); |
| LogRecordedBuffer(code, NULL); |
| } |
| + CODE_LOG(CodeCreateEvent(tag, code, name)); |
| +} |
| - if (!FLAG_log_code || !log_->IsEnabled()) return; |
| - Log::MessageBuilder msg(log_); |
| - AppendCodeCreateHeader(&msg, tag, code); |
| + |
| +void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
| + Code* code, |
| + Name* name) { |
| + CodeCreateMessageBuilder msg(log_, tag, code); |
| if (name->IsString()) { |
| msg.Append('"'); |
| msg.AppendDetailed(String::cast(name), false); |
| @@ -1105,13 +1148,17 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag, |
| LogRecordedBuffer(code, shared); |
| } |
| - if (!FLAG_log_code || !log_->IsEnabled()) return; |
| - if (code == isolate_->builtins()->builtin( |
| - Builtins::kLazyCompile)) |
| - return; |
| + if (code == isolate_->builtins()->builtin(Builtins::kLazyCompile)) return; |
| + CODE_LOG(CodeCreateEvent(tag, code, shared, info, name)); |
| +} |
| - Log::MessageBuilder msg(log_); |
| - AppendCodeCreateHeader(&msg, tag, code); |
| + |
| +void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
| + Code* code, |
| + SharedFunctionInfo* shared, |
| + CompilationInfo* info, |
| + Name* name) { |
| + CodeCreateMessageBuilder msg(log_, tag, code); |
| if (name->IsString()) { |
| SmartArrayPointer<char> str = |
| String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| @@ -1153,9 +1200,17 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag, |
| LogRecordedBuffer(code, shared); |
| } |
| - if (!FLAG_log_code || !log_->IsEnabled()) return; |
| - Log::MessageBuilder msg(log_); |
| - AppendCodeCreateHeader(&msg, tag, code); |
| + CODE_LOG(CodeCreateEvent(tag, code, shared, info, source, line)); |
| +} |
| + |
| + |
| +void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
| + Code* code, |
| + SharedFunctionInfo* shared, |
| + CompilationInfo* info, |
| + Name* source, |
| + int line) { |
| + CodeCreateMessageBuilder msg(log_, tag, code); |
| SmartArrayPointer<char> name = |
| shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| msg.Append("\"%s ", *name); |
| @@ -1181,10 +1236,14 @@ void Logger::CodeCreateEvent(LogEventsAndTags tag, Code* code, int args_count) { |
| name_buffer_->AppendInt(args_count); |
| LogRecordedBuffer(code, NULL); |
| } |
| + CODE_LOG(CodeCreateEvent(tag, code, args_count)); |
| +} |
| - if (!FLAG_log_code || !log_->IsEnabled()) return; |
| - Log::MessageBuilder msg(log_); |
| - AppendCodeCreateHeader(&msg, tag, code); |
| + |
| +void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, |
| + Code* code, |
| + int args_count) { |
| + CodeCreateMessageBuilder msg(log_, tag, code); |
| msg.Append("\"args_count: %d\"", args_count); |
| msg.Append('\n'); |
| msg.WriteToLogFile(); |
| @@ -1205,10 +1264,12 @@ void Logger::RegExpCodeCreateEvent(Code* code, String* source) { |
| name_buffer_->AppendString(source); |
| LogRecordedBuffer(code, NULL); |
| } |
| + CODE_LOG(RegExpCodeCreateEvent(code, source)); |
| +} |
| - if (!FLAG_log_code || !log_->IsEnabled()) return; |
| - Log::MessageBuilder msg(log_); |
| - AppendCodeCreateHeader(&msg, REG_EXP_TAG, code); |
| + |
| +void CodeEventLogger::RegExpCodeCreateEvent(Code* code, String* source) { |
| + CodeCreateMessageBuilder msg(log_, Logger::REG_EXP_TAG, code); |
| msg.Append('"'); |
| msg.AppendDetailed(source, false); |
| msg.Append('"'); |
| @@ -1224,7 +1285,7 @@ void Logger::CodeMoveEvent(Address from, Address to) { |
| if (Serializer::enabled() && address_to_name_map_ != NULL) { |
| address_to_name_map_->Move(from, to); |
| } |
| - MoveEventInternal(CODE_MOVE_EVENT, from, to); |
| + CODE_LOG(CodeMoveEvent(CODE_MOVE_EVENT, from, to)); |
| } |
| @@ -1235,7 +1296,7 @@ void Logger::CodeDeleteEvent(Address from) { |
| if (Serializer::enabled() && address_to_name_map_ != NULL) { |
| address_to_name_map_->Remove(from); |
| } |
| - DeleteEventInternal(CODE_DELETE_EVENT, from); |
| + CODE_LOG(CodeDeleteEvent(CODE_DELETE_EVENT, from)); |
| } |
| void Logger::CodeLinePosInfoAddPositionEvent(void* jit_handler_data, |
| @@ -1292,14 +1353,13 @@ void Logger::SnapshotPositionEvent(Address addr, int pos) { |
| void Logger::SharedFunctionInfoMoveEvent(Address from, Address to) { |
| - MoveEventInternal(SHARED_FUNC_MOVE_EVENT, from, to); |
| + CODE_LOG(CodeMoveEvent(SHARED_FUNC_MOVE_EVENT, from, to)); |
| } |
| -void Logger::MoveEventInternal(LogEventsAndTags event, |
| - Address from, |
| - Address to) { |
| - if (!log_->IsEnabled() || !FLAG_log_code) return; |
| +void CodeEventLogger::CodeMoveEvent(Logger::LogEventsAndTags event, |
| + Address from, |
| + Address to) { |
| Log::MessageBuilder msg(log_); |
| msg.Append("%s,", kLogEventsNames[event]); |
| msg.AppendAddress(from); |
| @@ -1310,8 +1370,8 @@ void Logger::MoveEventInternal(LogEventsAndTags event, |
| } |
| -void Logger::DeleteEventInternal(LogEventsAndTags event, Address from) { |
| - if (!log_->IsEnabled() || !FLAG_log_code) return; |
| +void CodeEventLogger::CodeDeleteEvent(Logger::LogEventsAndTags event, |
| + Address from) { |
| Log::MessageBuilder msg(log_); |
| msg.Append("%s,", kLogEventsNames[event]); |
| msg.AppendAddress(from); |
| @@ -1911,6 +1971,10 @@ bool Logger::SetUp(Isolate* isolate) { |
| if (FLAG_log_internal_timer_events || FLAG_prof) epoch_ = OS::Ticks(); |
| + if (FLAG_log_code) { |
| + code_logger_ = new CodeEventLogger(log_); |
| + } |
| + |
| return true; |
| } |
| @@ -1963,6 +2027,11 @@ FILE* Logger::TearDown() { |
| jit_logger_ = NULL; |
| } |
| + if (code_logger_) { |
| + delete code_logger_; |
| + code_logger_ = NULL; |
| + } |
| + |
| return log_->Close(); |
| } |