| 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 } | 276 } |
| 277 | 277 |
| 278 | 278 |
| 279 CpuProfile* CpuProfiler::FindProfile(unsigned uid) { | 279 CpuProfile* CpuProfiler::FindProfile(unsigned uid) { |
| 280 ASSERT(singleton_ != NULL); | 280 ASSERT(singleton_ != NULL); |
| 281 return singleton_->profiles_->GetProfile(uid); | 281 return singleton_->profiles_->GetProfile(uid); |
| 282 } | 282 } |
| 283 | 283 |
| 284 | 284 |
| 285 TickSample* CpuProfiler::TickSampleEvent() { | 285 TickSample* CpuProfiler::TickSampleEvent() { |
| 286 ASSERT(singleton_ != NULL); | 286 if (CpuProfiler::is_profiling()) { |
| 287 if (singleton_->is_profiling()) { | |
| 288 return singleton_->processor_->TickSampleEvent(); | 287 return singleton_->processor_->TickSampleEvent(); |
| 289 } else { | 288 } else { |
| 290 return NULL; | 289 return NULL; |
| 291 } | 290 } |
| 292 } | 291 } |
| 293 | 292 |
| 294 | 293 |
| 295 void CpuProfiler::CallbackEvent(String* name, Address entry_point) { | 294 void CpuProfiler::CallbackEvent(String* name, Address entry_point) { |
| 296 singleton_->processor_->CallbackCreateEvent( | 295 singleton_->processor_->CallbackCreateEvent( |
| 297 Logger::CALLBACK_TAG, CodeEntry::kEmptyNamePrefix, name, entry_point); | 296 Logger::CALLBACK_TAG, CodeEntry::kEmptyNamePrefix, name, entry_point); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 409 |
| 411 void CpuProfiler::StartCollectingProfile(String* title) { | 410 void CpuProfiler::StartCollectingProfile(String* title) { |
| 412 if (profiles_->StartProfiling(title, next_profile_uid_++)) { | 411 if (profiles_->StartProfiling(title, next_profile_uid_++)) { |
| 413 StartProcessorIfNotStarted(); | 412 StartProcessorIfNotStarted(); |
| 414 } | 413 } |
| 415 } | 414 } |
| 416 | 415 |
| 417 | 416 |
| 418 void CpuProfiler::StartProcessorIfNotStarted() { | 417 void CpuProfiler::StartProcessorIfNotStarted() { |
| 419 if (processor_ == NULL) { | 418 if (processor_ == NULL) { |
| 419 // Disable logging when using the new implementation. |
| 420 saved_logging_nesting_ = Logger::logging_nesting_; |
| 421 Logger::logging_nesting_ = 0; |
| 420 generator_ = new ProfileGenerator(profiles_); | 422 generator_ = new ProfileGenerator(profiles_); |
| 421 processor_ = new ProfilerEventsProcessor(generator_); | 423 processor_ = new ProfilerEventsProcessor(generator_); |
| 422 processor_->Start(); | 424 processor_->Start(); |
| 423 // Enumerate stuff we already have in the heap. | 425 // Enumerate stuff we already have in the heap. |
| 424 if (Heap::HasBeenSetup()) { | 426 if (Heap::HasBeenSetup()) { |
| 425 Logger::LogCodeObjects(); | 427 Logger::LogCodeObjects(); |
| 426 Logger::LogCompiledFunctions(); | 428 Logger::LogCompiledFunctions(); |
| 427 Logger::LogFunctionObjects(); | 429 Logger::LogFunctionObjects(); |
| 428 Logger::LogAccessorCallbacks(); | 430 Logger::LogAccessorCallbacks(); |
| 429 } | 431 } |
| 430 // Enable stack sampling. | 432 // Enable stack sampling. |
| 431 Logger::ticker_->Start(); | 433 reinterpret_cast<Sampler*>(Logger::ticker_)->Start(); |
| 432 } | 434 } |
| 433 } | 435 } |
| 434 | 436 |
| 435 | 437 |
| 436 CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) { | 438 CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) { |
| 437 StopProcessorIfLastProfile(); | 439 StopProcessorIfLastProfile(); |
| 438 CpuProfile* result = profiles_->StopProfiling(title); | 440 CpuProfile* result = profiles_->StopProfiling(title); |
| 439 if (result != NULL) { | 441 if (result != NULL) { |
| 440 result->Print(); | 442 result->Print(); |
| 441 } | 443 } |
| 442 return result; | 444 return result; |
| 443 } | 445 } |
| 444 | 446 |
| 445 | 447 |
| 446 CpuProfile* CpuProfiler::StopCollectingProfile(String* title) { | 448 CpuProfile* CpuProfiler::StopCollectingProfile(String* title) { |
| 447 StopProcessorIfLastProfile(); | 449 StopProcessorIfLastProfile(); |
| 448 return profiles_->StopProfiling(title); | 450 return profiles_->StopProfiling(title); |
| 449 } | 451 } |
| 450 | 452 |
| 451 | 453 |
| 452 void CpuProfiler::StopProcessorIfLastProfile() { | 454 void CpuProfiler::StopProcessorIfLastProfile() { |
| 453 if (profiles_->is_last_profile()) { | 455 if (profiles_->is_last_profile()) { |
| 454 Logger::ticker_->Stop(); | 456 reinterpret_cast<Sampler*>(Logger::ticker_)->Stop(); |
| 455 processor_->Stop(); | 457 processor_->Stop(); |
| 456 processor_->Join(); | 458 processor_->Join(); |
| 457 delete processor_; | 459 delete processor_; |
| 458 delete generator_; | 460 delete generator_; |
| 459 processor_ = NULL; | 461 processor_ = NULL; |
| 460 generator_ = NULL; | 462 generator_ = NULL; |
| 463 Logger::logging_nesting_ = saved_logging_nesting_; |
| 461 } | 464 } |
| 462 } | 465 } |
| 463 | 466 |
| 464 } } // namespace v8::internal | 467 } } // namespace v8::internal |
| 465 | 468 |
| 466 #endif // ENABLE_CPP_PROFILES_PROCESSOR | 469 #endif // ENABLE_CPP_PROFILES_PROCESSOR |
| 467 | 470 |
| 468 namespace v8 { | 471 namespace v8 { |
| 469 namespace internal { | 472 namespace internal { |
| 470 | 473 |
| 471 void CpuProfiler::Setup() { | 474 void CpuProfiler::Setup() { |
| 472 #ifdef ENABLE_CPP_PROFILES_PROCESSOR | 475 #ifdef ENABLE_CPP_PROFILES_PROCESSOR |
| 473 if (singleton_ == NULL) { | 476 if (singleton_ == NULL) { |
| 474 singleton_ = new CpuProfiler(); | 477 singleton_ = new CpuProfiler(); |
| 475 } | 478 } |
| 476 #endif | 479 #endif |
| 477 } | 480 } |
| 478 | 481 |
| 479 | 482 |
| 480 void CpuProfiler::TearDown() { | 483 void CpuProfiler::TearDown() { |
| 481 #ifdef ENABLE_CPP_PROFILES_PROCESSOR | 484 #ifdef ENABLE_CPP_PROFILES_PROCESSOR |
| 482 if (singleton_ != NULL) { | 485 if (singleton_ != NULL) { |
| 483 delete singleton_; | 486 delete singleton_; |
| 484 } | 487 } |
| 485 singleton_ = NULL; | 488 singleton_ = NULL; |
| 486 #endif | 489 #endif |
| 487 } | 490 } |
| 488 | 491 |
| 489 } } // namespace v8::internal | 492 } } // namespace v8::internal |
| OLD | NEW |