| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 static bool paused_; | 136 static bool paused_; |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 bool Profiler::paused_ = false; | 139 bool Profiler::paused_ = false; |
| 140 | 140 |
| 141 | 141 |
| 142 // | 142 // |
| 143 // StackTracer implementation | 143 // StackTracer implementation |
| 144 // | 144 // |
| 145 void StackTracer::Trace(TickSample* sample) { | 145 void StackTracer::Trace(TickSample* sample) { |
| 146 if (sample->state == GC) { | 146 sample->function = NULL; |
| 147 sample->frames_count = 0; | 147 sample->frames_count = 0; |
| 148 return; | 148 |
| 149 } | 149 if (sample->state == GC) return; |
| 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; | |
| 155 return; | 154 return; |
| 156 } | 155 } |
| 157 | 156 |
| 158 const Address functionAddr = | 157 const Address functionAddr = |
| 159 sample->fp + JavaScriptFrameConstants::kFunctionOffset; | 158 sample->fp + JavaScriptFrameConstants::kFunctionOffset; |
| 160 if (SafeStackFrameIterator::IsWithinBounds(sample->sp, js_entry_sp, | 159 if (SafeStackFrameIterator::IsWithinBounds(sample->sp, js_entry_sp, |
| 161 functionAddr)) { | 160 functionAddr)) { |
| 162 sample->function = Memory::Address_at(functionAddr) - kHeapObjectTag; | 161 sample->function = Memory::Address_at(functionAddr) - kHeapObjectTag; |
| 163 } | 162 } |
| 164 | 163 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 176 it.Advance(); | 175 it.Advance(); |
| 177 } | 176 } |
| 178 sample->frames_count = i; | 177 sample->frames_count = i; |
| 179 } | 178 } |
| 180 | 179 |
| 181 | 180 |
| 182 // | 181 // |
| 183 // Ticker used to provide ticks to the profiler and the sliding state | 182 // Ticker used to provide ticks to the profiler and the sliding state |
| 184 // window. | 183 // window. |
| 185 // | 184 // |
| 185 #ifndef ENABLE_CPP_PROFILES_PROCESSOR |
| 186 |
| 186 class Ticker: public Sampler { | 187 class Ticker: public Sampler { |
| 187 public: | 188 public: |
| 188 explicit Ticker(int interval): | 189 explicit Ticker(int interval): |
| 189 Sampler(interval, FLAG_prof), window_(NULL), profiler_(NULL) {} | 190 Sampler(interval, FLAG_prof), window_(NULL), profiler_(NULL) {} |
| 190 | 191 |
| 191 ~Ticker() { if (IsActive()) Stop(); } | 192 ~Ticker() { if (IsActive()) Stop(); } |
| 192 | 193 |
| 193 void SampleStack(TickSample* sample) { | 194 void SampleStack(TickSample* sample) { |
| 194 StackTracer::Trace(sample); | 195 StackTracer::Trace(sample); |
| 195 } | 196 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 217 void ClearProfiler() { | 218 void ClearProfiler() { |
| 218 profiler_ = NULL; | 219 profiler_ = NULL; |
| 219 if (!window_ && IsActive()) Stop(); | 220 if (!window_ && IsActive()) Stop(); |
| 220 } | 221 } |
| 221 | 222 |
| 222 private: | 223 private: |
| 223 SlidingStateWindow* window_; | 224 SlidingStateWindow* window_; |
| 224 Profiler* profiler_; | 225 Profiler* profiler_; |
| 225 }; | 226 }; |
| 226 | 227 |
| 228 #endif // ENABLE_CPP_PROFILES_PROCESSOR |
| 229 |
| 227 | 230 |
| 228 // | 231 // |
| 229 // SlidingStateWindow implementation. | 232 // SlidingStateWindow implementation. |
| 230 // | 233 // |
| 231 SlidingStateWindow::SlidingStateWindow(): current_index_(0), is_full_(false) { | 234 SlidingStateWindow::SlidingStateWindow(): current_index_(0), is_full_(false) { |
| 232 for (int i = 0; i < kBufferSize; i++) { | 235 for (int i = 0; i < kBufferSize; i++) { |
| 233 buffer_[i] = static_cast<byte>(OTHER); | 236 buffer_[i] = static_cast<byte>(OTHER); |
| 234 } | 237 } |
| 235 Logger::ticker_->SetWindow(this); | 238 Logger::ticker_->SetWindow(this); |
| 236 } | 239 } |
| (...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 break; | 1296 break; |
| 1294 case Code::KEYED_STORE_IC: | 1297 case Code::KEYED_STORE_IC: |
| 1295 description = "A keyed store IC from the snapshot"; | 1298 description = "A keyed store IC from the snapshot"; |
| 1296 tag = Logger::KEYED_STORE_IC_TAG; | 1299 tag = Logger::KEYED_STORE_IC_TAG; |
| 1297 break; | 1300 break; |
| 1298 case Code::CALL_IC: | 1301 case Code::CALL_IC: |
| 1299 description = "A call IC from the snapshot"; | 1302 description = "A call IC from the snapshot"; |
| 1300 tag = Logger::CALL_IC_TAG; | 1303 tag = Logger::CALL_IC_TAG; |
| 1301 break; | 1304 break; |
| 1302 } | 1305 } |
| 1303 LOG(CodeCreateEvent(tag, code_object, description)); | 1306 PROFILE(CodeCreateEvent(tag, code_object, description)); |
| 1304 } | 1307 } |
| 1305 } | 1308 } |
| 1306 | 1309 |
| 1307 | 1310 |
| 1308 void Logger::LogCodeObjects() { | 1311 void Logger::LogCodeObjects() { |
| 1309 AssertNoAllocation no_alloc; | 1312 AssertNoAllocation no_alloc; |
| 1310 HeapIterator iterator; | 1313 HeapIterator iterator; |
| 1311 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 1314 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
| 1312 if (obj->IsCode()) LogCodeObject(obj); | 1315 if (obj->IsCode()) LogCodeObject(obj); |
| 1313 } | 1316 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1327 Handle<SharedFunctionInfo> shared = sfis[i]; | 1330 Handle<SharedFunctionInfo> shared = sfis[i]; |
| 1328 Handle<String> name(String::cast(shared->name())); | 1331 Handle<String> name(String::cast(shared->name())); |
| 1329 Handle<String> func_name(name->length() > 0 ? | 1332 Handle<String> func_name(name->length() > 0 ? |
| 1330 *name : shared->inferred_name()); | 1333 *name : shared->inferred_name()); |
| 1331 if (shared->script()->IsScript()) { | 1334 if (shared->script()->IsScript()) { |
| 1332 Handle<Script> script(Script::cast(shared->script())); | 1335 Handle<Script> script(Script::cast(shared->script())); |
| 1333 if (script->name()->IsString()) { | 1336 if (script->name()->IsString()) { |
| 1334 Handle<String> script_name(String::cast(script->name())); | 1337 Handle<String> script_name(String::cast(script->name())); |
| 1335 int line_num = GetScriptLineNumber(script, shared->start_position()); | 1338 int line_num = GetScriptLineNumber(script, shared->start_position()); |
| 1336 if (line_num > 0) { | 1339 if (line_num > 0) { |
| 1337 LOG(CodeCreateEvent(Logger::LAZY_COMPILE_TAG, | 1340 PROFILE(CodeCreateEvent(Logger::LAZY_COMPILE_TAG, |
| 1338 shared->code(), *func_name, | 1341 shared->code(), *func_name, |
| 1339 *script_name, line_num + 1)); | 1342 *script_name, line_num + 1)); |
| 1340 } else { | 1343 } else { |
| 1341 // Can't distinguish enum and script here, so always use Script. | 1344 // Can't distinguish enum and script here, so always use Script. |
| 1342 LOG(CodeCreateEvent(Logger::SCRIPT_TAG, | 1345 PROFILE(CodeCreateEvent(Logger::SCRIPT_TAG, |
| 1343 shared->code(), *script_name)); | 1346 shared->code(), *script_name)); |
| 1344 } | 1347 } |
| 1345 } else { | 1348 } else { |
| 1346 LOG(CodeCreateEvent( | 1349 PROFILE(CodeCreateEvent( |
| 1347 Logger::LAZY_COMPILE_TAG, shared->code(), *func_name)); | 1350 Logger::LAZY_COMPILE_TAG, shared->code(), *func_name)); |
| 1348 } | 1351 } |
| 1349 } else if (shared->IsApiFunction()) { | 1352 } else if (shared->IsApiFunction()) { |
| 1350 // API function. | 1353 // API function. |
| 1351 FunctionTemplateInfo* fun_data = shared->get_api_func_data(); | 1354 FunctionTemplateInfo* fun_data = shared->get_api_func_data(); |
| 1352 Object* raw_call_data = fun_data->call_code(); | 1355 Object* raw_call_data = fun_data->call_code(); |
| 1353 if (!raw_call_data->IsUndefined()) { | 1356 if (!raw_call_data->IsUndefined()) { |
| 1354 CallHandlerInfo* call_data = CallHandlerInfo::cast(raw_call_data); | 1357 CallHandlerInfo* call_data = CallHandlerInfo::cast(raw_call_data); |
| 1355 Object* callback_obj = call_data->callback(); | 1358 Object* callback_obj = call_data->callback(); |
| 1356 Address entry_point = v8::ToCData<Address>(callback_obj); | 1359 Address entry_point = v8::ToCData<Address>(callback_obj); |
| 1357 LOG(CallbackEvent(*func_name, entry_point)); | 1360 PROFILE(CallbackEvent(*func_name, entry_point)); |
| 1358 } | 1361 } |
| 1359 } else { | 1362 } else { |
| 1360 LOG(CodeCreateEvent( | 1363 PROFILE(CodeCreateEvent( |
| 1361 Logger::LAZY_COMPILE_TAG, shared->code(), *func_name)); | 1364 Logger::LAZY_COMPILE_TAG, shared->code(), *func_name)); |
| 1362 } | 1365 } |
| 1363 } | 1366 } |
| 1364 | 1367 |
| 1365 DeleteArray(sfis); | 1368 DeleteArray(sfis); |
| 1366 } | 1369 } |
| 1367 | 1370 |
| 1368 | 1371 |
| 1369 void Logger::LogFunctionObjects() { | 1372 void Logger::LogFunctionObjects() { |
| 1370 AssertNoAllocation no_alloc; | 1373 AssertNoAllocation no_alloc; |
| 1371 HeapIterator iterator; | 1374 HeapIterator iterator; |
| 1372 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 1375 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
| 1373 if (!obj->IsJSFunction()) continue; | 1376 if (!obj->IsJSFunction()) continue; |
| 1374 JSFunction* jsf = JSFunction::cast(obj); | 1377 JSFunction* jsf = JSFunction::cast(obj); |
| 1375 if (!jsf->is_compiled()) continue; | 1378 if (!jsf->is_compiled()) continue; |
| 1376 LOG(FunctionCreateEvent(jsf)); | 1379 PROFILE(FunctionCreateEvent(jsf)); |
| 1377 } | 1380 } |
| 1378 } | 1381 } |
| 1379 | 1382 |
| 1380 | 1383 |
| 1381 void Logger::LogAccessorCallbacks() { | 1384 void Logger::LogAccessorCallbacks() { |
| 1382 AssertNoAllocation no_alloc; | 1385 AssertNoAllocation no_alloc; |
| 1383 HeapIterator iterator; | 1386 HeapIterator iterator; |
| 1384 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 1387 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
| 1385 if (!obj->IsAccessorInfo()) continue; | 1388 if (!obj->IsAccessorInfo()) continue; |
| 1386 AccessorInfo* ai = AccessorInfo::cast(obj); | 1389 AccessorInfo* ai = AccessorInfo::cast(obj); |
| 1387 if (!ai->name()->IsString()) continue; | 1390 if (!ai->name()->IsString()) continue; |
| 1388 String* name = String::cast(ai->name()); | 1391 String* name = String::cast(ai->name()); |
| 1389 Address getter_entry = v8::ToCData<Address>(ai->getter()); | 1392 Address getter_entry = v8::ToCData<Address>(ai->getter()); |
| 1390 if (getter_entry != 0) { | 1393 if (getter_entry != 0) { |
| 1391 LOG(GetterCallbackEvent(name, getter_entry)); | 1394 PROFILE(GetterCallbackEvent(name, getter_entry)); |
| 1392 } | 1395 } |
| 1393 Address setter_entry = v8::ToCData<Address>(ai->setter()); | 1396 Address setter_entry = v8::ToCData<Address>(ai->setter()); |
| 1394 if (setter_entry != 0) { | 1397 if (setter_entry != 0) { |
| 1395 LOG(SetterCallbackEvent(name, setter_entry)); | 1398 PROFILE(SetterCallbackEvent(name, setter_entry)); |
| 1396 } | 1399 } |
| 1397 } | 1400 } |
| 1398 } | 1401 } |
| 1399 | 1402 |
| 1400 #endif | 1403 #endif |
| 1401 | 1404 |
| 1402 | 1405 |
| 1403 bool Logger::Setup() { | 1406 bool Logger::Setup() { |
| 1404 #ifdef ENABLE_LOGGING_AND_PROFILING | 1407 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 1405 // --log-all enables all the log flags. | 1408 // --log-all enables all the log flags. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1498 if (!FLAG_prof_auto) { | 1501 if (!FLAG_prof_auto) { |
| 1499 profiler_->pause(); | 1502 profiler_->pause(); |
| 1500 } else { | 1503 } else { |
| 1501 logging_nesting_ = 1; | 1504 logging_nesting_ = 1; |
| 1502 } | 1505 } |
| 1503 if (!FLAG_prof_lazy) { | 1506 if (!FLAG_prof_lazy) { |
| 1504 profiler_->Engage(); | 1507 profiler_->Engage(); |
| 1505 } | 1508 } |
| 1506 } | 1509 } |
| 1507 | 1510 |
| 1511 #ifdef ENABLE_CPP_PROFILES_PROCESSOR |
| 1512 // Disable old logging, as we are using the same '--prof' flag. |
| 1513 logging_nesting_ = 0; |
| 1514 #endif |
| 1515 |
| 1508 LogMessageBuilder::set_write_failure_handler(StopLoggingAndProfiling); | 1516 LogMessageBuilder::set_write_failure_handler(StopLoggingAndProfiling); |
| 1509 | 1517 |
| 1510 return true; | 1518 return true; |
| 1511 | 1519 |
| 1512 #else | 1520 #else |
| 1513 return false; | 1521 return false; |
| 1514 #endif | 1522 #endif |
| 1515 } | 1523 } |
| 1516 | 1524 |
| 1517 | 1525 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1551 return; | 1559 return; |
| 1552 } | 1560 } |
| 1553 // Otherwise, if the sliding state window computation has not been | 1561 // Otherwise, if the sliding state window computation has not been |
| 1554 // started we do it now. | 1562 // started we do it now. |
| 1555 if (sliding_state_window_ == NULL) { | 1563 if (sliding_state_window_ == NULL) { |
| 1556 sliding_state_window_ = new SlidingStateWindow(); | 1564 sliding_state_window_ = new SlidingStateWindow(); |
| 1557 } | 1565 } |
| 1558 #endif | 1566 #endif |
| 1559 } | 1567 } |
| 1560 | 1568 |
| 1561 | |
| 1562 } } // namespace v8::internal | 1569 } } // namespace v8::internal |
| OLD | NEW |