Chromium Code Reviews| 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 <memory> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 | 10 |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 836 uintptr_t start, uintptr_t end, | 836 uintptr_t start, uintptr_t end, |
| 837 intptr_t aslr_slide) { | 837 intptr_t aslr_slide) { |
| 838 if (!log_->IsEnabled() || !FLAG_prof_cpp) return; | 838 if (!log_->IsEnabled() || !FLAG_prof_cpp) return; |
| 839 Log::MessageBuilder msg(log_); | 839 Log::MessageBuilder msg(log_); |
| 840 msg.Append("shared-library,\"%s\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR | 840 msg.Append("shared-library,\"%s\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR |
| 841 ",%" V8PRIdPTR, | 841 ",%" V8PRIdPTR, |
| 842 library_path.c_str(), start, end, aslr_slide); | 842 library_path.c_str(), start, end, aslr_slide); |
| 843 msg.WriteToLogFile(); | 843 msg.WriteToLogFile(); |
| 844 } | 844 } |
| 845 | 845 |
| 846 | 846 void Logger::CodeDeoptEvent(DeoptKind kind, Code* code, Address pc, |
| 847 void Logger::CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta) { | 847 int fp_to_sp_delta) { |
| 848 if (!log_->IsEnabled() || !FLAG_log_internal_timer_events) return; | 848 if (!log_->IsEnabled()) return; |
| 849 Deoptimizer::DeoptInfo info = Deoptimizer::GetDeoptInfo(code, pc); | |
| 849 Log::MessageBuilder msg(log_); | 850 Log::MessageBuilder msg(log_); |
| 850 int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds()); | 851 int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds()); |
| 851 msg.Append("code-deopt,%d,%d", since_epoch, code->CodeSize()); | 852 msg.Append("code-deopt,%d,%d,", since_epoch, code->CodeSize()); |
| 853 msg.AppendAddress(code->address()); | |
| 854 | |
| 855 // Deoptimization position. | |
| 856 std::ostringstream deopt_location; | |
| 857 int inlining_id = -1; | |
| 858 int script_offset = -1; | |
| 859 if (info.position.IsKnown()) { | |
| 860 info.position.Print(deopt_location, code); | |
| 861 inlining_id = info.position.InliningId(); | |
| 862 script_offset = info.position.ScriptOffset(); | |
| 863 } else { | |
| 864 deopt_location << "<unknown>"; | |
| 865 } | |
| 866 msg.Append(",%d,%d,", inlining_id, script_offset); | |
| 867 switch (kind) { | |
| 868 case kLazy: | |
| 869 msg.Append("\"lazy\","); | |
| 870 break; | |
| 871 case kSoft: | |
| 872 msg.Append("\"soft\","); | |
| 873 break; | |
| 874 case kEager: | |
| 875 msg.Append("\"eager\","); | |
| 876 break; | |
| 877 } | |
| 878 msg.AppendDoubleQuotedString(deopt_location.str().c_str()); | |
| 879 msg.Append(","); | |
| 880 msg.AppendDoubleQuotedString(DeoptimizeReasonToString(info.deopt_reason)); | |
| 852 msg.WriteToLogFile(); | 881 msg.WriteToLogFile(); |
| 853 } | 882 } |
| 854 | 883 |
| 855 | 884 |
| 856 void Logger::CurrentTimeEvent() { | 885 void Logger::CurrentTimeEvent() { |
| 857 if (!log_->IsEnabled()) return; | 886 if (!log_->IsEnabled()) return; |
| 858 DCHECK(FLAG_log_timer_events || FLAG_prof_cpp); | 887 DCHECK(FLAG_log_timer_events || FLAG_prof_cpp); |
| 859 Log::MessageBuilder msg(log_); | 888 Log::MessageBuilder msg(log_); |
| 860 int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds()); | 889 int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds()); |
| 861 msg.Append("current-time,%d", since_epoch); | 890 msg.Append("current-time,%d", since_epoch); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 965 } | 994 } |
| 966 | 995 |
| 967 | 996 |
| 968 void Logger::CallbackEventInternal(const char* prefix, Name* name, | 997 void Logger::CallbackEventInternal(const char* prefix, Name* name, |
| 969 Address entry_point) { | 998 Address entry_point) { |
| 970 if (!FLAG_log_code || !log_->IsEnabled()) return; | 999 if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 971 Log::MessageBuilder msg(log_); | 1000 Log::MessageBuilder msg(log_); |
| 972 msg.Append("%s,%s,-2,", | 1001 msg.Append("%s,%s,-2,", |
| 973 kLogEventsNames[CodeEventListener::CODE_CREATION_EVENT], | 1002 kLogEventsNames[CodeEventListener::CODE_CREATION_EVENT], |
| 974 kLogEventsNames[CodeEventListener::CALLBACK_TAG]); | 1003 kLogEventsNames[CodeEventListener::CALLBACK_TAG]); |
| 1004 if (timer_.IsStarted()) { | |
| 1005 msg.Append("%d,", static_cast<int>(timer_.Elapsed().InMicroseconds())); | |
| 1006 } else { | |
| 1007 msg.Append("-1,"); | |
| 1008 } | |
| 975 msg.AppendAddress(entry_point); | 1009 msg.AppendAddress(entry_point); |
| 976 if (name->IsString()) { | 1010 if (name->IsString()) { |
| 977 std::unique_ptr<char[]> str = | 1011 std::unique_ptr<char[]> str = |
| 978 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1012 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 979 msg.Append(",1,\"%s%s\"", prefix, str.get()); | 1013 msg.Append(",1,\"%s%s\"", prefix, str.get()); |
| 980 } else { | 1014 } else { |
| 981 Symbol* symbol = Symbol::cast(name); | 1015 Symbol* symbol = Symbol::cast(name); |
| 982 if (symbol->name()->IsUndefined(symbol->GetIsolate())) { | 1016 if (symbol->name()->IsUndefined(symbol->GetIsolate())) { |
| 983 msg.Append(",1,symbol(hash %x)", symbol->Hash()); | 1017 msg.Append(",1,symbol(hash %x)", symbol->Hash()); |
| 984 } else { | 1018 } else { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1000 | 1034 |
| 1001 void Logger::GetterCallbackEvent(Name* name, Address entry_point) { | 1035 void Logger::GetterCallbackEvent(Name* name, Address entry_point) { |
| 1002 CallbackEventInternal("get ", name, entry_point); | 1036 CallbackEventInternal("get ", name, entry_point); |
| 1003 } | 1037 } |
| 1004 | 1038 |
| 1005 | 1039 |
| 1006 void Logger::SetterCallbackEvent(Name* name, Address entry_point) { | 1040 void Logger::SetterCallbackEvent(Name* name, Address entry_point) { |
| 1007 CallbackEventInternal("set ", name, entry_point); | 1041 CallbackEventInternal("set ", name, entry_point); |
| 1008 } | 1042 } |
| 1009 | 1043 |
| 1010 static void AppendCodeCreateHeader(Log::MessageBuilder* msg, | 1044 namespace { |
| 1011 CodeEventListener::LogEventsAndTags tag, | 1045 |
| 1012 AbstractCode* code) { | 1046 void AppendCodeCreateHeader(Log::MessageBuilder* msg, |
| 1047 CodeEventListener::LogEventsAndTags tag, | |
| 1048 AbstractCode* code, base::ElapsedTimer* timer) { | |
| 1013 DCHECK(msg); | 1049 DCHECK(msg); |
| 1014 msg->Append("%s,%s,%d,", | 1050 msg->Append("%s,%s,%d,", |
| 1015 kLogEventsNames[CodeEventListener::CODE_CREATION_EVENT], | 1051 kLogEventsNames[CodeEventListener::CODE_CREATION_EVENT], |
| 1016 kLogEventsNames[tag], code->kind()); | 1052 kLogEventsNames[tag], code->kind()); |
| 1053 int timestamp = timer->IsStarted() | |
|
Leszek Swirski
2017/03/21 14:28:39
nit: inconsistent use of if blocks vs. ternary ope
| |
| 1054 ? static_cast<int>(timer->Elapsed().InMicroseconds()) | |
| 1055 : -1; | |
| 1056 msg->Append("%d,", timestamp); | |
| 1017 msg->AppendAddress(code->address()); | 1057 msg->AppendAddress(code->address()); |
| 1018 msg->Append(",%d,", code->ExecutableSize()); | 1058 msg->Append(",%d,", code->ExecutableSize()); |
| 1019 } | 1059 } |
| 1020 | 1060 |
| 1061 } // namespace | |
| 1062 | |
| 1021 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, | 1063 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
| 1022 AbstractCode* code, const char* comment) { | 1064 AbstractCode* code, const char* comment) { |
| 1023 if (!is_logging_code_events()) return; | 1065 if (!is_logging_code_events()) return; |
| 1024 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1066 if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 1025 Log::MessageBuilder msg(log_); | 1067 Log::MessageBuilder msg(log_); |
| 1026 AppendCodeCreateHeader(&msg, tag, code); | 1068 AppendCodeCreateHeader(&msg, tag, code, &timer_); |
| 1027 msg.AppendDoubleQuotedString(comment); | 1069 msg.AppendDoubleQuotedString(comment); |
| 1028 msg.WriteToLogFile(); | 1070 msg.WriteToLogFile(); |
| 1029 } | 1071 } |
| 1030 | 1072 |
| 1031 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, | 1073 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
| 1032 AbstractCode* code, Name* name) { | 1074 AbstractCode* code, Name* name) { |
| 1033 if (!is_logging_code_events()) return; | 1075 if (!is_logging_code_events()) return; |
| 1034 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1076 if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 1035 Log::MessageBuilder msg(log_); | 1077 Log::MessageBuilder msg(log_); |
| 1036 AppendCodeCreateHeader(&msg, tag, code); | 1078 AppendCodeCreateHeader(&msg, tag, code, &timer_); |
| 1037 if (name->IsString()) { | 1079 if (name->IsString()) { |
| 1038 msg.Append('"'); | 1080 msg.Append('"'); |
| 1039 msg.AppendDetailed(String::cast(name), false); | 1081 msg.AppendDetailed(String::cast(name), false); |
| 1040 msg.Append('"'); | 1082 msg.Append('"'); |
| 1041 } else { | 1083 } else { |
| 1042 msg.AppendSymbolName(Symbol::cast(name)); | 1084 msg.AppendSymbolName(Symbol::cast(name)); |
| 1043 } | 1085 } |
| 1044 msg.WriteToLogFile(); | 1086 msg.WriteToLogFile(); |
| 1045 } | 1087 } |
| 1046 | 1088 |
| 1047 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, | 1089 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
| 1048 AbstractCode* code, SharedFunctionInfo* shared, | 1090 AbstractCode* code, SharedFunctionInfo* shared, |
| 1049 Name* name) { | 1091 Name* name) { |
| 1050 if (!is_logging_code_events()) return; | 1092 if (!is_logging_code_events()) return; |
| 1051 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1093 if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 1052 if (code == AbstractCode::cast( | 1094 if (code == AbstractCode::cast( |
| 1053 isolate_->builtins()->builtin(Builtins::kCompileLazy))) { | 1095 isolate_->builtins()->builtin(Builtins::kCompileLazy))) { |
| 1054 return; | 1096 return; |
| 1055 } | 1097 } |
| 1056 | 1098 |
| 1057 Log::MessageBuilder msg(log_); | 1099 Log::MessageBuilder msg(log_); |
| 1058 AppendCodeCreateHeader(&msg, tag, code); | 1100 AppendCodeCreateHeader(&msg, tag, code, &timer_); |
| 1059 if (name->IsString()) { | 1101 if (name->IsString()) { |
| 1060 std::unique_ptr<char[]> str = | 1102 std::unique_ptr<char[]> str = |
| 1061 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1103 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 1062 msg.Append("\"%s\"", str.get()); | 1104 msg.Append("\"%s\"", str.get()); |
| 1063 } else { | 1105 } else { |
| 1064 msg.AppendSymbolName(Symbol::cast(name)); | 1106 msg.AppendSymbolName(Symbol::cast(name)); |
| 1065 } | 1107 } |
| 1066 msg.Append(','); | 1108 msg.Append(','); |
| 1067 msg.AppendAddress(shared->address()); | 1109 msg.AppendAddress(shared->address()); |
| 1068 msg.Append(",%s", ComputeMarker(shared, code)); | 1110 msg.Append(",%s", ComputeMarker(shared, code)); |
| 1069 msg.WriteToLogFile(); | 1111 msg.WriteToLogFile(); |
| 1070 } | 1112 } |
| 1071 | 1113 |
| 1072 | 1114 |
| 1073 // Although, it is possible to extract source and line from | 1115 // Although, it is possible to extract source and line from |
| 1074 // the SharedFunctionInfo object, we left it to caller | 1116 // the SharedFunctionInfo object, we left it to caller |
| 1075 // to leave logging functions free from heap allocations. | 1117 // to leave logging functions free from heap allocations. |
| 1076 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, | 1118 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
| 1077 AbstractCode* code, SharedFunctionInfo* shared, | 1119 AbstractCode* code, SharedFunctionInfo* shared, |
| 1078 Name* source, int line, int column) { | 1120 Name* source, int line, int column) { |
| 1079 if (!is_logging_code_events()) return; | 1121 if (!is_logging_code_events()) return; |
| 1080 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1122 if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 1081 Log::MessageBuilder msg(log_); | 1123 Log::MessageBuilder msg(log_); |
| 1082 AppendCodeCreateHeader(&msg, tag, code); | 1124 AppendCodeCreateHeader(&msg, tag, code, &timer_); |
| 1083 std::unique_ptr<char[]> name = | 1125 std::unique_ptr<char[]> name = |
| 1084 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1126 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 1085 msg.Append("\"%s ", name.get()); | 1127 msg.Append("\"%s ", name.get()); |
| 1086 if (source->IsString()) { | 1128 if (source->IsString()) { |
| 1087 std::unique_ptr<char[]> sourcestr = String::cast(source)->ToCString( | 1129 std::unique_ptr<char[]> sourcestr = String::cast(source)->ToCString( |
| 1088 DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1130 DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 1089 msg.Append("%s", sourcestr.get()); | 1131 msg.Append("%s", sourcestr.get()); |
| 1090 } else { | 1132 } else { |
| 1091 msg.AppendSymbolName(Symbol::cast(source)); | 1133 msg.AppendSymbolName(Symbol::cast(source)); |
| 1092 } | 1134 } |
| 1093 msg.Append(":%d:%d\",", line, column); | 1135 msg.Append(":%d:%d\",", line, column); |
| 1094 msg.AppendAddress(shared->address()); | 1136 msg.AppendAddress(shared->address()); |
| 1095 msg.Append(",%s", ComputeMarker(shared, code)); | 1137 msg.Append(",%s", ComputeMarker(shared, code)); |
| 1096 msg.WriteToLogFile(); | 1138 msg.WriteToLogFile(); |
| 1097 } | 1139 } |
| 1098 | 1140 |
| 1099 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, | 1141 void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, |
| 1100 AbstractCode* code, int args_count) { | 1142 AbstractCode* code, int args_count) { |
| 1101 if (!is_logging_code_events()) return; | 1143 if (!is_logging_code_events()) return; |
| 1102 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1144 if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 1103 Log::MessageBuilder msg(log_); | 1145 Log::MessageBuilder msg(log_); |
| 1104 AppendCodeCreateHeader(&msg, tag, code); | 1146 AppendCodeCreateHeader(&msg, tag, code, &timer_); |
| 1105 msg.Append("\"args_count: %d\"", args_count); | 1147 msg.Append("\"args_count: %d\"", args_count); |
| 1106 msg.WriteToLogFile(); | 1148 msg.WriteToLogFile(); |
| 1107 } | 1149 } |
| 1108 | 1150 |
| 1109 void Logger::CodeDisableOptEvent(AbstractCode* code, | 1151 void Logger::CodeDisableOptEvent(AbstractCode* code, |
| 1110 SharedFunctionInfo* shared) { | 1152 SharedFunctionInfo* shared) { |
| 1111 if (!is_logging_code_events()) return; | 1153 if (!is_logging_code_events()) return; |
| 1112 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1154 if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 1113 Log::MessageBuilder msg(log_); | 1155 Log::MessageBuilder msg(log_); |
| 1114 msg.Append("%s,", kLogEventsNames[CodeEventListener::CODE_DISABLE_OPT_EVENT]); | 1156 msg.Append("%s,", kLogEventsNames[CodeEventListener::CODE_DISABLE_OPT_EVENT]); |
| 1115 std::unique_ptr<char[]> name = | 1157 std::unique_ptr<char[]> name = |
| 1116 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1158 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 1117 msg.Append("\"%s\",", name.get()); | 1159 msg.Append("\"%s\",", name.get()); |
| 1118 msg.Append("\"%s\"", GetBailoutReason(shared->disable_optimization_reason())); | 1160 msg.Append("\"%s\"", GetBailoutReason(shared->disable_optimization_reason())); |
| 1119 msg.WriteToLogFile(); | 1161 msg.WriteToLogFile(); |
| 1120 } | 1162 } |
| 1121 | 1163 |
| 1122 | 1164 |
| 1123 void Logger::CodeMovingGCEvent() { | 1165 void Logger::CodeMovingGCEvent() { |
| 1124 if (!is_logging_code_events()) return; | 1166 if (!is_logging_code_events()) return; |
| 1125 if (!log_->IsEnabled() || !FLAG_ll_prof) return; | 1167 if (!log_->IsEnabled() || !FLAG_ll_prof) return; |
| 1126 base::OS::SignalCodeMovingGC(); | 1168 base::OS::SignalCodeMovingGC(); |
| 1127 } | 1169 } |
| 1128 | 1170 |
| 1129 void Logger::RegExpCodeCreateEvent(AbstractCode* code, String* source) { | 1171 void Logger::RegExpCodeCreateEvent(AbstractCode* code, String* source) { |
| 1130 if (!is_logging_code_events()) return; | 1172 if (!is_logging_code_events()) return; |
| 1131 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1173 if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 1132 Log::MessageBuilder msg(log_); | 1174 Log::MessageBuilder msg(log_); |
| 1133 AppendCodeCreateHeader(&msg, CodeEventListener::REG_EXP_TAG, code); | 1175 AppendCodeCreateHeader(&msg, CodeEventListener::REG_EXP_TAG, code, &timer_); |
| 1134 msg.Append('"'); | 1176 msg.Append('"'); |
| 1135 msg.AppendDetailed(source, false); | 1177 msg.AppendDetailed(source, false); |
| 1136 msg.Append('"'); | 1178 msg.Append('"'); |
| 1137 msg.WriteToLogFile(); | 1179 msg.WriteToLogFile(); |
| 1138 } | 1180 } |
| 1139 | 1181 |
| 1140 void Logger::CodeMoveEvent(AbstractCode* from, Address to) { | 1182 void Logger::CodeMoveEvent(AbstractCode* from, Address to) { |
| 1141 if (!is_logging_code_events()) return; | 1183 if (!is_logging_code_events()) return; |
| 1142 MoveEventInternal(CodeEventListener::CODE_MOVE_EVENT, from->address(), to); | 1184 MoveEventInternal(CodeEventListener::CODE_MOVE_EVENT, from->address(), to); |
| 1143 } | 1185 } |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1856 | 1898 |
| 1857 if (profiler_listener_.get() != nullptr) { | 1899 if (profiler_listener_.get() != nullptr) { |
| 1858 removeCodeEventListener(profiler_listener_.get()); | 1900 removeCodeEventListener(profiler_listener_.get()); |
| 1859 } | 1901 } |
| 1860 | 1902 |
| 1861 return log_->Close(); | 1903 return log_->Close(); |
| 1862 } | 1904 } |
| 1863 | 1905 |
| 1864 } // namespace internal | 1906 } // namespace internal |
| 1865 } // namespace v8 | 1907 } // namespace v8 |
| OLD | NEW |