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 <memory> |
8 #include <sstream> | 9 #include <sstream> |
9 | 10 |
10 #include "src/bailout-reason.h" | 11 #include "src/bailout-reason.h" |
11 #include "src/base/platform/platform.h" | 12 #include "src/base/platform/platform.h" |
12 #include "src/bootstrapper.h" | 13 #include "src/bootstrapper.h" |
13 #include "src/code-stubs.h" | 14 #include "src/code-stubs.h" |
14 #include "src/counters.h" | 15 #include "src/counters.h" |
15 #include "src/deoptimizer.h" | 16 #include "src/deoptimizer.h" |
16 #include "src/global-handles.h" | 17 #include "src/global-handles.h" |
17 #include "src/interpreter/bytecodes.h" | 18 #include "src/interpreter/bytecodes.h" |
(...skipping 948 matching lines...) Loading... |
966 msg.WriteToLogFile(); | 967 msg.WriteToLogFile(); |
967 } | 968 } |
968 | 969 |
969 | 970 |
970 void Logger::ApiNamedPropertyAccess(const char* tag, | 971 void Logger::ApiNamedPropertyAccess(const char* tag, |
971 JSObject* holder, | 972 JSObject* holder, |
972 Object* name) { | 973 Object* name) { |
973 DCHECK(name->IsName()); | 974 DCHECK(name->IsName()); |
974 if (!log_->IsEnabled() || !FLAG_log_api) return; | 975 if (!log_->IsEnabled() || !FLAG_log_api) return; |
975 String* class_name_obj = holder->class_name(); | 976 String* class_name_obj = holder->class_name(); |
976 base::SmartArrayPointer<char> class_name = | 977 std::unique_ptr<char[]> class_name = |
977 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 978 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
978 if (name->IsString()) { | 979 if (name->IsString()) { |
979 base::SmartArrayPointer<char> property_name = | 980 std::unique_ptr<char[]> property_name = |
980 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 981 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
981 ApiEvent("api,%s,\"%s\",\"%s\"", tag, class_name.get(), | 982 ApiEvent("api,%s,\"%s\",\"%s\"", tag, class_name.get(), |
982 property_name.get()); | 983 property_name.get()); |
983 } else { | 984 } else { |
984 Symbol* symbol = Symbol::cast(name); | 985 Symbol* symbol = Symbol::cast(name); |
985 uint32_t hash = symbol->Hash(); | 986 uint32_t hash = symbol->Hash(); |
986 if (symbol->name()->IsUndefined(symbol->GetIsolate())) { | 987 if (symbol->name()->IsUndefined(symbol->GetIsolate())) { |
987 ApiEvent("api,%s,\"%s\",symbol(hash %x)", tag, class_name.get(), hash); | 988 ApiEvent("api,%s,\"%s\",symbol(hash %x)", tag, class_name.get(), hash); |
988 } else { | 989 } else { |
989 base::SmartArrayPointer<char> str = | 990 std::unique_ptr<char[]> str = |
990 String::cast(symbol->name()) | 991 String::cast(symbol->name()) |
991 ->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 992 ->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
992 ApiEvent("api,%s,\"%s\",symbol(\"%s\" hash %x)", tag, class_name.get(), | 993 ApiEvent("api,%s,\"%s\",symbol(\"%s\" hash %x)", tag, class_name.get(), |
993 str.get(), hash); | 994 str.get(), hash); |
994 } | 995 } |
995 } | 996 } |
996 } | 997 } |
997 | 998 |
998 void Logger::ApiIndexedPropertyAccess(const char* tag, | 999 void Logger::ApiIndexedPropertyAccess(const char* tag, |
999 JSObject* holder, | 1000 JSObject* holder, |
1000 uint32_t index) { | 1001 uint32_t index) { |
1001 if (!log_->IsEnabled() || !FLAG_log_api) return; | 1002 if (!log_->IsEnabled() || !FLAG_log_api) return; |
1002 String* class_name_obj = holder->class_name(); | 1003 String* class_name_obj = holder->class_name(); |
1003 base::SmartArrayPointer<char> class_name = | 1004 std::unique_ptr<char[]> class_name = |
1004 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1005 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
1005 ApiEvent("api,%s,\"%s\",%u", tag, class_name.get(), index); | 1006 ApiEvent("api,%s,\"%s\",%u", tag, class_name.get(), index); |
1006 } | 1007 } |
1007 | 1008 |
1008 | 1009 |
1009 void Logger::ApiObjectAccess(const char* tag, JSObject* object) { | 1010 void Logger::ApiObjectAccess(const char* tag, JSObject* object) { |
1010 if (!log_->IsEnabled() || !FLAG_log_api) return; | 1011 if (!log_->IsEnabled() || !FLAG_log_api) return; |
1011 String* class_name_obj = object->class_name(); | 1012 String* class_name_obj = object->class_name(); |
1012 base::SmartArrayPointer<char> class_name = | 1013 std::unique_ptr<char[]> class_name = |
1013 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1014 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
1014 ApiEvent("api,%s,\"%s\"", tag, class_name.get()); | 1015 ApiEvent("api,%s,\"%s\"", tag, class_name.get()); |
1015 } | 1016 } |
1016 | 1017 |
1017 | 1018 |
1018 void Logger::ApiEntryCall(const char* name) { | 1019 void Logger::ApiEntryCall(const char* name) { |
1019 if (!log_->IsEnabled() || !FLAG_log_api) return; | 1020 if (!log_->IsEnabled() || !FLAG_log_api) return; |
1020 ApiEvent("api,%s", name); | 1021 ApiEvent("api,%s", name); |
1021 } | 1022 } |
1022 | 1023 |
(...skipping 16 matching lines...) Loading... |
1039 | 1040 |
1040 void Logger::CallbackEventInternal(const char* prefix, Name* name, | 1041 void Logger::CallbackEventInternal(const char* prefix, Name* name, |
1041 Address entry_point) { | 1042 Address entry_point) { |
1042 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1043 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1043 Log::MessageBuilder msg(log_); | 1044 Log::MessageBuilder msg(log_); |
1044 msg.Append("%s,%s,-2,", | 1045 msg.Append("%s,%s,-2,", |
1045 kLogEventsNames[CodeEventListener::CODE_CREATION_EVENT], | 1046 kLogEventsNames[CodeEventListener::CODE_CREATION_EVENT], |
1046 kLogEventsNames[CodeEventListener::CALLBACK_TAG]); | 1047 kLogEventsNames[CodeEventListener::CALLBACK_TAG]); |
1047 msg.AppendAddress(entry_point); | 1048 msg.AppendAddress(entry_point); |
1048 if (name->IsString()) { | 1049 if (name->IsString()) { |
1049 base::SmartArrayPointer<char> str = | 1050 std::unique_ptr<char[]> str = |
1050 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1051 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
1051 msg.Append(",1,\"%s%s\"", prefix, str.get()); | 1052 msg.Append(",1,\"%s%s\"", prefix, str.get()); |
1052 } else { | 1053 } else { |
1053 Symbol* symbol = Symbol::cast(name); | 1054 Symbol* symbol = Symbol::cast(name); |
1054 if (symbol->name()->IsUndefined(symbol->GetIsolate())) { | 1055 if (symbol->name()->IsUndefined(symbol->GetIsolate())) { |
1055 msg.Append(",1,symbol(hash %x)", symbol->Hash()); | 1056 msg.Append(",1,symbol(hash %x)", symbol->Hash()); |
1056 } else { | 1057 } else { |
1057 base::SmartArrayPointer<char> str = | 1058 std::unique_ptr<char[]> str = |
1058 String::cast(symbol->name()) | 1059 String::cast(symbol->name()) |
1059 ->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1060 ->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
1060 msg.Append(",1,symbol(\"%s%s\" hash %x)", prefix, str.get(), | 1061 msg.Append(",1,symbol(\"%s%s\" hash %x)", prefix, str.get(), |
1061 symbol->Hash()); | 1062 symbol->Hash()); |
1062 } | 1063 } |
1063 } | 1064 } |
1064 msg.WriteToLogFile(); | 1065 msg.WriteToLogFile(); |
1065 } | 1066 } |
1066 | 1067 |
1067 | 1068 |
(...skipping 54 matching lines...) Loading... |
1122 if (!is_logging_code_events()) return; | 1123 if (!is_logging_code_events()) return; |
1123 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1124 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1124 if (code == AbstractCode::cast( | 1125 if (code == AbstractCode::cast( |
1125 isolate_->builtins()->builtin(Builtins::kCompileLazy))) { | 1126 isolate_->builtins()->builtin(Builtins::kCompileLazy))) { |
1126 return; | 1127 return; |
1127 } | 1128 } |
1128 | 1129 |
1129 Log::MessageBuilder msg(log_); | 1130 Log::MessageBuilder msg(log_); |
1130 AppendCodeCreateHeader(&msg, tag, code); | 1131 AppendCodeCreateHeader(&msg, tag, code); |
1131 if (name->IsString()) { | 1132 if (name->IsString()) { |
1132 base::SmartArrayPointer<char> str = | 1133 std::unique_ptr<char[]> str = |
1133 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1134 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
1134 msg.Append("\"%s\"", str.get()); | 1135 msg.Append("\"%s\"", str.get()); |
1135 } else { | 1136 } else { |
1136 msg.AppendSymbolName(Symbol::cast(name)); | 1137 msg.AppendSymbolName(Symbol::cast(name)); |
1137 } | 1138 } |
1138 msg.Append(','); | 1139 msg.Append(','); |
1139 msg.AppendAddress(shared->address()); | 1140 msg.AppendAddress(shared->address()); |
1140 msg.Append(",%s", ComputeMarker(shared, code)); | 1141 msg.Append(",%s", ComputeMarker(shared, code)); |
1141 msg.WriteToLogFile(); | 1142 msg.WriteToLogFile(); |
1142 } | 1143 } |
1143 | 1144 |
1144 | 1145 |
1145 // Although, it is possible to extract source and line from | 1146 // Although, it is possible to extract source and line from |
1146 // the SharedFunctionInfo object, we left it to caller | 1147 // the SharedFunctionInfo object, we left it to caller |
1147 // to leave logging functions free from heap allocations. | 1148 // to leave logging functions free from heap allocations. |
1148 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, | 1149 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
1149 AbstractCode* code, SharedFunctionInfo* shared, | 1150 AbstractCode* code, SharedFunctionInfo* shared, |
1150 Name* source, int line, int column) { | 1151 Name* source, int line, int column) { |
1151 if (!is_logging_code_events()) return; | 1152 if (!is_logging_code_events()) return; |
1152 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1153 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1153 Log::MessageBuilder msg(log_); | 1154 Log::MessageBuilder msg(log_); |
1154 AppendCodeCreateHeader(&msg, tag, code); | 1155 AppendCodeCreateHeader(&msg, tag, code); |
1155 base::SmartArrayPointer<char> name = | 1156 std::unique_ptr<char[]> name = |
1156 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1157 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
1157 msg.Append("\"%s ", name.get()); | 1158 msg.Append("\"%s ", name.get()); |
1158 if (source->IsString()) { | 1159 if (source->IsString()) { |
1159 base::SmartArrayPointer<char> sourcestr = String::cast(source)->ToCString( | 1160 std::unique_ptr<char[]> sourcestr = String::cast(source)->ToCString( |
1160 DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1161 DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
1161 msg.Append("%s", sourcestr.get()); | 1162 msg.Append("%s", sourcestr.get()); |
1162 } else { | 1163 } else { |
1163 msg.AppendSymbolName(Symbol::cast(source)); | 1164 msg.AppendSymbolName(Symbol::cast(source)); |
1164 } | 1165 } |
1165 msg.Append(":%d:%d\",", line, column); | 1166 msg.Append(":%d:%d\",", line, column); |
1166 msg.AppendAddress(shared->address()); | 1167 msg.AppendAddress(shared->address()); |
1167 msg.Append(",%s", ComputeMarker(shared, code)); | 1168 msg.Append(",%s", ComputeMarker(shared, code)); |
1168 msg.WriteToLogFile(); | 1169 msg.WriteToLogFile(); |
1169 } | 1170 } |
1170 | 1171 |
1171 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, | 1172 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
1172 AbstractCode* code, int args_count) { | 1173 AbstractCode* code, int args_count) { |
1173 if (!is_logging_code_events()) return; | 1174 if (!is_logging_code_events()) return; |
1174 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1175 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1175 Log::MessageBuilder msg(log_); | 1176 Log::MessageBuilder msg(log_); |
1176 AppendCodeCreateHeader(&msg, tag, code); | 1177 AppendCodeCreateHeader(&msg, tag, code); |
1177 msg.Append("\"args_count: %d\"", args_count); | 1178 msg.Append("\"args_count: %d\"", args_count); |
1178 msg.WriteToLogFile(); | 1179 msg.WriteToLogFile(); |
1179 } | 1180 } |
1180 | 1181 |
1181 void Logger::CodeDisableOptEvent(AbstractCode* code, | 1182 void Logger::CodeDisableOptEvent(AbstractCode* code, |
1182 SharedFunctionInfo* shared) { | 1183 SharedFunctionInfo* shared) { |
1183 if (!is_logging_code_events()) return; | 1184 if (!is_logging_code_events()) return; |
1184 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1185 if (!FLAG_log_code || !log_->IsEnabled()) return; |
1185 Log::MessageBuilder msg(log_); | 1186 Log::MessageBuilder msg(log_); |
1186 msg.Append("%s,", kLogEventsNames[CodeEventListener::CODE_DISABLE_OPT_EVENT]); | 1187 msg.Append("%s,", kLogEventsNames[CodeEventListener::CODE_DISABLE_OPT_EVENT]); |
1187 base::SmartArrayPointer<char> name = | 1188 std::unique_ptr<char[]> name = |
1188 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1189 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
1189 msg.Append("\"%s\",", name.get()); | 1190 msg.Append("\"%s\",", name.get()); |
1190 msg.Append("\"%s\"", GetBailoutReason(shared->disable_optimization_reason())); | 1191 msg.Append("\"%s\"", GetBailoutReason(shared->disable_optimization_reason())); |
1191 msg.WriteToLogFile(); | 1192 msg.WriteToLogFile(); |
1192 } | 1193 } |
1193 | 1194 |
1194 | 1195 |
1195 void Logger::CodeMovingGCEvent() { | 1196 void Logger::CodeMovingGCEvent() { |
1196 if (!is_logging_code_events()) return; | 1197 if (!is_logging_code_events()) return; |
1197 if (!log_->IsEnabled() || !FLAG_ll_prof) return; | 1198 if (!log_->IsEnabled() || !FLAG_ll_prof) return; |
(...skipping 671 matching lines...) Loading... |
1869 | 1870 |
1870 if (profiler_listener_.get() != nullptr) { | 1871 if (profiler_listener_.get() != nullptr) { |
1871 removeCodeEventListener(profiler_listener_.get()); | 1872 removeCodeEventListener(profiler_listener_.get()); |
1872 } | 1873 } |
1873 | 1874 |
1874 return log_->Close(); | 1875 return log_->Close(); |
1875 } | 1876 } |
1876 | 1877 |
1877 } // namespace internal | 1878 } // namespace internal |
1878 } // namespace v8 | 1879 } // namespace v8 |
OLD | NEW |