| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 return; | 148 return; |
| 149 } | 149 } |
| 150 | 150 |
| 151 const Address js_entry_sp = Top::js_entry_sp(Top::GetCurrentThread()); | 151 const Address js_entry_sp = Top::js_entry_sp(Top::GetCurrentThread()); |
| 152 if (js_entry_sp == 0) { | 152 if (js_entry_sp == 0) { |
| 153 // Not executing JS now. | 153 // Not executing JS now. |
| 154 sample->frames_count = 0; | 154 sample->frames_count = 0; |
| 155 return; | 155 return; |
| 156 } | 156 } |
| 157 | 157 |
| 158 const Address functionAddr = |
| 159 sample->fp + JavaScriptFrameConstants::kFunctionOffset; |
| 160 if (SafeStackFrameIterator::IsWithinBounds(sample->sp, js_entry_sp, |
| 161 functionAddr)) { |
| 162 sample->function = Memory::Address_at(functionAddr) - kHeapObjectTag; |
| 163 } |
| 164 |
| 158 int i = 0; | 165 int i = 0; |
| 159 const Address callback = Logger::current_state_ != NULL ? | 166 const Address callback = Logger::current_state_ != NULL ? |
| 160 Logger::current_state_->external_callback() : NULL; | 167 Logger::current_state_->external_callback() : NULL; |
| 161 if (callback != NULL) { | 168 if (callback != NULL) { |
| 162 sample->stack[i++] = callback; | 169 sample->stack[i++] = callback; |
| 163 } | 170 } |
| 164 | 171 |
| 165 SafeStackTraceFrameIterator it( | 172 SafeStackTraceFrameIterator it(sample->fp, sample->sp, |
| 166 reinterpret_cast<Address>(sample->fp), | 173 sample->sp, js_entry_sp); |
| 167 reinterpret_cast<Address>(sample->sp), | |
| 168 reinterpret_cast<Address>(sample->sp), | |
| 169 js_entry_sp); | |
| 170 while (!it.done() && i < TickSample::kMaxFramesCount) { | 174 while (!it.done() && i < TickSample::kMaxFramesCount) { |
| 171 sample->stack[i++] = it.frame()->pc(); | 175 sample->stack[i++] = it.frame()->pc(); |
| 172 it.Advance(); | 176 it.Advance(); |
| 173 } | 177 } |
| 174 sample->frames_count = i; | 178 sample->frames_count = i; |
| 175 } | 179 } |
| 176 | 180 |
| 177 | 181 |
| 178 // | 182 // |
| 179 // Ticker used to provide ticks to the profiler and the sliding state | 183 // Ticker used to provide ticks to the profiler and the sliding state |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 if (!compression_helper_->HandleMessage(&msg)) return; | 834 if (!compression_helper_->HandleMessage(&msg)) return; |
| 831 } | 835 } |
| 832 msg.Append('\n'); | 836 msg.Append('\n'); |
| 833 msg.WriteToLogFile(); | 837 msg.WriteToLogFile(); |
| 834 #endif | 838 #endif |
| 835 } | 839 } |
| 836 | 840 |
| 837 | 841 |
| 838 void Logger::CodeMoveEvent(Address from, Address to) { | 842 void Logger::CodeMoveEvent(Address from, Address to) { |
| 839 #ifdef ENABLE_LOGGING_AND_PROFILING | 843 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 840 static Address prev_to_ = NULL; | 844 MoveEventInternal(CODE_MOVE_EVENT, from, to); |
| 841 if (!Log::IsEnabled() || !FLAG_log_code) return; | 845 #endif |
| 846 } |
| 847 |
| 848 |
| 849 void Logger::CodeDeleteEvent(Address from) { |
| 850 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 851 DeleteEventInternal(CODE_DELETE_EVENT, from); |
| 852 #endif |
| 853 } |
| 854 |
| 855 |
| 856 void Logger::SnapshotPositionEvent(Address addr, int pos) { |
| 857 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 858 if (!Log::IsEnabled() || !FLAG_log_snapshot_positions) return; |
| 842 LogMessageBuilder msg; | 859 LogMessageBuilder msg; |
| 843 msg.Append("%s,", log_events_[CODE_MOVE_EVENT]); | 860 msg.Append("%s,", log_events_[SNAPSHOT_POSITION_EVENT]); |
| 844 msg.AppendAddress(from); | 861 msg.AppendAddress(addr); |
| 845 msg.Append(','); | 862 msg.Append(",%d", pos); |
| 846 msg.AppendAddress(to, prev_to_); | |
| 847 prev_to_ = to; | |
| 848 if (FLAG_compress_log) { | 863 if (FLAG_compress_log) { |
| 849 ASSERT(compression_helper_ != NULL); | 864 ASSERT(compression_helper_ != NULL); |
| 850 if (!compression_helper_->HandleMessage(&msg)) return; | 865 if (!compression_helper_->HandleMessage(&msg)) return; |
| 866 } |
| 867 msg.Append('\n'); |
| 868 msg.WriteToLogFile(); |
| 869 #endif |
| 870 } |
| 871 |
| 872 |
| 873 void Logger::FunctionCreateEvent(JSFunction* function) { |
| 874 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 875 static Address prev_code = NULL; |
| 876 if (!Log::IsEnabled() || !FLAG_log_code) return; |
| 877 LogMessageBuilder msg; |
| 878 msg.Append("%s,", log_events_[FUNCTION_CREATION_EVENT]); |
| 879 msg.AppendAddress(function->address()); |
| 880 msg.Append(','); |
| 881 msg.AppendAddress(function->code()->address(), prev_code); |
| 882 prev_code = function->code()->address(); |
| 883 if (FLAG_compress_log) { |
| 884 ASSERT(compression_helper_ != NULL); |
| 885 if (!compression_helper_->HandleMessage(&msg)) return; |
| 851 } | 886 } |
| 852 msg.Append('\n'); | 887 msg.Append('\n'); |
| 853 msg.WriteToLogFile(); | 888 msg.WriteToLogFile(); |
| 854 #endif | 889 #endif |
| 855 } | 890 } |
| 856 | 891 |
| 857 | 892 |
| 858 void Logger::CodeDeleteEvent(Address from) { | 893 void Logger::FunctionMoveEvent(Address from, Address to) { |
| 859 #ifdef ENABLE_LOGGING_AND_PROFILING | 894 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 895 MoveEventInternal(FUNCTION_MOVE_EVENT, from, to); |
| 896 #endif |
| 897 } |
| 898 |
| 899 |
| 900 void Logger::FunctionDeleteEvent(Address from) { |
| 901 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 902 DeleteEventInternal(FUNCTION_DELETE_EVENT, from); |
| 903 #endif |
| 904 } |
| 905 |
| 906 |
| 907 void Logger::MoveEventInternal(LogEventsAndTags event, |
| 908 Address from, |
| 909 Address to) { |
| 910 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 911 static Address prev_to_ = NULL; |
| 860 if (!Log::IsEnabled() || !FLAG_log_code) return; | 912 if (!Log::IsEnabled() || !FLAG_log_code) return; |
| 861 LogMessageBuilder msg; | 913 LogMessageBuilder msg; |
| 862 msg.Append("%s,", log_events_[CODE_DELETE_EVENT]); | 914 msg.Append("%s,", log_events_[event]); |
| 863 msg.AppendAddress(from); | 915 msg.AppendAddress(from); |
| 916 msg.Append(','); |
| 917 msg.AppendAddress(to, prev_to_); |
| 918 prev_to_ = to; |
| 864 if (FLAG_compress_log) { | 919 if (FLAG_compress_log) { |
| 865 ASSERT(compression_helper_ != NULL); | 920 ASSERT(compression_helper_ != NULL); |
| 866 if (!compression_helper_->HandleMessage(&msg)) return; | 921 if (!compression_helper_->HandleMessage(&msg)) return; |
| 867 } | 922 } |
| 868 msg.Append('\n'); | 923 msg.Append('\n'); |
| 869 msg.WriteToLogFile(); | 924 msg.WriteToLogFile(); |
| 870 #endif | 925 #endif |
| 871 } | 926 } |
| 872 | 927 |
| 873 | 928 |
| 874 void Logger::SnapshotPositionEvent(Address addr, int pos) { | 929 void Logger::DeleteEventInternal(LogEventsAndTags event, Address from) { |
| 875 #ifdef ENABLE_LOGGING_AND_PROFILING | 930 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 876 if (!Log::IsEnabled() || !FLAG_log_snapshot_positions) return; | 931 if (!Log::IsEnabled() || !FLAG_log_code) return; |
| 877 LogMessageBuilder msg; | 932 LogMessageBuilder msg; |
| 878 msg.Append("%s,", log_events_[SNAPSHOT_POSITION_EVENT]); | 933 msg.Append("%s,", log_events_[event]); |
| 879 msg.AppendAddress(addr); | 934 msg.AppendAddress(from); |
| 880 msg.Append(",%d", pos); | |
| 881 if (FLAG_compress_log) { | 935 if (FLAG_compress_log) { |
| 882 ASSERT(compression_helper_ != NULL); | 936 ASSERT(compression_helper_ != NULL); |
| 883 if (!compression_helper_->HandleMessage(&msg)) return; | 937 if (!compression_helper_->HandleMessage(&msg)) return; |
| 884 } | 938 } |
| 885 msg.Append('\n'); | 939 msg.Append('\n'); |
| 886 msg.WriteToLogFile(); | 940 msg.WriteToLogFile(); |
| 887 #endif | 941 #endif |
| 888 } | 942 } |
| 889 | 943 |
| 890 | 944 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 DeleteArray(parameter_string); | 1116 DeleteArray(parameter_string); |
| 1063 msg.WriteToLogFile(); | 1117 msg.WriteToLogFile(); |
| 1064 #endif | 1118 #endif |
| 1065 } | 1119 } |
| 1066 | 1120 |
| 1067 | 1121 |
| 1068 #ifdef ENABLE_LOGGING_AND_PROFILING | 1122 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 1069 void Logger::TickEvent(TickSample* sample, bool overflow) { | 1123 void Logger::TickEvent(TickSample* sample, bool overflow) { |
| 1070 if (!Log::IsEnabled() || !FLAG_prof) return; | 1124 if (!Log::IsEnabled() || !FLAG_prof) return; |
| 1071 static Address prev_sp = NULL; | 1125 static Address prev_sp = NULL; |
| 1126 static Address prev_function = NULL; |
| 1072 LogMessageBuilder msg; | 1127 LogMessageBuilder msg; |
| 1073 msg.Append("%s,", log_events_[TICK_EVENT]); | 1128 msg.Append("%s,", log_events_[TICK_EVENT]); |
| 1074 Address prev_addr = reinterpret_cast<Address>(sample->pc); | 1129 Address prev_addr = sample->pc; |
| 1075 msg.AppendAddress(prev_addr); | 1130 msg.AppendAddress(prev_addr); |
| 1076 msg.Append(','); | 1131 msg.Append(','); |
| 1077 msg.AppendAddress(reinterpret_cast<Address>(sample->sp), prev_sp); | 1132 msg.AppendAddress(sample->sp, prev_sp); |
| 1078 prev_sp = reinterpret_cast<Address>(sample->sp); | 1133 prev_sp = sample->sp; |
| 1134 msg.Append(','); |
| 1135 msg.AppendAddress(sample->function, prev_function); |
| 1136 prev_function = sample->function; |
| 1079 msg.Append(",%d", static_cast<int>(sample->state)); | 1137 msg.Append(",%d", static_cast<int>(sample->state)); |
| 1080 if (overflow) { | 1138 if (overflow) { |
| 1081 msg.Append(",overflow"); | 1139 msg.Append(",overflow"); |
| 1082 } | 1140 } |
| 1083 for (int i = 0; i < sample->frames_count; ++i) { | 1141 for (int i = 0; i < sample->frames_count; ++i) { |
| 1084 msg.Append(','); | 1142 msg.Append(','); |
| 1085 msg.AppendAddress(sample->stack[i], prev_addr); | 1143 msg.AppendAddress(sample->stack[i], prev_addr); |
| 1086 prev_addr = sample->stack[i]; | 1144 prev_addr = sample->stack[i]; |
| 1087 } | 1145 } |
| 1088 if (FLAG_compress_log) { | 1146 if (FLAG_compress_log) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 const int modules_to_enable = ~GetActiveProfilerModules() & flags; | 1195 const int modules_to_enable = ~GetActiveProfilerModules() & flags; |
| 1138 if (modules_to_enable != PROFILER_MODULE_NONE) { | 1196 if (modules_to_enable != PROFILER_MODULE_NONE) { |
| 1139 is_logging_ = true; | 1197 is_logging_ = true; |
| 1140 } | 1198 } |
| 1141 if (modules_to_enable & PROFILER_MODULE_CPU) { | 1199 if (modules_to_enable & PROFILER_MODULE_CPU) { |
| 1142 if (FLAG_prof_lazy) { | 1200 if (FLAG_prof_lazy) { |
| 1143 profiler_->Engage(); | 1201 profiler_->Engage(); |
| 1144 LOG(UncheckedStringEvent("profiler", "resume")); | 1202 LOG(UncheckedStringEvent("profiler", "resume")); |
| 1145 FLAG_log_code = true; | 1203 FLAG_log_code = true; |
| 1146 LogCompiledFunctions(); | 1204 LogCompiledFunctions(); |
| 1205 LogFunctionObjects(); |
| 1147 LogAccessorCallbacks(); | 1206 LogAccessorCallbacks(); |
| 1148 if (!FLAG_sliding_state_window) ticker_->Start(); | 1207 if (!FLAG_sliding_state_window) ticker_->Start(); |
| 1149 } | 1208 } |
| 1150 profiler_->resume(); | 1209 profiler_->resume(); |
| 1151 } | 1210 } |
| 1152 if (modules_to_enable & | 1211 if (modules_to_enable & |
| 1153 (PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS)) { | 1212 (PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS)) { |
| 1154 FLAG_log_gc = true; | 1213 FLAG_log_gc = true; |
| 1155 } | 1214 } |
| 1156 } | 1215 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1283 } else { | 1342 } else { |
| 1284 LOG(CodeCreateEvent( | 1343 LOG(CodeCreateEvent( |
| 1285 Logger::LAZY_COMPILE_TAG, shared->code(), *func_name)); | 1344 Logger::LAZY_COMPILE_TAG, shared->code(), *func_name)); |
| 1286 } | 1345 } |
| 1287 } | 1346 } |
| 1288 | 1347 |
| 1289 DeleteArray(sfis); | 1348 DeleteArray(sfis); |
| 1290 } | 1349 } |
| 1291 | 1350 |
| 1292 | 1351 |
| 1352 void Logger::LogFunctionObjects() { |
| 1353 AssertNoAllocation no_alloc; |
| 1354 HeapIterator iterator; |
| 1355 while (iterator.has_next()) { |
| 1356 HeapObject* obj = iterator.next(); |
| 1357 ASSERT(obj != NULL); |
| 1358 if (!obj->IsJSFunction()) continue; |
| 1359 JSFunction* jsf = JSFunction::cast(obj); |
| 1360 if (!jsf->is_compiled()) continue; |
| 1361 LOG(FunctionCreateEvent(jsf)); |
| 1362 } |
| 1363 } |
| 1364 |
| 1365 |
| 1293 void Logger::LogAccessorCallbacks() { | 1366 void Logger::LogAccessorCallbacks() { |
| 1294 AssertNoAllocation no_alloc; | 1367 AssertNoAllocation no_alloc; |
| 1295 HeapIterator iterator; | 1368 HeapIterator iterator; |
| 1296 while (iterator.has_next()) { | 1369 while (iterator.has_next()) { |
| 1297 HeapObject* obj = iterator.next(); | 1370 HeapObject* obj = iterator.next(); |
| 1298 ASSERT(obj != NULL); | 1371 ASSERT(obj != NULL); |
| 1299 if (!obj->IsAccessorInfo()) continue; | 1372 if (!obj->IsAccessorInfo()) continue; |
| 1300 AccessorInfo* ai = AccessorInfo::cast(obj); | 1373 AccessorInfo* ai = AccessorInfo::cast(obj); |
| 1301 if (!ai->name()->IsString()) continue; | 1374 if (!ai->name()->IsString()) continue; |
| 1302 String* name = String::cast(ai->name()); | 1375 String* name = String::cast(ai->name()); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1465 // Otherwise, if the sliding state window computation has not been | 1538 // Otherwise, if the sliding state window computation has not been |
| 1466 // started we do it now. | 1539 // started we do it now. |
| 1467 if (sliding_state_window_ == NULL) { | 1540 if (sliding_state_window_ == NULL) { |
| 1468 sliding_state_window_ = new SlidingStateWindow(); | 1541 sliding_state_window_ = new SlidingStateWindow(); |
| 1469 } | 1542 } |
| 1470 #endif | 1543 #endif |
| 1471 } | 1544 } |
| 1472 | 1545 |
| 1473 | 1546 |
| 1474 } } // namespace v8::internal | 1547 } } // namespace v8::internal |
| OLD | NEW |