Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 14 matching lines...) Expand all Loading... | |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "cpu-profiler-inl.h" | 30 #include "cpu-profiler-inl.h" |
| 31 | 31 |
| 32 #ifdef ENABLE_LOGGING_AND_PROFILING | 32 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 33 | 33 |
| 34 #include "frames-inl.h" | 34 #include "frames-inl.h" |
| 35 #include "hashmap.h" | |
| 35 #include "log-inl.h" | 36 #include "log-inl.h" |
| 36 | 37 |
| 37 #include "../include/v8-profiler.h" | 38 #include "../include/v8-profiler.h" |
| 38 | 39 |
| 39 namespace v8 { | 40 namespace v8 { |
| 40 namespace internal { | 41 namespace internal { |
| 41 | 42 |
| 42 static const int kEventsBufferSize = 256*KB; | 43 static const int kEventsBufferSize = 256*KB; |
| 43 static const int kTickSamplesBufferChunkSize = 64*KB; | 44 static const int kTickSamplesBufferChunkSize = 64*KB; |
| 44 static const int kTickSamplesBufferChunksCount = 16; | 45 static const int kTickSamplesBufferChunksCount = 16; |
| 45 | 46 |
| 46 | 47 |
| 47 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator) | 48 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator) |
| 48 : generator_(generator), | 49 : generator_(generator), |
| 49 running_(true), | 50 running_(true), |
| 50 ticks_buffer_(sizeof(TickSampleEventRecord), | 51 ticks_buffer_(sizeof(TickSampleEventRecord), |
| 51 kTickSamplesBufferChunkSize, | 52 kTickSamplesBufferChunkSize, |
| 52 kTickSamplesBufferChunksCount), | 53 kTickSamplesBufferChunksCount), |
| 53 enqueue_order_(0) { | 54 enqueue_order_(0), |
| 55 known_functions_(new HashMap(AddressesMatch)) { | |
| 54 } | 56 } |
| 55 | 57 |
| 56 | 58 |
| 59 ProfilerEventsProcessor::~ProfilerEventsProcessor() { | |
| 60 delete known_functions_; | |
| 61 } | |
| 62 | |
| 63 | |
| 57 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag, | 64 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag, |
| 58 const char* prefix, | 65 const char* prefix, |
| 59 String* name, | 66 String* name, |
| 60 Address start) { | 67 Address start) { |
| 61 if (FilterOutCodeCreateEvent(tag)) return; | 68 if (FilterOutCodeCreateEvent(tag)) return; |
| 62 CodeEventsContainer evt_rec; | 69 CodeEventsContainer evt_rec; |
| 63 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; | 70 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; |
| 64 rec->type = CodeEventRecord::CODE_CREATION; | 71 rec->type = CodeEventRecord::CODE_CREATION; |
| 65 rec->order = ++enqueue_order_; | 72 rec->order = ++enqueue_order_; |
| 66 rec->start = start; | 73 rec->start = start; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 Address start, | 152 Address start, |
| 146 int security_token_id) { | 153 int security_token_id) { |
| 147 CodeEventsContainer evt_rec; | 154 CodeEventsContainer evt_rec; |
| 148 CodeAliasEventRecord* rec = &evt_rec.CodeAliasEventRecord_; | 155 CodeAliasEventRecord* rec = &evt_rec.CodeAliasEventRecord_; |
| 149 rec->type = CodeEventRecord::CODE_ALIAS; | 156 rec->type = CodeEventRecord::CODE_ALIAS; |
| 150 rec->order = ++enqueue_order_; | 157 rec->order = ++enqueue_order_; |
| 151 rec->start = alias; | 158 rec->start = alias; |
| 152 rec->entry = generator_->NewCodeEntry(security_token_id); | 159 rec->entry = generator_->NewCodeEntry(security_token_id); |
| 153 rec->code_start = start; | 160 rec->code_start = start; |
| 154 events_buffer_.Enqueue(evt_rec); | 161 events_buffer_.Enqueue(evt_rec); |
| 162 | |
| 163 known_functions_->Lookup(alias, AddressHash(alias), true); | |
| 155 } | 164 } |
| 156 | 165 |
| 157 | 166 |
| 158 void ProfilerEventsProcessor::FunctionMoveEvent(Address from, Address to) { | 167 void ProfilerEventsProcessor::FunctionMoveEvent(Address from, Address to) { |
| 159 CodeMoveEvent(from, to); | 168 CodeMoveEvent(from, to); |
| 169 | |
| 170 if (IsKnownFunction(from)) { | |
| 171 known_functions_->Remove(from, AddressHash(from)); | |
| 172 known_functions_->Lookup(to, AddressHash(to), true); | |
| 173 } | |
| 160 } | 174 } |
| 161 | 175 |
| 162 | 176 |
| 163 void ProfilerEventsProcessor::FunctionDeleteEvent(Address from) { | 177 void ProfilerEventsProcessor::FunctionDeleteEvent(Address from) { |
| 164 CodeDeleteEvent(from); | 178 CodeDeleteEvent(from); |
| 179 | |
| 180 known_functions_->Remove(from, AddressHash(from)); | |
| 165 } | 181 } |
| 166 | 182 |
| 167 | 183 |
| 184 bool ProfilerEventsProcessor::IsKnownFunction(Address start) { | |
| 185 HashMap::Entry* entry = | |
| 186 known_functions_->Lookup(start, AddressHash(start), false); | |
| 187 return entry != NULL; | |
| 188 } | |
| 189 | |
| 190 | |
| 168 void ProfilerEventsProcessor::RegExpCodeCreateEvent( | 191 void ProfilerEventsProcessor::RegExpCodeCreateEvent( |
| 169 Logger::LogEventsAndTags tag, | 192 Logger::LogEventsAndTags tag, |
| 170 const char* prefix, | 193 const char* prefix, |
| 171 String* name, | 194 String* name, |
| 172 Address start, | 195 Address start, |
| 173 unsigned size) { | 196 unsigned size) { |
| 174 if (FilterOutCodeCreateEvent(tag)) return; | 197 if (FilterOutCodeCreateEvent(tag)) return; |
| 175 CodeEventsContainer evt_rec; | 198 CodeEventsContainer evt_rec; |
| 176 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; | 199 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; |
| 177 rec->type = CodeEventRecord::CODE_CREATION; | 200 rec->type = CodeEventRecord::CODE_CREATION; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 security_token_id = singleton_->token_enumerator_->GetTokenId( | 419 security_token_id = singleton_->token_enumerator_->GetTokenId( |
| 397 function->context()->global_context()->security_token()); | 420 function->context()->global_context()->security_token()); |
| 398 } | 421 } |
| 399 singleton_->processor_->FunctionCreateEvent( | 422 singleton_->processor_->FunctionCreateEvent( |
| 400 function->address(), | 423 function->address(), |
| 401 function->code()->address(), | 424 function->code()->address(), |
| 402 security_token_id); | 425 security_token_id); |
| 403 } | 426 } |
| 404 | 427 |
| 405 | 428 |
| 429 void CpuProfiler::FunctionCreateEventFromMove(JSFunction* function, | |
| 430 HeapObject* source) { | |
| 431 // The same function can be reported several times. | |
|
Søren Thygesen Gjesse
2010/09/24 10:20:07
Please add a comment here that this is called duri
mnaganov (inactive)
2010/09/24 11:43:40
Done.
| |
| 432 if (function->unchecked_code() == Builtins::builtin(Builtins::LazyCompile) | |
| 433 || singleton_->processor_->IsKnownFunction(function->address())) return; | |
| 434 | |
| 435 int security_token_id = TokenEnumerator::kNoSecurityToken; | |
| 436 // In debug mode, assertions may fail for contexts, | |
| 437 // and we can live without security tokens in debug mode. | |
| 438 #ifndef DEBUG | |
| 439 if (function->unchecked_context()->IsContext()) { | |
| 440 security_token_id = singleton_->token_enumerator_->GetTokenId( | |
| 441 function->context()->global_context()->security_token()); | |
| 442 } | |
| 443 // Security token may not be moved yet. | |
| 444 if (security_token_id == TokenEnumerator::kNoSecurityToken) { | |
| 445 JSFunction* old_function = reinterpret_cast<JSFunction*>(source); | |
| 446 if (old_function->unchecked_context()->IsContext()) { | |
| 447 security_token_id = singleton_->token_enumerator_->GetTokenId( | |
| 448 old_function->context()->global_context()->security_token()); | |
| 449 } | |
| 450 } | |
| 451 #endif | |
| 452 singleton_->processor_->FunctionCreateEvent( | |
| 453 function->address(), | |
| 454 function->unchecked_code()->address(), | |
| 455 security_token_id); | |
| 456 } | |
| 457 | |
| 458 | |
| 406 void CpuProfiler::FunctionMoveEvent(Address from, Address to) { | 459 void CpuProfiler::FunctionMoveEvent(Address from, Address to) { |
| 407 singleton_->processor_->FunctionMoveEvent(from, to); | 460 singleton_->processor_->FunctionMoveEvent(from, to); |
| 408 } | 461 } |
| 409 | 462 |
| 410 | 463 |
| 411 void CpuProfiler::FunctionDeleteEvent(Address from) { | 464 void CpuProfiler::FunctionDeleteEvent(Address from) { |
| 412 singleton_->processor_->FunctionDeleteEvent(from); | 465 singleton_->processor_->FunctionDeleteEvent(from); |
| 413 } | 466 } |
| 414 | 467 |
| 415 | 468 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 void CpuProfiler::StartProcessorIfNotStarted() { | 519 void CpuProfiler::StartProcessorIfNotStarted() { |
| 467 if (processor_ == NULL) { | 520 if (processor_ == NULL) { |
| 468 // Disable logging when using the new implementation. | 521 // Disable logging when using the new implementation. |
| 469 saved_logging_nesting_ = Logger::logging_nesting_; | 522 saved_logging_nesting_ = Logger::logging_nesting_; |
| 470 Logger::logging_nesting_ = 0; | 523 Logger::logging_nesting_ = 0; |
| 471 generator_ = new ProfileGenerator(profiles_); | 524 generator_ = new ProfileGenerator(profiles_); |
| 472 processor_ = new ProfilerEventsProcessor(generator_); | 525 processor_ = new ProfilerEventsProcessor(generator_); |
| 473 processor_->Start(); | 526 processor_->Start(); |
| 474 // Enumerate stuff we already have in the heap. | 527 // Enumerate stuff we already have in the heap. |
| 475 if (Heap::HasBeenSetup()) { | 528 if (Heap::HasBeenSetup()) { |
| 476 Logger::LogCodeObjects(); | 529 if (!FLAG_prof_browser_mode) { |
| 530 bool saved_log_code_flag = FLAG_log_code; | |
| 531 FLAG_log_code = true; | |
| 532 Logger::LogCodeObjects(); | |
| 533 FLAG_log_code = saved_log_code_flag; | |
| 534 } | |
| 477 Logger::LogCompiledFunctions(); | 535 Logger::LogCompiledFunctions(); |
| 478 Logger::LogFunctionObjects(); | 536 Logger::LogFunctionObjects(); |
| 479 Logger::LogAccessorCallbacks(); | 537 Logger::LogAccessorCallbacks(); |
| 480 } | 538 } |
| 481 // Enable stack sampling. | 539 // Enable stack sampling. |
| 482 reinterpret_cast<Sampler*>(Logger::ticker_)->Start(); | 540 reinterpret_cast<Sampler*>(Logger::ticker_)->Start(); |
| 483 } | 541 } |
| 484 } | 542 } |
| 485 | 543 |
| 486 | 544 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 540 void CpuProfiler::TearDown() { | 598 void CpuProfiler::TearDown() { |
| 541 #ifdef ENABLE_LOGGING_AND_PROFILING | 599 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 542 if (singleton_ != NULL) { | 600 if (singleton_ != NULL) { |
| 543 delete singleton_; | 601 delete singleton_; |
| 544 } | 602 } |
| 545 singleton_ = NULL; | 603 singleton_ = NULL; |
| 546 #endif | 604 #endif |
| 547 } | 605 } |
| 548 | 606 |
| 549 } } // namespace v8::internal | 607 } } // namespace v8::internal |
| OLD | NEW |