Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: src/log.cc

Issue 16917008: CPUProfiler: remove copy&paste from CodeCreateEvent. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/log.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 CallbackEventInternal("get ", name, entry_point); 896 CallbackEventInternal("get ", name, entry_point);
897 } 897 }
898 898
899 899
900 void Logger::SetterCallbackEvent(Name* name, Address entry_point) { 900 void Logger::SetterCallbackEvent(Name* name, Address entry_point) {
901 if (!log_->IsEnabled() || !FLAG_log_code) return; 901 if (!log_->IsEnabled() || !FLAG_log_code) return;
902 CallbackEventInternal("set ", name, entry_point); 902 CallbackEventInternal("set ", name, entry_point);
903 } 903 }
904 904
905 905
906 void Logger::CodeCreateEvent(LogEventsAndTags tag, 906 void Logger::AppendName(Name* name) {
907 Code* code, 907 if (name->IsString()) {
908 const char* comment) { 908 name_buffer_->AppendString(String::cast(name));
909 if (!is_logging_code_events()) return; 909 } else {
910 if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) { 910 Symbol* symbol = Symbol::cast(name);
911 name_buffer_->AppendBytes("symbol(");
912 if (!symbol->name()->IsUndefined()) {
913 name_buffer_->AppendBytes("\"");
914 name_buffer_->AppendString(String::cast(symbol->name()));
915 name_buffer_->AppendBytes("\" ");
916 }
917 name_buffer_->AppendBytes("hash ");
918 name_buffer_->AppendHex(symbol->Hash());
919 name_buffer_->AppendByte(')');
920 }
921 }
922
923
924 void Logger::InitNameBuffer(LogEventsAndTags tag) {
911 name_buffer_->Reset(); 925 name_buffer_->Reset();
912 name_buffer_->AppendBytes(kLogEventsNames[tag]); 926 name_buffer_->AppendBytes(kLogEventsNames[tag]);
913 name_buffer_->AppendByte(':'); 927 name_buffer_->AppendByte(':');
914 name_buffer_->AppendBytes(comment); 928 }
915 } 929
930
931 void Logger::LogRecordedBuffer(Code* code, SharedFunctionInfo* shared) {
916 if (code_event_handler_ != NULL) { 932 if (code_event_handler_ != NULL) {
917 IssueCodeAddedEvent(code, NULL, name_buffer_->get(), name_buffer_->size()); 933 Script* script = shared && shared->script()->IsScript() ?
934 Script::cast(shared->script()) : NULL;
935 IssueCodeAddedEvent(code,
936 script,
937 name_buffer_->get(),
938 name_buffer_->size());
918 } 939 }
919 if (!log_->IsEnabled()) return; 940 if (!log_->IsEnabled()) return;
920 if (FLAG_ll_prof) { 941 if (FLAG_ll_prof) {
921 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size()); 942 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size());
922 } 943 }
923 if (Serializer::enabled()) { 944 if (Serializer::enabled()) {
924 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size()); 945 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size());
925 } 946 }
926 if (!FLAG_log_code) return; 947 }
948
949
950 void Logger::CodeCreateEvent(LogEventsAndTags tag,
951 Code* code,
952 const char* comment) {
953 if (!is_logging_code_events()) return;
954 if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) {
955 InitNameBuffer(tag);
956 name_buffer_->AppendBytes(comment);
957 LogRecordedBuffer(code, NULL);
958 }
959
960 if (!FLAG_log_code || !log_->IsEnabled()) return;
927 LogMessageBuilder msg(this); 961 LogMessageBuilder msg(this);
928 msg.Append("%s,%s,%d,", 962 msg.Append("%s,%s,%d,",
929 kLogEventsNames[CODE_CREATION_EVENT], 963 kLogEventsNames[CODE_CREATION_EVENT],
930 kLogEventsNames[tag], 964 kLogEventsNames[tag],
931 code->kind()); 965 code->kind());
932 msg.AppendAddress(code->address()); 966 msg.AppendAddress(code->address());
933 msg.Append(",%d,\"", code->ExecutableSize()); 967 msg.Append(",%d,\"", code->ExecutableSize());
934 for (const char* p = comment; *p != '\0'; p++) { 968 for (const char* p = comment; *p != '\0'; p++) {
935 if (*p == '"') { 969 if (*p == '"') {
936 msg.Append('\\'); 970 msg.Append('\\');
937 } 971 }
938 msg.Append(*p); 972 msg.Append(*p);
939 } 973 }
940 msg.Append('"'); 974 msg.Append('"');
941 msg.Append('\n'); 975 msg.Append('\n');
942 msg.WriteToLogFile(); 976 msg.WriteToLogFile();
943 } 977 }
944 978
945 979
946 void Logger::CodeCreateEvent(LogEventsAndTags tag, 980 void Logger::CodeCreateEvent(LogEventsAndTags tag,
947 Code* code, 981 Code* code,
948 Name* name) { 982 Name* name) {
949 if (!is_logging_code_events()) return; 983 if (!is_logging_code_events()) return;
950 if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) { 984 if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) {
951 name_buffer_->Reset(); 985 InitNameBuffer(tag);
952 name_buffer_->AppendBytes(kLogEventsNames[tag]); 986 AppendName(name);
953 name_buffer_->AppendByte(':'); 987 LogRecordedBuffer(code, NULL);
954 if (name->IsString()) {
955 name_buffer_->AppendString(String::cast(name));
956 } else {
957 Symbol* symbol = Symbol::cast(name);
958 name_buffer_->AppendBytes("symbol(");
959 if (!symbol->name()->IsUndefined()) {
960 name_buffer_->AppendBytes("\"");
961 name_buffer_->AppendString(String::cast(symbol->name()));
962 name_buffer_->AppendBytes("\" ");
963 }
964 name_buffer_->AppendBytes("hash ");
965 name_buffer_->AppendHex(symbol->Hash());
966 name_buffer_->AppendByte(')');
967 }
968 } 988 }
969 if (code_event_handler_ != NULL) { 989
970 IssueCodeAddedEvent(code, NULL, name_buffer_->get(), name_buffer_->size()); 990 if (!FLAG_log_code || !log_->IsEnabled()) return;
971 }
972 if (!log_->IsEnabled()) return;
973 if (FLAG_ll_prof) {
974 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size());
975 }
976 if (Serializer::enabled()) {
977 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size());
978 }
979 if (!FLAG_log_code) return;
980 LogMessageBuilder msg(this); 991 LogMessageBuilder msg(this);
981 msg.Append("%s,%s,%d,", 992 msg.Append("%s,%s,%d,",
982 kLogEventsNames[CODE_CREATION_EVENT], 993 kLogEventsNames[CODE_CREATION_EVENT],
983 kLogEventsNames[tag], 994 kLogEventsNames[tag],
984 code->kind()); 995 code->kind());
985 msg.AppendAddress(code->address()); 996 msg.AppendAddress(code->address());
986 msg.Append(",%d,", code->ExecutableSize()); 997 msg.Append(",%d,", code->ExecutableSize());
987 if (name->IsString()) { 998 if (name->IsString()) {
988 msg.Append('"'); 999 msg.Append('"');
989 msg.AppendDetailed(String::cast(name), false); 1000 msg.AppendDetailed(String::cast(name), false);
(...skipping 23 matching lines...) Expand all
1013 } 1024 }
1014 1025
1015 1026
1016 void Logger::CodeCreateEvent(LogEventsAndTags tag, 1027 void Logger::CodeCreateEvent(LogEventsAndTags tag,
1017 Code* code, 1028 Code* code,
1018 SharedFunctionInfo* shared, 1029 SharedFunctionInfo* shared,
1019 CompilationInfo* info, 1030 CompilationInfo* info,
1020 Name* name) { 1031 Name* name) {
1021 if (!is_logging_code_events()) return; 1032 if (!is_logging_code_events()) return;
1022 if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) { 1033 if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) {
1023 name_buffer_->Reset(); 1034 InitNameBuffer(tag);
1024 name_buffer_->AppendBytes(kLogEventsNames[tag]);
1025 name_buffer_->AppendByte(':');
1026 name_buffer_->AppendBytes(ComputeMarker(code)); 1035 name_buffer_->AppendBytes(ComputeMarker(code));
1027 if (name->IsString()) { 1036 AppendName(name);
1028 name_buffer_->AppendString(String::cast(name)); 1037 LogRecordedBuffer(code, shared);
1029 } else {
1030 Symbol* symbol = Symbol::cast(name);
1031 name_buffer_->AppendBytes("symbol(");
1032 if (!symbol->name()->IsUndefined()) {
1033 name_buffer_->AppendBytes("\"");
1034 name_buffer_->AppendString(String::cast(symbol->name()));
1035 name_buffer_->AppendBytes("\" ");
1036 }
1037 name_buffer_->AppendBytes("hash ");
1038 name_buffer_->AppendHex(symbol->Hash());
1039 name_buffer_->AppendByte(')');
1040 }
1041 } 1038 }
1042 if (code_event_handler_ != NULL) { 1039
1043 Script* script = 1040 if (!FLAG_log_code || !log_->IsEnabled()) return;
1044 shared->script()->IsScript() ? Script::cast(shared->script()) : NULL;
1045 IssueCodeAddedEvent(code,
1046 script,
1047 name_buffer_->get(),
1048 name_buffer_->size());
1049 }
1050 if (!log_->IsEnabled()) return;
1051 if (FLAG_ll_prof) {
1052 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size());
1053 }
1054 if (Serializer::enabled()) {
1055 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size());
1056 }
1057 if (!FLAG_log_code) return;
1058 if (code == Isolate::Current()->builtins()->builtin( 1041 if (code == Isolate::Current()->builtins()->builtin(
1059 Builtins::kLazyCompile)) 1042 Builtins::kLazyCompile))
1060 return; 1043 return;
1061 1044
1062 LogMessageBuilder msg(this); 1045 LogMessageBuilder msg(this);
1063 msg.Append("%s,%s,%d,", 1046 msg.Append("%s,%s,%d,",
1064 kLogEventsNames[CODE_CREATION_EVENT], 1047 kLogEventsNames[CODE_CREATION_EVENT],
1065 kLogEventsNames[tag], 1048 kLogEventsNames[tag],
1066 code->kind()); 1049 code->kind());
1067 msg.AppendAddress(code->address()); 1050 msg.AppendAddress(code->address());
(...skipping 23 matching lines...) Expand all
1091 // Although, it is possible to extract source and line from 1074 // Although, it is possible to extract source and line from
1092 // the SharedFunctionInfo object, we left it to caller 1075 // the SharedFunctionInfo object, we left it to caller
1093 // to leave logging functions free from heap allocations. 1076 // to leave logging functions free from heap allocations.
1094 void Logger::CodeCreateEvent(LogEventsAndTags tag, 1077 void Logger::CodeCreateEvent(LogEventsAndTags tag,
1095 Code* code, 1078 Code* code,
1096 SharedFunctionInfo* shared, 1079 SharedFunctionInfo* shared,
1097 CompilationInfo* info, 1080 CompilationInfo* info,
1098 Name* source, int line) { 1081 Name* source, int line) {
1099 if (!is_logging_code_events()) return; 1082 if (!is_logging_code_events()) return;
1100 if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) { 1083 if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) {
1101 name_buffer_->Reset(); 1084 InitNameBuffer(tag);
1102 name_buffer_->AppendBytes(kLogEventsNames[tag]);
1103 name_buffer_->AppendByte(':');
1104 name_buffer_->AppendBytes(ComputeMarker(code)); 1085 name_buffer_->AppendBytes(ComputeMarker(code));
1105 name_buffer_->AppendString(shared->DebugName()); 1086 name_buffer_->AppendString(shared->DebugName());
1106 name_buffer_->AppendByte(' '); 1087 name_buffer_->AppendByte(' ');
1107 if (source->IsString()) { 1088 if (source->IsString()) {
1108 name_buffer_->AppendString(String::cast(source)); 1089 name_buffer_->AppendString(String::cast(source));
1109 } else { 1090 } else {
1110 name_buffer_->AppendBytes("symbol(hash "); 1091 name_buffer_->AppendBytes("symbol(hash ");
1111 name_buffer_->AppendHex(Name::cast(source)->Hash()); 1092 name_buffer_->AppendHex(Name::cast(source)->Hash());
1112 name_buffer_->AppendByte(')'); 1093 name_buffer_->AppendByte(')');
1113 } 1094 }
1114 name_buffer_->AppendByte(':'); 1095 name_buffer_->AppendByte(':');
1115 name_buffer_->AppendInt(line); 1096 name_buffer_->AppendInt(line);
1097 LogRecordedBuffer(code, shared);
1116 } 1098 }
1117 if (code_event_handler_ != NULL) { 1099
1118 Script* script = 1100 if (!FLAG_log_code || !log_->IsEnabled()) return;
1119 shared->script()->IsScript() ? Script::cast(shared->script()) : NULL;
1120 IssueCodeAddedEvent(code,
1121 script,
1122 name_buffer_->get(),
1123 name_buffer_->size());
1124 }
1125 if (!log_->IsEnabled()) return;
1126 if (FLAG_ll_prof) {
1127 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size());
1128 }
1129 if (Serializer::enabled()) {
1130 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size());
1131 }
1132 if (!FLAG_log_code) return;
1133 LogMessageBuilder msg(this); 1101 LogMessageBuilder msg(this);
1134 SmartArrayPointer<char> name = 1102 SmartArrayPointer<char> name =
1135 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 1103 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
1136 msg.Append("%s,%s,%d,", 1104 msg.Append("%s,%s,%d,",
1137 kLogEventsNames[CODE_CREATION_EVENT], 1105 kLogEventsNames[CODE_CREATION_EVENT],
1138 kLogEventsNames[tag], 1106 kLogEventsNames[tag],
1139 code->kind()); 1107 code->kind());
1140 msg.AppendAddress(code->address()); 1108 msg.AppendAddress(code->address());
1141 msg.Append(",%d,\"%s ", code->ExecutableSize(), *name); 1109 msg.Append(",%d,\"%s ", code->ExecutableSize(), *name);
1142 if (source->IsString()) { 1110 if (source->IsString()) {
(...skipping 14 matching lines...) Expand all
1157 msg.AppendAddress(shared->address()); 1125 msg.AppendAddress(shared->address());
1158 msg.Append(",%s", ComputeMarker(code)); 1126 msg.Append(",%s", ComputeMarker(code));
1159 msg.Append('\n'); 1127 msg.Append('\n');
1160 msg.WriteToLogFile(); 1128 msg.WriteToLogFile();
1161 } 1129 }
1162 1130
1163 1131
1164 void Logger::CodeCreateEvent(LogEventsAndTags tag, Code* code, int args_count) { 1132 void Logger::CodeCreateEvent(LogEventsAndTags tag, Code* code, int args_count) {
1165 if (!is_logging_code_events()) return; 1133 if (!is_logging_code_events()) return;
1166 if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) { 1134 if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) {
1167 name_buffer_->Reset(); 1135 InitNameBuffer(tag);
1168 name_buffer_->AppendBytes(kLogEventsNames[tag]);
1169 name_buffer_->AppendByte(':');
1170 name_buffer_->AppendInt(args_count); 1136 name_buffer_->AppendInt(args_count);
1137 LogRecordedBuffer(code, NULL);
1171 } 1138 }
1172 if (code_event_handler_ != NULL) { 1139
1173 IssueCodeAddedEvent(code, NULL, name_buffer_->get(), name_buffer_->size()); 1140 if (!FLAG_log_code || !log_->IsEnabled()) return;
1174 }
1175 if (!log_->IsEnabled()) return;
1176 if (FLAG_ll_prof) {
1177 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size());
1178 }
1179 if (Serializer::enabled()) {
1180 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size());
1181 }
1182 if (!FLAG_log_code) return;
1183 LogMessageBuilder msg(this); 1141 LogMessageBuilder msg(this);
1184 msg.Append("%s,%s,%d,", 1142 msg.Append("%s,%s,%d,",
1185 kLogEventsNames[CODE_CREATION_EVENT], 1143 kLogEventsNames[CODE_CREATION_EVENT],
1186 kLogEventsNames[tag], 1144 kLogEventsNames[tag],
1187 code->kind()); 1145 code->kind());
1188 msg.AppendAddress(code->address()); 1146 msg.AppendAddress(code->address());
1189 msg.Append(",%d,\"args_count: %d\"", code->ExecutableSize(), args_count); 1147 msg.Append(",%d,\"args_count: %d\"", code->ExecutableSize(), args_count);
1190 msg.Append('\n'); 1148 msg.Append('\n');
1191 msg.WriteToLogFile(); 1149 msg.WriteToLogFile();
1192 } 1150 }
1193 1151
1194 1152
1195 void Logger::CodeMovingGCEvent() { 1153 void Logger::CodeMovingGCEvent() {
1196 if (!log_->IsEnabled() || !FLAG_ll_prof) return; 1154 if (!log_->IsEnabled() || !FLAG_ll_prof) return;
1197 LowLevelLogWriteBytes(&kCodeMovingGCTag, sizeof(kCodeMovingGCTag)); 1155 LowLevelLogWriteBytes(&kCodeMovingGCTag, sizeof(kCodeMovingGCTag));
1198 OS::SignalCodeMovingGC(); 1156 OS::SignalCodeMovingGC();
1199 } 1157 }
1200 1158
1201 1159
1202 void Logger::RegExpCodeCreateEvent(Code* code, String* source) { 1160 void Logger::RegExpCodeCreateEvent(Code* code, String* source) {
1203 if (!is_logging_code_events()) return; 1161 if (!is_logging_code_events()) return;
1204 if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) { 1162 if (FLAG_ll_prof || Serializer::enabled() || code_event_handler_ != NULL) {
1205 name_buffer_->Reset(); 1163 InitNameBuffer(REG_EXP_TAG);
1206 name_buffer_->AppendBytes(kLogEventsNames[REG_EXP_TAG]);
1207 name_buffer_->AppendByte(':');
1208 name_buffer_->AppendString(source); 1164 name_buffer_->AppendString(source);
1165 LogRecordedBuffer(code, NULL);
1209 } 1166 }
1210 if (code_event_handler_ != NULL) { 1167
1211 IssueCodeAddedEvent(code, NULL, name_buffer_->get(), name_buffer_->size()); 1168 if (!FLAG_log_code || !log_->IsEnabled()) return;
1212 }
1213 if (!log_->IsEnabled()) return;
1214 if (FLAG_ll_prof) {
1215 LowLevelCodeCreateEvent(code, name_buffer_->get(), name_buffer_->size());
1216 }
1217 if (Serializer::enabled()) {
1218 RegisterSnapshotCodeName(code, name_buffer_->get(), name_buffer_->size());
1219 }
1220 if (!FLAG_log_code) return;
1221 LogMessageBuilder msg(this); 1169 LogMessageBuilder msg(this);
1222 msg.Append("%s,%s,-2,", 1170 msg.Append("%s,%s,-2,",
1223 kLogEventsNames[CODE_CREATION_EVENT], 1171 kLogEventsNames[CODE_CREATION_EVENT],
1224 kLogEventsNames[REG_EXP_TAG]); 1172 kLogEventsNames[REG_EXP_TAG]);
1225 msg.AppendAddress(code->address()); 1173 msg.AppendAddress(code->address());
1226 msg.Append(",%d,\"", code->ExecutableSize()); 1174 msg.Append(",%d,\"", code->ExecutableSize());
1227 msg.AppendDetailed(source, false); 1175 msg.AppendDetailed(source, false);
1228 msg.Append('\"'); 1176 msg.Append('\"');
1229 msg.Append('\n'); 1177 msg.Append('\n');
1230 msg.WriteToLogFile(); 1178 msg.WriteToLogFile();
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 profiler_ = NULL; 1832 profiler_ = NULL;
1885 } 1833 }
1886 1834
1887 delete ticker_; 1835 delete ticker_;
1888 ticker_ = NULL; 1836 ticker_ = NULL;
1889 1837
1890 return log_->Close(); 1838 return log_->Close();
1891 } 1839 }
1892 1840
1893 } } // namespace v8::internal 1841 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/log.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698