OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/log.h" | 5 #include "src/log.h" |
6 | 6 |
7 #include <cstdarg> | 7 #include <cstdarg> |
8 #include <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "src/profiler/cpu-profiler-inl.h" | 24 #include "src/profiler/cpu-profiler-inl.h" |
25 #include "src/runtime-profiler.h" | 25 #include "src/runtime-profiler.h" |
26 #include "src/string-stream.h" | 26 #include "src/string-stream.h" |
27 #include "src/vm-state-inl.h" | 27 #include "src/vm-state-inl.h" |
28 | 28 |
29 namespace v8 { | 29 namespace v8 { |
30 namespace internal { | 30 namespace internal { |
31 | 31 |
32 | 32 |
33 #define DECLARE_EVENT(ignore1, name) name, | 33 #define DECLARE_EVENT(ignore1, name) name, |
34 static const char* const kLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = { | 34 static const char* kLogEventsNames[CodeEventListener::NUMBER_OF_LOG_EVENTS] = { |
35 LOG_EVENTS_AND_TAGS_LIST(DECLARE_EVENT) | 35 LOG_EVENTS_AND_TAGS_LIST(DECLARE_EVENT)}; |
36 }; | |
37 #undef DECLARE_EVENT | 36 #undef DECLARE_EVENT |
38 | 37 |
39 | |
40 #define CALL_LISTENERS(Call) \ | |
41 for (int i = 0; i < listeners_.length(); ++i) { \ | |
42 listeners_[i]->Call; \ | |
43 } | |
44 | |
45 #define PROFILER_LOG(Call) \ | |
46 if (isolate_->is_profiling()) { \ | |
47 isolate_->cpu_profiler()->Call; \ | |
48 } else { \ | |
49 } | |
50 | |
51 static const char* ComputeMarker(SharedFunctionInfo* shared, | 38 static const char* ComputeMarker(SharedFunctionInfo* shared, |
52 AbstractCode* code) { | 39 AbstractCode* code) { |
53 switch (code->kind()) { | 40 switch (code->kind()) { |
54 case AbstractCode::FUNCTION: | 41 case AbstractCode::FUNCTION: |
55 case AbstractCode::INTERPRETED_FUNCTION: | 42 case AbstractCode::INTERPRETED_FUNCTION: |
56 return shared->optimization_disabled() ? "" : "~"; | 43 return shared->optimization_disabled() ? "" : "~"; |
57 case AbstractCode::OPTIMIZED_FUNCTION: | 44 case AbstractCode::OPTIMIZED_FUNCTION: |
58 return "*"; | 45 return "*"; |
59 default: | 46 default: |
60 return ""; | 47 return ""; |
61 } | 48 } |
62 } | 49 } |
63 | 50 |
64 | 51 |
65 class CodeEventLogger::NameBuffer { | 52 class CodeEventLogger::NameBuffer { |
66 public: | 53 public: |
67 NameBuffer() { Reset(); } | 54 NameBuffer() { Reset(); } |
68 | 55 |
69 void Reset() { | 56 void Reset() { |
70 utf8_pos_ = 0; | 57 utf8_pos_ = 0; |
71 } | 58 } |
72 | 59 |
73 void Init(Logger::LogEventsAndTags tag) { | 60 void Init(CodeEventListener::LogEventsAndTags tag) { |
74 Reset(); | 61 Reset(); |
75 AppendBytes(kLogEventsNames[tag]); | 62 AppendBytes(kLogEventsNames[tag]); |
76 AppendByte(':'); | 63 AppendByte(':'); |
77 } | 64 } |
78 | 65 |
79 void AppendName(Name* name) { | 66 void AppendName(Name* name) { |
80 if (name->IsString()) { | 67 if (name->IsString()) { |
81 AppendString(String::cast(name)); | 68 AppendString(String::cast(name)); |
82 } else { | 69 } else { |
83 Symbol* symbol = Symbol::cast(name); | 70 Symbol* symbol = Symbol::cast(name); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 int utf8_pos_; | 144 int utf8_pos_; |
158 char utf8_buffer_[kUtf8BufferSize]; | 145 char utf8_buffer_[kUtf8BufferSize]; |
159 uc16 utf16_buffer[kUtf16BufferSize]; | 146 uc16 utf16_buffer[kUtf16BufferSize]; |
160 }; | 147 }; |
161 | 148 |
162 | 149 |
163 CodeEventLogger::CodeEventLogger() : name_buffer_(new NameBuffer) { } | 150 CodeEventLogger::CodeEventLogger() : name_buffer_(new NameBuffer) { } |
164 | 151 |
165 CodeEventLogger::~CodeEventLogger() { delete name_buffer_; } | 152 CodeEventLogger::~CodeEventLogger() { delete name_buffer_; } |
166 | 153 |
167 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, | 154 void CodeEventLogger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
168 AbstractCode* code, const char* comment) { | 155 AbstractCode* code, const char* comment) { |
169 name_buffer_->Init(tag); | 156 name_buffer_->Init(tag); |
170 name_buffer_->AppendBytes(comment); | 157 name_buffer_->AppendBytes(comment); |
171 LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); | 158 LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); |
172 } | 159 } |
173 | 160 |
174 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, | 161 void CodeEventLogger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
175 AbstractCode* code, Name* name) { | 162 AbstractCode* code, Name* name) { |
176 name_buffer_->Init(tag); | 163 name_buffer_->Init(tag); |
177 name_buffer_->AppendName(name); | 164 name_buffer_->AppendName(name); |
178 LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); | 165 LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); |
179 } | 166 } |
180 | 167 |
181 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, | 168 void CodeEventLogger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
182 AbstractCode* code, | 169 AbstractCode* code, |
183 SharedFunctionInfo* shared, Name* name) { | 170 SharedFunctionInfo* shared, Name* name) { |
184 name_buffer_->Init(tag); | 171 name_buffer_->Init(tag); |
185 name_buffer_->AppendBytes(ComputeMarker(shared, code)); | 172 name_buffer_->AppendBytes(ComputeMarker(shared, code)); |
186 name_buffer_->AppendName(name); | 173 name_buffer_->AppendName(name); |
187 LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size()); | 174 LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size()); |
188 } | 175 } |
189 | 176 |
190 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, | 177 void CodeEventLogger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
191 AbstractCode* code, | 178 AbstractCode* code, |
192 SharedFunctionInfo* shared, Name* source, | 179 SharedFunctionInfo* shared, Name* source, |
193 int line, int column) { | 180 int line, int column) { |
194 name_buffer_->Init(tag); | 181 name_buffer_->Init(tag); |
195 name_buffer_->AppendBytes(ComputeMarker(shared, code)); | 182 name_buffer_->AppendBytes(ComputeMarker(shared, code)); |
196 name_buffer_->AppendString(shared->DebugName()); | 183 name_buffer_->AppendString(shared->DebugName()); |
197 name_buffer_->AppendByte(' '); | 184 name_buffer_->AppendByte(' '); |
198 if (source->IsString()) { | 185 if (source->IsString()) { |
199 name_buffer_->AppendString(String::cast(source)); | 186 name_buffer_->AppendString(String::cast(source)); |
200 } else { | 187 } else { |
201 name_buffer_->AppendBytes("symbol(hash "); | 188 name_buffer_->AppendBytes("symbol(hash "); |
202 name_buffer_->AppendHex(Name::cast(source)->Hash()); | 189 name_buffer_->AppendHex(Name::cast(source)->Hash()); |
203 name_buffer_->AppendByte(')'); | 190 name_buffer_->AppendByte(')'); |
204 } | 191 } |
205 name_buffer_->AppendByte(':'); | 192 name_buffer_->AppendByte(':'); |
206 name_buffer_->AppendInt(line); | 193 name_buffer_->AppendInt(line); |
207 LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size()); | 194 LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size()); |
208 } | 195 } |
209 | 196 |
210 void CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag, | 197 void CodeEventLogger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
211 AbstractCode* code, int args_count) { | 198 AbstractCode* code, int args_count) { |
212 name_buffer_->Init(tag); | 199 name_buffer_->Init(tag); |
213 name_buffer_->AppendInt(args_count); | 200 name_buffer_->AppendInt(args_count); |
214 LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); | 201 LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); |
215 } | 202 } |
216 | 203 |
217 void CodeEventLogger::RegExpCodeCreateEvent(AbstractCode* code, | 204 void CodeEventLogger::RegExpCodeCreateEvent(AbstractCode* code, |
218 String* source) { | 205 String* source) { |
219 name_buffer_->Init(Logger::REG_EXP_TAG); | 206 name_buffer_->Init(CodeEventListener::REG_EXP_TAG); |
220 name_buffer_->AppendString(source); | 207 name_buffer_->AppendString(source); |
221 LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); | 208 LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size()); |
222 } | 209 } |
223 | 210 |
224 | 211 |
225 // Linux perf tool logging support | 212 // Linux perf tool logging support |
226 class PerfBasicLogger : public CodeEventLogger { | 213 class PerfBasicLogger : public CodeEventLogger { |
227 public: | 214 public: |
228 PerfBasicLogger(); | 215 PerfBasicLogger(); |
229 ~PerfBasicLogger() override; | 216 ~PerfBasicLogger() override; |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 perf_jit_logger_(NULL), | 754 perf_jit_logger_(NULL), |
768 ll_logger_(NULL), | 755 ll_logger_(NULL), |
769 jit_logger_(NULL), | 756 jit_logger_(NULL), |
770 listeners_(5), | 757 listeners_(5), |
771 is_initialized_(false) {} | 758 is_initialized_(false) {} |
772 | 759 |
773 Logger::~Logger() { | 760 Logger::~Logger() { |
774 delete log_; | 761 delete log_; |
775 } | 762 } |
776 | 763 |
777 | |
778 void Logger::addCodeEventListener(CodeEventListener* listener) { | 764 void Logger::addCodeEventListener(CodeEventListener* listener) { |
779 DCHECK(!hasCodeEventListener(listener)); | 765 bool result = isolate_->code_event_dispatcher()->AddListener(listener); |
780 listeners_.Add(listener); | 766 USE(result); |
| 767 DCHECK(result); |
781 } | 768 } |
782 | 769 |
783 | |
784 void Logger::removeCodeEventListener(CodeEventListener* listener) { | 770 void Logger::removeCodeEventListener(CodeEventListener* listener) { |
785 DCHECK(hasCodeEventListener(listener)); | 771 isolate_->code_event_dispatcher()->RemoveListener(listener); |
786 listeners_.RemoveElement(listener); | |
787 } | 772 } |
788 | 773 |
789 | |
790 bool Logger::hasCodeEventListener(CodeEventListener* listener) { | |
791 return listeners_.Contains(listener); | |
792 } | |
793 | |
794 | |
795 void Logger::ProfilerBeginEvent() { | 774 void Logger::ProfilerBeginEvent() { |
796 if (!log_->IsEnabled()) return; | 775 if (!log_->IsEnabled()) return; |
797 Log::MessageBuilder msg(log_); | 776 Log::MessageBuilder msg(log_); |
798 msg.Append("profiler,\"begin\",%d", kSamplingIntervalMs); | 777 msg.Append("profiler,\"begin\",%d", kSamplingIntervalMs); |
799 msg.WriteToLogFile(); | 778 msg.WriteToLogFile(); |
800 } | 779 } |
801 | 780 |
802 | 781 |
803 void Logger::StringEvent(const char* name, const char* value) { | 782 void Logger::StringEvent(const char* name, const char* value) { |
804 if (FLAG_log) UncheckedStringEvent(name, value); | 783 if (FLAG_log) UncheckedStringEvent(name, value); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 if (!log_->IsEnabled() || !FLAG_prof_cpp) return; | 851 if (!log_->IsEnabled() || !FLAG_prof_cpp) return; |
873 Log::MessageBuilder msg(log_); | 852 Log::MessageBuilder msg(log_); |
874 msg.Append("shared-library,\"%s\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR | 853 msg.Append("shared-library,\"%s\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR |
875 ",%" V8PRIdPTR, | 854 ",%" V8PRIdPTR, |
876 library_path.c_str(), start, end, aslr_slide); | 855 library_path.c_str(), start, end, aslr_slide); |
877 msg.WriteToLogFile(); | 856 msg.WriteToLogFile(); |
878 } | 857 } |
879 | 858 |
880 | 859 |
881 void Logger::CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta) { | 860 void Logger::CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta) { |
882 PROFILER_LOG(CodeDeoptEvent(code, pc, fp_to_sp_delta)); | |
883 if (!log_->IsEnabled() || !FLAG_log_internal_timer_events) return; | 861 if (!log_->IsEnabled() || !FLAG_log_internal_timer_events) return; |
884 Log::MessageBuilder msg(log_); | 862 Log::MessageBuilder msg(log_); |
885 int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds()); | 863 int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds()); |
886 msg.Append("code-deopt,%d,%d", since_epoch, code->CodeSize()); | 864 msg.Append("code-deopt,%d,%d", since_epoch, code->CodeSize()); |
887 msg.WriteToLogFile(); | 865 msg.WriteToLogFile(); |
888 } | 866 } |
889 | 867 |
890 | 868 |
891 void Logger::CurrentTimeEvent() { | 869 void Logger::CurrentTimeEvent() { |
892 if (!log_->IsEnabled()) return; | 870 if (!log_->IsEnabled()) return; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 msg.Append("delete,%s,%p", name, object); | 1042 msg.Append("delete,%s,%p", name, object); |
1065 msg.WriteToLogFile(); | 1043 msg.WriteToLogFile(); |
1066 } | 1044 } |
1067 | 1045 |
1068 | 1046 |
1069 void Logger::CallbackEventInternal(const char* prefix, Name* name, | 1047 void Logger::CallbackEventInternal(const char* prefix, Name* name, |
1070 Address entry_point) { | 1048 Address entry_point) { |
1071 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1049 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1072 Log::MessageBuilder msg(log_); | 1050 Log::MessageBuilder msg(log_); |
1073 msg.Append("%s,%s,-2,", | 1051 msg.Append("%s,%s,-2,", |
1074 kLogEventsNames[CODE_CREATION_EVENT], | 1052 kLogEventsNames[CodeEventListener::CODE_CREATION_EVENT], |
1075 kLogEventsNames[CALLBACK_TAG]); | 1053 kLogEventsNames[CodeEventListener::CALLBACK_TAG]); |
1076 msg.AppendAddress(entry_point); | 1054 msg.AppendAddress(entry_point); |
1077 if (name->IsString()) { | 1055 if (name->IsString()) { |
1078 base::SmartArrayPointer<char> str = | 1056 base::SmartArrayPointer<char> str = |
1079 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1057 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
1080 msg.Append(",1,\"%s%s\"", prefix, str.get()); | 1058 msg.Append(",1,\"%s%s\"", prefix, str.get()); |
1081 } else { | 1059 } else { |
1082 Symbol* symbol = Symbol::cast(name); | 1060 Symbol* symbol = Symbol::cast(name); |
1083 if (symbol->name()->IsUndefined(symbol->GetIsolate())) { | 1061 if (symbol->name()->IsUndefined(symbol->GetIsolate())) { |
1084 msg.Append(",1,symbol(hash %x)", symbol->Hash()); | 1062 msg.Append(",1,symbol(hash %x)", symbol->Hash()); |
1085 } else { | 1063 } else { |
1086 base::SmartArrayPointer<char> str = | 1064 base::SmartArrayPointer<char> str = |
1087 String::cast(symbol->name()) | 1065 String::cast(symbol->name()) |
1088 ->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1066 ->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
1089 msg.Append(",1,symbol(\"%s%s\" hash %x)", prefix, str.get(), | 1067 msg.Append(",1,symbol(\"%s%s\" hash %x)", prefix, str.get(), |
1090 symbol->Hash()); | 1068 symbol->Hash()); |
1091 } | 1069 } |
1092 } | 1070 } |
1093 msg.WriteToLogFile(); | 1071 msg.WriteToLogFile(); |
1094 } | 1072 } |
1095 | 1073 |
1096 | 1074 |
1097 void Logger::CallbackEvent(Name* name, Address entry_point) { | 1075 void Logger::CallbackEvent(Name* name, Address entry_point) { |
1098 PROFILER_LOG(CallbackEvent(name, entry_point)); | |
1099 CallbackEventInternal("", name, entry_point); | 1076 CallbackEventInternal("", name, entry_point); |
1100 } | 1077 } |
1101 | 1078 |
1102 | 1079 |
1103 void Logger::GetterCallbackEvent(Name* name, Address entry_point) { | 1080 void Logger::GetterCallbackEvent(Name* name, Address entry_point) { |
1104 PROFILER_LOG(GetterCallbackEvent(name, entry_point)); | |
1105 CallbackEventInternal("get ", name, entry_point); | 1081 CallbackEventInternal("get ", name, entry_point); |
1106 } | 1082 } |
1107 | 1083 |
1108 | 1084 |
1109 void Logger::SetterCallbackEvent(Name* name, Address entry_point) { | 1085 void Logger::SetterCallbackEvent(Name* name, Address entry_point) { |
1110 PROFILER_LOG(SetterCallbackEvent(name, entry_point)); | |
1111 CallbackEventInternal("set ", name, entry_point); | 1086 CallbackEventInternal("set ", name, entry_point); |
1112 } | 1087 } |
1113 | 1088 |
1114 static void AppendCodeCreateHeader(Log::MessageBuilder* msg, | 1089 static void AppendCodeCreateHeader(Log::MessageBuilder* msg, |
1115 Logger::LogEventsAndTags tag, | 1090 CodeEventListener::LogEventsAndTags tag, |
1116 AbstractCode* code) { | 1091 AbstractCode* code) { |
1117 DCHECK(msg); | 1092 DCHECK(msg); |
1118 msg->Append("%s,%s,%d,", | 1093 msg->Append("%s,%s,%d,", |
1119 kLogEventsNames[Logger::CODE_CREATION_EVENT], | 1094 kLogEventsNames[CodeEventListener::CODE_CREATION_EVENT], |
1120 kLogEventsNames[tag], | 1095 kLogEventsNames[tag], code->kind()); |
1121 code->kind()); | |
1122 msg->AppendAddress(code->address()); | 1096 msg->AppendAddress(code->address()); |
1123 msg->Append(",%d,", code->ExecutableSize()); | 1097 msg->Append(",%d,", code->ExecutableSize()); |
1124 } | 1098 } |
1125 | 1099 |
1126 void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, | 1100 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
1127 const char* comment) { | 1101 AbstractCode* code, const char* comment) { |
1128 PROFILER_LOG(CodeCreateEvent(tag, code, comment)); | |
1129 | |
1130 if (!is_logging_code_events()) return; | 1102 if (!is_logging_code_events()) return; |
1131 CALL_LISTENERS(CodeCreateEvent(tag, code, comment)); | |
1132 | |
1133 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1103 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1134 Log::MessageBuilder msg(log_); | 1104 Log::MessageBuilder msg(log_); |
1135 AppendCodeCreateHeader(&msg, tag, code); | 1105 AppendCodeCreateHeader(&msg, tag, code); |
1136 msg.AppendDoubleQuotedString(comment); | 1106 msg.AppendDoubleQuotedString(comment); |
1137 msg.WriteToLogFile(); | 1107 msg.WriteToLogFile(); |
1138 } | 1108 } |
1139 | 1109 |
1140 void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, | 1110 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
1141 Name* name) { | 1111 AbstractCode* code, Name* name) { |
1142 PROFILER_LOG(CodeCreateEvent(tag, code, name)); | |
1143 | |
1144 if (!is_logging_code_events()) return; | 1112 if (!is_logging_code_events()) return; |
1145 CALL_LISTENERS(CodeCreateEvent(tag, code, name)); | |
1146 | |
1147 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1113 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1148 Log::MessageBuilder msg(log_); | 1114 Log::MessageBuilder msg(log_); |
1149 AppendCodeCreateHeader(&msg, tag, code); | 1115 AppendCodeCreateHeader(&msg, tag, code); |
1150 if (name->IsString()) { | 1116 if (name->IsString()) { |
1151 msg.Append('"'); | 1117 msg.Append('"'); |
1152 msg.AppendDetailed(String::cast(name), false); | 1118 msg.AppendDetailed(String::cast(name), false); |
1153 msg.Append('"'); | 1119 msg.Append('"'); |
1154 } else { | 1120 } else { |
1155 msg.AppendSymbolName(Symbol::cast(name)); | 1121 msg.AppendSymbolName(Symbol::cast(name)); |
1156 } | 1122 } |
1157 msg.WriteToLogFile(); | 1123 msg.WriteToLogFile(); |
1158 } | 1124 } |
1159 | 1125 |
1160 void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, | 1126 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
1161 SharedFunctionInfo* shared, Name* name) { | 1127 AbstractCode* code, SharedFunctionInfo* shared, |
1162 PROFILER_LOG(CodeCreateEvent(tag, code, shared, name)); | 1128 Name* name) { |
1163 | |
1164 if (!is_logging_code_events()) return; | 1129 if (!is_logging_code_events()) return; |
1165 CALL_LISTENERS(CodeCreateEvent(tag, code, shared, name)); | |
1166 | |
1167 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1130 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1168 if (code == AbstractCode::cast( | 1131 if (code == AbstractCode::cast( |
1169 isolate_->builtins()->builtin(Builtins::kCompileLazy))) { | 1132 isolate_->builtins()->builtin(Builtins::kCompileLazy))) { |
1170 return; | 1133 return; |
1171 } | 1134 } |
1172 | 1135 |
1173 Log::MessageBuilder msg(log_); | 1136 Log::MessageBuilder msg(log_); |
1174 AppendCodeCreateHeader(&msg, tag, code); | 1137 AppendCodeCreateHeader(&msg, tag, code); |
1175 if (name->IsString()) { | 1138 if (name->IsString()) { |
1176 base::SmartArrayPointer<char> str = | 1139 base::SmartArrayPointer<char> str = |
1177 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1140 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
1178 msg.Append("\"%s\"", str.get()); | 1141 msg.Append("\"%s\"", str.get()); |
1179 } else { | 1142 } else { |
1180 msg.AppendSymbolName(Symbol::cast(name)); | 1143 msg.AppendSymbolName(Symbol::cast(name)); |
1181 } | 1144 } |
1182 msg.Append(','); | 1145 msg.Append(','); |
1183 msg.AppendAddress(shared->address()); | 1146 msg.AppendAddress(shared->address()); |
1184 msg.Append(",%s", ComputeMarker(shared, code)); | 1147 msg.Append(",%s", ComputeMarker(shared, code)); |
1185 msg.WriteToLogFile(); | 1148 msg.WriteToLogFile(); |
1186 } | 1149 } |
1187 | 1150 |
1188 | 1151 |
1189 // Although, it is possible to extract source and line from | 1152 // Although, it is possible to extract source and line from |
1190 // the SharedFunctionInfo object, we left it to caller | 1153 // the SharedFunctionInfo object, we left it to caller |
1191 // to leave logging functions free from heap allocations. | 1154 // to leave logging functions free from heap allocations. |
1192 void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, | 1155 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
1193 SharedFunctionInfo* shared, Name* source, int line, | 1156 AbstractCode* code, SharedFunctionInfo* shared, |
1194 int column) { | 1157 Name* source, int line, int column) { |
1195 PROFILER_LOG(CodeCreateEvent(tag, code, shared, source, line, column)); | |
1196 | |
1197 if (!is_logging_code_events()) return; | 1158 if (!is_logging_code_events()) return; |
1198 CALL_LISTENERS(CodeCreateEvent(tag, code, shared, source, line, column)); | |
1199 | |
1200 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1159 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1201 Log::MessageBuilder msg(log_); | 1160 Log::MessageBuilder msg(log_); |
1202 AppendCodeCreateHeader(&msg, tag, code); | 1161 AppendCodeCreateHeader(&msg, tag, code); |
1203 base::SmartArrayPointer<char> name = | 1162 base::SmartArrayPointer<char> name = |
1204 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1163 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
1205 msg.Append("\"%s ", name.get()); | 1164 msg.Append("\"%s ", name.get()); |
1206 if (source->IsString()) { | 1165 if (source->IsString()) { |
1207 base::SmartArrayPointer<char> sourcestr = String::cast(source)->ToCString( | 1166 base::SmartArrayPointer<char> sourcestr = String::cast(source)->ToCString( |
1208 DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1167 DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
1209 msg.Append("%s", sourcestr.get()); | 1168 msg.Append("%s", sourcestr.get()); |
1210 } else { | 1169 } else { |
1211 msg.AppendSymbolName(Symbol::cast(source)); | 1170 msg.AppendSymbolName(Symbol::cast(source)); |
1212 } | 1171 } |
1213 msg.Append(":%d:%d\",", line, column); | 1172 msg.Append(":%d:%d\",", line, column); |
1214 msg.AppendAddress(shared->address()); | 1173 msg.AppendAddress(shared->address()); |
1215 msg.Append(",%s", ComputeMarker(shared, code)); | 1174 msg.Append(",%s", ComputeMarker(shared, code)); |
1216 msg.WriteToLogFile(); | 1175 msg.WriteToLogFile(); |
1217 } | 1176 } |
1218 | 1177 |
1219 void Logger::CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code, | 1178 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
1220 int args_count) { | 1179 AbstractCode* code, int args_count) { |
1221 PROFILER_LOG(CodeCreateEvent(tag, code, args_count)); | |
1222 | |
1223 if (!is_logging_code_events()) return; | 1180 if (!is_logging_code_events()) return; |
1224 CALL_LISTENERS(CodeCreateEvent(tag, code, args_count)); | |
1225 | |
1226 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1181 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1227 Log::MessageBuilder msg(log_); | 1182 Log::MessageBuilder msg(log_); |
1228 AppendCodeCreateHeader(&msg, tag, code); | 1183 AppendCodeCreateHeader(&msg, tag, code); |
1229 msg.Append("\"args_count: %d\"", args_count); | 1184 msg.Append("\"args_count: %d\"", args_count); |
1230 msg.WriteToLogFile(); | 1185 msg.WriteToLogFile(); |
1231 } | 1186 } |
1232 | 1187 |
1233 void Logger::CodeDisableOptEvent(AbstractCode* code, | 1188 void Logger::CodeDisableOptEvent(AbstractCode* code, |
1234 SharedFunctionInfo* shared) { | 1189 SharedFunctionInfo* shared) { |
1235 PROFILER_LOG(CodeDisableOptEvent(code, shared)); | |
1236 | |
1237 if (!is_logging_code_events()) return; | 1190 if (!is_logging_code_events()) return; |
1238 CALL_LISTENERS(CodeDisableOptEvent(code, shared)); | |
1239 | |
1240 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1191 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1241 Log::MessageBuilder msg(log_); | 1192 Log::MessageBuilder msg(log_); |
1242 msg.Append("%s,", kLogEventsNames[CODE_DISABLE_OPT_EVENT]); | 1193 msg.Append("%s,", kLogEventsNames[CodeEventListener::CODE_DISABLE_OPT_EVENT]); |
1243 base::SmartArrayPointer<char> name = | 1194 base::SmartArrayPointer<char> name = |
1244 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1195 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
1245 msg.Append("\"%s\",", name.get()); | 1196 msg.Append("\"%s\",", name.get()); |
1246 msg.Append("\"%s\"", GetBailoutReason(shared->disable_optimization_reason())); | 1197 msg.Append("\"%s\"", GetBailoutReason(shared->disable_optimization_reason())); |
1247 msg.WriteToLogFile(); | 1198 msg.WriteToLogFile(); |
1248 } | 1199 } |
1249 | 1200 |
1250 | 1201 |
1251 void Logger::CodeMovingGCEvent() { | 1202 void Logger::CodeMovingGCEvent() { |
1252 PROFILER_LOG(CodeMovingGCEvent()); | |
1253 | |
1254 if (!is_logging_code_events()) return; | 1203 if (!is_logging_code_events()) return; |
1255 if (!log_->IsEnabled() || !FLAG_ll_prof) return; | 1204 if (!log_->IsEnabled() || !FLAG_ll_prof) return; |
1256 CALL_LISTENERS(CodeMovingGCEvent()); | |
1257 base::OS::SignalCodeMovingGC(); | 1205 base::OS::SignalCodeMovingGC(); |
1258 } | 1206 } |
1259 | 1207 |
1260 void Logger::RegExpCodeCreateEvent(AbstractCode* code, String* source) { | 1208 void Logger::RegExpCodeCreateEvent(AbstractCode* code, String* source) { |
1261 PROFILER_LOG(RegExpCodeCreateEvent(code, source)); | |
1262 | |
1263 if (!is_logging_code_events()) return; | 1209 if (!is_logging_code_events()) return; |
1264 CALL_LISTENERS(RegExpCodeCreateEvent(code, source)); | |
1265 | |
1266 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1210 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1267 Log::MessageBuilder msg(log_); | 1211 Log::MessageBuilder msg(log_); |
1268 AppendCodeCreateHeader(&msg, REG_EXP_TAG, code); | 1212 AppendCodeCreateHeader(&msg, CodeEventListener::REG_EXP_TAG, code); |
1269 msg.Append('"'); | 1213 msg.Append('"'); |
1270 msg.AppendDetailed(source, false); | 1214 msg.AppendDetailed(source, false); |
1271 msg.Append('"'); | 1215 msg.Append('"'); |
1272 msg.WriteToLogFile(); | 1216 msg.WriteToLogFile(); |
1273 } | 1217 } |
1274 | 1218 |
1275 void Logger::CodeMoveEvent(AbstractCode* from, Address to) { | 1219 void Logger::CodeMoveEvent(AbstractCode* from, Address to) { |
1276 PROFILER_LOG(CodeMoveEvent(from, to)); | |
1277 | |
1278 if (!is_logging_code_events()) return; | 1220 if (!is_logging_code_events()) return; |
1279 CALL_LISTENERS(CodeMoveEvent(from, to)); | 1221 MoveEventInternal(CodeEventListener::CODE_MOVE_EVENT, from->address(), to); |
1280 MoveEventInternal(CODE_MOVE_EVENT, from->address(), to); | |
1281 } | 1222 } |
1282 | 1223 |
1283 void Logger::CodeLinePosInfoAddPositionEvent(void* jit_handler_data, | 1224 void Logger::CodeLinePosInfoAddPositionEvent(void* jit_handler_data, |
1284 int pc_offset, int position) { | 1225 int pc_offset, int position) { |
1285 JIT_LOG(AddCodeLinePosInfoEvent(jit_handler_data, | 1226 JIT_LOG(AddCodeLinePosInfoEvent(jit_handler_data, |
1286 pc_offset, | 1227 pc_offset, |
1287 position, | 1228 position, |
1288 JitCodeEvent::POSITION)); | 1229 JitCodeEvent::POSITION)); |
1289 } | 1230 } |
1290 | 1231 |
(...skipping 16 matching lines...) Expand all Loading... |
1307 | 1248 |
1308 void Logger::CodeEndLinePosInfoRecordEvent(AbstractCode* code, | 1249 void Logger::CodeEndLinePosInfoRecordEvent(AbstractCode* code, |
1309 void* jit_handler_data) { | 1250 void* jit_handler_data) { |
1310 JIT_LOG(EndCodePosInfoEvent(code, jit_handler_data)); | 1251 JIT_LOG(EndCodePosInfoEvent(code, jit_handler_data)); |
1311 } | 1252 } |
1312 | 1253 |
1313 | 1254 |
1314 void Logger::CodeNameEvent(Address addr, int pos, const char* code_name) { | 1255 void Logger::CodeNameEvent(Address addr, int pos, const char* code_name) { |
1315 if (code_name == NULL) return; // Not a code object. | 1256 if (code_name == NULL) return; // Not a code object. |
1316 Log::MessageBuilder msg(log_); | 1257 Log::MessageBuilder msg(log_); |
1317 msg.Append("%s,%d,", kLogEventsNames[SNAPSHOT_CODE_NAME_EVENT], pos); | 1258 msg.Append("%s,%d,", |
| 1259 kLogEventsNames[CodeEventListener::SNAPSHOT_CODE_NAME_EVENT], pos); |
1318 msg.AppendDoubleQuotedString(code_name); | 1260 msg.AppendDoubleQuotedString(code_name); |
1319 msg.WriteToLogFile(); | 1261 msg.WriteToLogFile(); |
1320 } | 1262 } |
1321 | 1263 |
1322 | 1264 |
1323 void Logger::SharedFunctionInfoMoveEvent(Address from, Address to) { | 1265 void Logger::SharedFunctionInfoMoveEvent(Address from, Address to) { |
1324 if (!is_logging_code_events()) return; | 1266 if (!is_logging_code_events()) return; |
1325 MoveEventInternal(SHARED_FUNC_MOVE_EVENT, from, to); | 1267 MoveEventInternal(CodeEventListener::SHARED_FUNC_MOVE_EVENT, from, to); |
1326 } | 1268 } |
1327 | 1269 |
1328 | 1270 void Logger::MoveEventInternal(CodeEventListener::LogEventsAndTags event, |
1329 void Logger::MoveEventInternal(LogEventsAndTags event, | 1271 Address from, Address to) { |
1330 Address from, | |
1331 Address to) { | |
1332 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1272 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1333 Log::MessageBuilder msg(log_); | 1273 Log::MessageBuilder msg(log_); |
1334 msg.Append("%s,", kLogEventsNames[event]); | 1274 msg.Append("%s,", kLogEventsNames[event]); |
1335 msg.AppendAddress(from); | 1275 msg.AppendAddress(from); |
1336 msg.Append(','); | 1276 msg.Append(','); |
1337 msg.AppendAddress(to); | 1277 msg.AppendAddress(to); |
1338 msg.WriteToLogFile(); | 1278 msg.WriteToLogFile(); |
1339 } | 1279 } |
1340 | 1280 |
1341 | 1281 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1433 msg.AppendDoubleQuotedString(counter->name); | 1373 msg.AppendDoubleQuotedString(counter->name); |
1434 msg.WriteToLogFile(); | 1374 msg.WriteToLogFile(); |
1435 } | 1375 } |
1436 | 1376 |
1437 void Logger::TickEvent(TickSample* sample, bool overflow) { | 1377 void Logger::TickEvent(TickSample* sample, bool overflow) { |
1438 if (!log_->IsEnabled() || !FLAG_prof_cpp) return; | 1378 if (!log_->IsEnabled() || !FLAG_prof_cpp) return; |
1439 if (FLAG_runtime_call_stats) { | 1379 if (FLAG_runtime_call_stats) { |
1440 RuntimeCallTimerEvent(); | 1380 RuntimeCallTimerEvent(); |
1441 } | 1381 } |
1442 Log::MessageBuilder msg(log_); | 1382 Log::MessageBuilder msg(log_); |
1443 msg.Append("%s,", kLogEventsNames[TICK_EVENT]); | 1383 msg.Append("%s,", kLogEventsNames[CodeEventListener::TICK_EVENT]); |
1444 msg.AppendAddress(sample->pc); | 1384 msg.AppendAddress(sample->pc); |
1445 msg.Append(",%d", static_cast<int>(timer_.Elapsed().InMicroseconds())); | 1385 msg.Append(",%d", static_cast<int>(timer_.Elapsed().InMicroseconds())); |
1446 if (sample->has_external_callback) { | 1386 if (sample->has_external_callback) { |
1447 msg.Append(",1,"); | 1387 msg.Append(",1,"); |
1448 msg.AppendAddress(sample->external_callback_entry); | 1388 msg.AppendAddress(sample->external_callback_entry); |
1449 } else { | 1389 } else { |
1450 msg.Append(",0,"); | 1390 msg.Append(",0,"); |
1451 msg.AppendAddress(sample->tos); | 1391 msg.AppendAddress(sample->tos); |
1452 } | 1392 } |
1453 msg.Append(",%d", static_cast<int>(sample->state)); | 1393 msg.Append(",%d", static_cast<int>(sample->state)); |
1454 if (overflow) { | 1394 if (overflow) { |
1455 msg.Append(",overflow"); | 1395 msg.Append(",overflow"); |
1456 } | 1396 } |
1457 for (unsigned i = 0; i < sample->frames_count; ++i) { | 1397 for (unsigned i = 0; i < sample->frames_count; ++i) { |
1458 msg.Append(','); | 1398 msg.Append(','); |
1459 msg.AppendAddress(sample->stack[i]); | 1399 msg.AppendAddress(sample->stack[i]); |
1460 } | 1400 } |
1461 msg.WriteToLogFile(); | 1401 msg.WriteToLogFile(); |
1462 } | 1402 } |
1463 | 1403 |
1464 | 1404 |
1465 void Logger::StopProfiler() { | 1405 void Logger::StopProfiler() { |
1466 if (!log_->IsEnabled()) return; | 1406 if (!log_->IsEnabled()) return; |
1467 if (profiler_ != NULL) { | 1407 if (profiler_ != NULL) { |
1468 profiler_->pause(); | 1408 profiler_->pause(); |
1469 is_logging_ = false; | 1409 is_logging_ = false; |
| 1410 removeCodeEventListener(this); |
1470 } | 1411 } |
1471 } | 1412 } |
1472 | 1413 |
1473 | 1414 |
1474 // This function can be called when Log's mutex is acquired, | 1415 // This function can be called when Log's mutex is acquired, |
1475 // either from main or Profiler's thread. | 1416 // either from main or Profiler's thread. |
1476 void Logger::LogFailure() { | 1417 void Logger::LogFailure() { |
1477 StopProfiler(); | 1418 StopProfiler(); |
1478 } | 1419 } |
1479 | 1420 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 code_objects, | 1482 code_objects, |
1542 &compiled_funcs_count); | 1483 &compiled_funcs_count); |
1543 Deoptimizer::VisitAllOptimizedFunctions(heap->isolate(), &visitor); | 1484 Deoptimizer::VisitAllOptimizedFunctions(heap->isolate(), &visitor); |
1544 | 1485 |
1545 return compiled_funcs_count; | 1486 return compiled_funcs_count; |
1546 } | 1487 } |
1547 | 1488 |
1548 | 1489 |
1549 void Logger::LogCodeObject(Object* object) { | 1490 void Logger::LogCodeObject(Object* object) { |
1550 AbstractCode* code_object = AbstractCode::cast(object); | 1491 AbstractCode* code_object = AbstractCode::cast(object); |
1551 LogEventsAndTags tag = Logger::STUB_TAG; | 1492 CodeEventListener::LogEventsAndTags tag = CodeEventListener::STUB_TAG; |
1552 const char* description = "Unknown code from the snapshot"; | 1493 const char* description = "Unknown code from the snapshot"; |
1553 switch (code_object->kind()) { | 1494 switch (code_object->kind()) { |
1554 case AbstractCode::FUNCTION: | 1495 case AbstractCode::FUNCTION: |
1555 case AbstractCode::INTERPRETED_FUNCTION: | 1496 case AbstractCode::INTERPRETED_FUNCTION: |
1556 case AbstractCode::OPTIMIZED_FUNCTION: | 1497 case AbstractCode::OPTIMIZED_FUNCTION: |
1557 return; // We log this later using LogCompiledFunctions. | 1498 return; // We log this later using LogCompiledFunctions. |
1558 case AbstractCode::BYTECODE_HANDLER: | 1499 case AbstractCode::BYTECODE_HANDLER: |
1559 return; // We log it later by walking the dispatch table. | 1500 return; // We log it later by walking the dispatch table. |
1560 case AbstractCode::BINARY_OP_IC: // fall through | 1501 case AbstractCode::BINARY_OP_IC: // fall through |
1561 case AbstractCode::COMPARE_IC: // fall through | 1502 case AbstractCode::COMPARE_IC: // fall through |
1562 case AbstractCode::TO_BOOLEAN_IC: // fall through | 1503 case AbstractCode::TO_BOOLEAN_IC: // fall through |
1563 | 1504 |
1564 case AbstractCode::STUB: | 1505 case AbstractCode::STUB: |
1565 description = | 1506 description = |
1566 CodeStub::MajorName(CodeStub::GetMajorKey(code_object->GetCode())); | 1507 CodeStub::MajorName(CodeStub::GetMajorKey(code_object->GetCode())); |
1567 if (description == NULL) | 1508 if (description == NULL) |
1568 description = "A stub from the snapshot"; | 1509 description = "A stub from the snapshot"; |
1569 tag = Logger::STUB_TAG; | 1510 tag = CodeEventListener::STUB_TAG; |
1570 break; | 1511 break; |
1571 case AbstractCode::REGEXP: | 1512 case AbstractCode::REGEXP: |
1572 description = "Regular expression code"; | 1513 description = "Regular expression code"; |
1573 tag = Logger::REG_EXP_TAG; | 1514 tag = CodeEventListener::REG_EXP_TAG; |
1574 break; | 1515 break; |
1575 case AbstractCode::BUILTIN: | 1516 case AbstractCode::BUILTIN: |
1576 description = | 1517 description = |
1577 isolate_->builtins()->name(code_object->GetCode()->builtin_index()); | 1518 isolate_->builtins()->name(code_object->GetCode()->builtin_index()); |
1578 tag = Logger::BUILTIN_TAG; | 1519 tag = CodeEventListener::BUILTIN_TAG; |
1579 break; | 1520 break; |
1580 case AbstractCode::HANDLER: | 1521 case AbstractCode::HANDLER: |
1581 description = "An IC handler from the snapshot"; | 1522 description = "An IC handler from the snapshot"; |
1582 tag = Logger::HANDLER_TAG; | 1523 tag = CodeEventListener::HANDLER_TAG; |
1583 break; | 1524 break; |
1584 case AbstractCode::KEYED_LOAD_IC: | 1525 case AbstractCode::KEYED_LOAD_IC: |
1585 description = "A keyed load IC from the snapshot"; | 1526 description = "A keyed load IC from the snapshot"; |
1586 tag = Logger::KEYED_LOAD_IC_TAG; | 1527 tag = CodeEventListener::KEYED_LOAD_IC_TAG; |
1587 break; | 1528 break; |
1588 case AbstractCode::LOAD_IC: | 1529 case AbstractCode::LOAD_IC: |
1589 description = "A load IC from the snapshot"; | 1530 description = "A load IC from the snapshot"; |
1590 tag = Logger::LOAD_IC_TAG; | 1531 tag = CodeEventListener::LOAD_IC_TAG; |
1591 break; | 1532 break; |
1592 case AbstractCode::CALL_IC: | 1533 case AbstractCode::CALL_IC: |
1593 description = "A call IC from the snapshot"; | 1534 description = "A call IC from the snapshot"; |
1594 tag = Logger::CALL_IC_TAG; | 1535 tag = CodeEventListener::CALL_IC_TAG; |
1595 break; | 1536 break; |
1596 case AbstractCode::STORE_IC: | 1537 case AbstractCode::STORE_IC: |
1597 description = "A store IC from the snapshot"; | 1538 description = "A store IC from the snapshot"; |
1598 tag = Logger::STORE_IC_TAG; | 1539 tag = CodeEventListener::STORE_IC_TAG; |
1599 break; | 1540 break; |
1600 case AbstractCode::KEYED_STORE_IC: | 1541 case AbstractCode::KEYED_STORE_IC: |
1601 description = "A keyed store IC from the snapshot"; | 1542 description = "A keyed store IC from the snapshot"; |
1602 tag = Logger::KEYED_STORE_IC_TAG; | 1543 tag = CodeEventListener::KEYED_STORE_IC_TAG; |
1603 break; | 1544 break; |
1604 case AbstractCode::WASM_FUNCTION: | 1545 case AbstractCode::WASM_FUNCTION: |
1605 description = "A Wasm function"; | 1546 description = "A Wasm function"; |
1606 tag = Logger::STUB_TAG; | 1547 tag = CodeEventListener::STUB_TAG; |
1607 break; | 1548 break; |
1608 case AbstractCode::JS_TO_WASM_FUNCTION: | 1549 case AbstractCode::JS_TO_WASM_FUNCTION: |
1609 description = "A JavaScript to Wasm adapter"; | 1550 description = "A JavaScript to Wasm adapter"; |
1610 tag = Logger::STUB_TAG; | 1551 tag = CodeEventListener::STUB_TAG; |
1611 break; | 1552 break; |
1612 case AbstractCode::WASM_TO_JS_FUNCTION: | 1553 case AbstractCode::WASM_TO_JS_FUNCTION: |
1613 description = "A Wasm to JavaScript adapter"; | 1554 description = "A Wasm to JavaScript adapter"; |
1614 tag = Logger::STUB_TAG; | 1555 tag = CodeEventListener::STUB_TAG; |
1615 break; | 1556 break; |
1616 case AbstractCode::NUMBER_OF_KINDS: | 1557 case AbstractCode::NUMBER_OF_KINDS: |
1617 UNIMPLEMENTED(); | 1558 UNIMPLEMENTED(); |
1618 } | 1559 } |
1619 PROFILE(isolate_, CodeCreateEvent(tag, code_object, description)); | 1560 PROFILE(isolate_, CodeCreateEvent(tag, code_object, description)); |
1620 } | 1561 } |
1621 | 1562 |
1622 | 1563 |
1623 void Logger::LogCodeObjects() { | 1564 void Logger::LogCodeObjects() { |
1624 Heap* heap = isolate_->heap(); | 1565 Heap* heap = isolate_->heap(); |
(...skipping 18 matching lines...) Expand all Loading... |
1643 | 1584 |
1644 const int last_index = static_cast<int>(interpreter::Bytecode::kLast); | 1585 const int last_index = static_cast<int>(interpreter::Bytecode::kLast); |
1645 interpreter::Interpreter* interpreter = isolate_->interpreter(); | 1586 interpreter::Interpreter* interpreter = isolate_->interpreter(); |
1646 for (auto operand_scale : kOperandScales) { | 1587 for (auto operand_scale : kOperandScales) { |
1647 for (int index = 0; index <= last_index; ++index) { | 1588 for (int index = 0; index <= last_index; ++index) { |
1648 interpreter::Bytecode bytecode = interpreter::Bytecodes::FromByte(index); | 1589 interpreter::Bytecode bytecode = interpreter::Bytecodes::FromByte(index); |
1649 if (interpreter::Bytecodes::BytecodeHasHandler(bytecode, operand_scale)) { | 1590 if (interpreter::Bytecodes::BytecodeHasHandler(bytecode, operand_scale)) { |
1650 Code* code = interpreter->GetBytecodeHandler(bytecode, operand_scale); | 1591 Code* code = interpreter->GetBytecodeHandler(bytecode, operand_scale); |
1651 std::string bytecode_name = | 1592 std::string bytecode_name = |
1652 interpreter::Bytecodes::ToString(bytecode, operand_scale); | 1593 interpreter::Bytecodes::ToString(bytecode, operand_scale); |
1653 CodeCreateEvent(Logger::BYTECODE_HANDLER_TAG, AbstractCode::cast(code), | 1594 CodeCreateEvent(CodeEventListener::BYTECODE_HANDLER_TAG, |
1654 bytecode_name.c_str()); | 1595 AbstractCode::cast(code), bytecode_name.c_str()); |
1655 } | 1596 } |
1656 } | 1597 } |
1657 } | 1598 } |
1658 } | 1599 } |
1659 | 1600 |
1660 void Logger::LogExistingFunction(Handle<SharedFunctionInfo> shared, | 1601 void Logger::LogExistingFunction(Handle<SharedFunctionInfo> shared, |
1661 Handle<AbstractCode> code) { | 1602 Handle<AbstractCode> code) { |
1662 Handle<String> func_name(shared->DebugName()); | 1603 Handle<String> func_name(shared->DebugName()); |
1663 if (shared->script()->IsScript()) { | 1604 if (shared->script()->IsScript()) { |
1664 Handle<Script> script(Script::cast(shared->script())); | 1605 Handle<Script> script(Script::cast(shared->script())); |
1665 int line_num = Script::GetLineNumber(script, shared->start_position()) + 1; | 1606 int line_num = Script::GetLineNumber(script, shared->start_position()) + 1; |
1666 int column_num = | 1607 int column_num = |
1667 Script::GetColumnNumber(script, shared->start_position()) + 1; | 1608 Script::GetColumnNumber(script, shared->start_position()) + 1; |
1668 if (script->name()->IsString()) { | 1609 if (script->name()->IsString()) { |
1669 Handle<String> script_name(String::cast(script->name())); | 1610 Handle<String> script_name(String::cast(script->name())); |
1670 if (line_num > 0) { | 1611 if (line_num > 0) { |
1671 PROFILE(isolate_, | 1612 PROFILE(isolate_, |
1672 CodeCreateEvent( | 1613 CodeCreateEvent( |
1673 Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script), | 1614 Logger::ToNativeByScript( |
| 1615 CodeEventListener::LAZY_COMPILE_TAG, *script), |
1674 *code, *shared, *script_name, line_num, column_num)); | 1616 *code, *shared, *script_name, line_num, column_num)); |
1675 } else { | 1617 } else { |
1676 // Can't distinguish eval and script here, so always use Script. | 1618 // Can't distinguish eval and script here, so always use Script. |
1677 PROFILE(isolate_, CodeCreateEvent(Logger::ToNativeByScript( | 1619 PROFILE(isolate_, |
1678 Logger::SCRIPT_TAG, *script), | 1620 CodeCreateEvent(Logger::ToNativeByScript( |
1679 *code, *shared, *script_name)); | 1621 CodeEventListener::SCRIPT_TAG, *script), |
| 1622 *code, *shared, *script_name)); |
1680 } | 1623 } |
1681 } else { | 1624 } else { |
1682 PROFILE(isolate_, | 1625 PROFILE(isolate_, |
1683 CodeCreateEvent( | 1626 CodeCreateEvent(Logger::ToNativeByScript( |
1684 Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script), | 1627 CodeEventListener::LAZY_COMPILE_TAG, *script), |
1685 *code, *shared, isolate_->heap()->empty_string(), line_num, | 1628 *code, *shared, isolate_->heap()->empty_string(), |
1686 column_num)); | 1629 line_num, column_num)); |
1687 } | 1630 } |
1688 } else if (shared->IsApiFunction()) { | 1631 } else if (shared->IsApiFunction()) { |
1689 // API function. | 1632 // API function. |
1690 FunctionTemplateInfo* fun_data = shared->get_api_func_data(); | 1633 FunctionTemplateInfo* fun_data = shared->get_api_func_data(); |
1691 Object* raw_call_data = fun_data->call_code(); | 1634 Object* raw_call_data = fun_data->call_code(); |
1692 if (!raw_call_data->IsUndefined(isolate_)) { | 1635 if (!raw_call_data->IsUndefined(isolate_)) { |
1693 CallHandlerInfo* call_data = CallHandlerInfo::cast(raw_call_data); | 1636 CallHandlerInfo* call_data = CallHandlerInfo::cast(raw_call_data); |
1694 Object* callback_obj = call_data->callback(); | 1637 Object* callback_obj = call_data->callback(); |
1695 Address entry_point = v8::ToCData<Address>(callback_obj); | 1638 Address entry_point = v8::ToCData<Address>(callback_obj); |
1696 #if USES_FUNCTION_DESCRIPTORS | 1639 #if USES_FUNCTION_DESCRIPTORS |
1697 entry_point = *FUNCTION_ENTRYPOINT_ADDRESS(entry_point); | 1640 entry_point = *FUNCTION_ENTRYPOINT_ADDRESS(entry_point); |
1698 #endif | 1641 #endif |
1699 PROFILE(isolate_, CallbackEvent(*func_name, entry_point)); | 1642 PROFILE(isolate_, CallbackEvent(*func_name, entry_point)); |
1700 } | 1643 } |
1701 } else { | 1644 } else { |
1702 PROFILE(isolate_, CodeCreateEvent(Logger::LAZY_COMPILE_TAG, *code, *shared, | 1645 PROFILE(isolate_, CodeCreateEvent(CodeEventListener::LAZY_COMPILE_TAG, |
1703 *func_name)); | 1646 *code, *shared, *func_name)); |
1704 } | 1647 } |
1705 } | 1648 } |
1706 | 1649 |
1707 | 1650 |
1708 void Logger::LogCompiledFunctions() { | 1651 void Logger::LogCompiledFunctions() { |
1709 Heap* heap = isolate_->heap(); | 1652 Heap* heap = isolate_->heap(); |
1710 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, | 1653 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
1711 "Logger::LogCompiledFunctions"); | 1654 "Logger::LogCompiledFunctions"); |
1712 HandleScope scope(isolate_); | 1655 HandleScope scope(isolate_); |
1713 const int compiled_funcs_count = EnumerateCompiledFunctions(heap, NULL, NULL); | 1656 const int compiled_funcs_count = EnumerateCompiledFunctions(heap, NULL, NULL); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1806 | 1749 |
1807 bool Logger::SetUp(Isolate* isolate) { | 1750 bool Logger::SetUp(Isolate* isolate) { |
1808 // Tests and EnsureInitialize() can call this twice in a row. It's harmless. | 1751 // Tests and EnsureInitialize() can call this twice in a row. It's harmless. |
1809 if (is_initialized_) return true; | 1752 if (is_initialized_) return true; |
1810 is_initialized_ = true; | 1753 is_initialized_ = true; |
1811 | 1754 |
1812 std::ostringstream log_file_name; | 1755 std::ostringstream log_file_name; |
1813 PrepareLogFileName(log_file_name, isolate, FLAG_logfile); | 1756 PrepareLogFileName(log_file_name, isolate, FLAG_logfile); |
1814 log_->Initialize(log_file_name.str().c_str()); | 1757 log_->Initialize(log_file_name.str().c_str()); |
1815 | 1758 |
1816 | |
1817 if (FLAG_perf_basic_prof) { | 1759 if (FLAG_perf_basic_prof) { |
1818 perf_basic_logger_ = new PerfBasicLogger(); | 1760 perf_basic_logger_ = new PerfBasicLogger(); |
1819 addCodeEventListener(perf_basic_logger_); | 1761 addCodeEventListener(perf_basic_logger_); |
1820 } | 1762 } |
1821 | 1763 |
1822 if (FLAG_perf_prof) { | 1764 if (FLAG_perf_prof) { |
1823 perf_jit_logger_ = new PerfJitLogger(); | 1765 perf_jit_logger_ = new PerfJitLogger(); |
1824 addCodeEventListener(perf_jit_logger_); | 1766 addCodeEventListener(perf_jit_logger_); |
1825 } | 1767 } |
1826 | 1768 |
1827 if (FLAG_ll_prof) { | 1769 if (FLAG_ll_prof) { |
1828 ll_logger_ = new LowLevelLogger(log_file_name.str().c_str()); | 1770 ll_logger_ = new LowLevelLogger(log_file_name.str().c_str()); |
1829 addCodeEventListener(ll_logger_); | 1771 addCodeEventListener(ll_logger_); |
1830 } | 1772 } |
1831 | 1773 |
1832 ticker_ = new Ticker(isolate, kSamplingIntervalMs); | 1774 ticker_ = new Ticker(isolate, kSamplingIntervalMs); |
1833 | 1775 |
1834 if (Log::InitLogAtStart()) { | 1776 if (Log::InitLogAtStart()) { |
1835 is_logging_ = true; | 1777 is_logging_ = true; |
1836 } | 1778 } |
1837 | 1779 |
1838 if (FLAG_log_internal_timer_events || FLAG_prof_cpp) timer_.Start(); | 1780 if (FLAG_log_internal_timer_events || FLAG_prof_cpp) timer_.Start(); |
1839 | 1781 |
1840 if (FLAG_prof_cpp) { | 1782 if (FLAG_prof_cpp) { |
1841 profiler_ = new Profiler(isolate); | 1783 profiler_ = new Profiler(isolate); |
1842 is_logging_ = true; | 1784 is_logging_ = true; |
1843 profiler_->Engage(); | 1785 profiler_->Engage(); |
1844 } | 1786 } |
1845 | 1787 |
| 1788 if (is_logging_) { |
| 1789 addCodeEventListener(this); |
| 1790 } |
| 1791 |
1846 return true; | 1792 return true; |
1847 } | 1793 } |
1848 | 1794 |
1849 | 1795 |
1850 void Logger::SetCodeEventHandler(uint32_t options, | 1796 void Logger::SetCodeEventHandler(uint32_t options, |
1851 JitCodeEventHandler event_handler) { | 1797 JitCodeEventHandler event_handler) { |
1852 if (jit_logger_) { | 1798 if (jit_logger_) { |
1853 removeCodeEventListener(jit_logger_); | 1799 removeCodeEventListener(jit_logger_); |
1854 delete jit_logger_; | 1800 delete jit_logger_; |
1855 jit_logger_ = NULL; | 1801 jit_logger_ = NULL; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1908 removeCodeEventListener(jit_logger_); | 1854 removeCodeEventListener(jit_logger_); |
1909 delete jit_logger_; | 1855 delete jit_logger_; |
1910 jit_logger_ = NULL; | 1856 jit_logger_ = NULL; |
1911 } | 1857 } |
1912 | 1858 |
1913 return log_->Close(); | 1859 return log_->Close(); |
1914 } | 1860 } |
1915 | 1861 |
1916 } // namespace internal | 1862 } // namespace internal |
1917 } // namespace v8 | 1863 } // namespace v8 |
OLD | NEW |