| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // All ticks of the current dequeue_order are processed, | 132 // All ticks of the current dequeue_order are processed, |
| 133 // proceed to the next code event. | 133 // proceed to the next code event. |
| 134 ProcessCodeEvent(); | 134 ProcessCodeEvent(); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 // Schedule next sample. sampler_ is NULL in tests. | 137 // Schedule next sample. sampler_ is NULL in tests. |
| 138 if (sampler_) sampler_->DoSample(); | 138 if (sampler_) sampler_->DoSample(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 | 141 |
| 142 void ProfilerEventsProcessor::ProcessEventsAndYield() { | |
| 143 // Process ticks until we have any. | |
| 144 if (ProcessTicks()) { | |
| 145 // All ticks of the current dequeue_order are processed, | |
| 146 // proceed to the next code event. | |
| 147 ProcessCodeEvent(); | |
| 148 } | |
| 149 YieldCPU(); | |
| 150 } | |
| 151 | |
| 152 | |
| 153 void ProfilerEventsProcessor::Run() { | 142 void ProfilerEventsProcessor::Run() { |
| 154 while (running_) { | 143 while (running_) { |
| 155 if (Sampler::CanSampleOnProfilerEventsProcessorThread()) { | 144 ProcessEventsAndDoSample(); |
| 156 ProcessEventsAndDoSample(); | |
| 157 } else { | |
| 158 ProcessEventsAndYield(); | |
| 159 } | |
| 160 } | 145 } |
| 161 | 146 |
| 162 // Process remaining tick events. | 147 // Process remaining tick events. |
| 163 do { | 148 do { |
| 164 ProcessTicks(); | 149 ProcessTicks(); |
| 165 } while (ProcessCodeEvent()); | 150 } while (ProcessCodeEvent()); |
| 166 } | 151 } |
| 167 | 152 |
| 168 | 153 |
| 169 int CpuProfiler::GetProfilesCount() { | 154 int CpuProfiler::GetProfilesCount() { |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 processor_->Enqueue(evt_rec); | 360 processor_->Enqueue(evt_rec); |
| 376 } | 361 } |
| 377 | 362 |
| 378 | 363 |
| 379 CpuProfiler::CpuProfiler(Isolate* isolate) | 364 CpuProfiler::CpuProfiler(Isolate* isolate) |
| 380 : isolate_(isolate), | 365 : isolate_(isolate), |
| 381 profiles_(new CpuProfilesCollection()), | 366 profiles_(new CpuProfilesCollection()), |
| 382 next_profile_uid_(1), | 367 next_profile_uid_(1), |
| 383 generator_(NULL), | 368 generator_(NULL), |
| 384 processor_(NULL), | 369 processor_(NULL), |
| 385 need_to_stop_sampler_(false), | |
| 386 is_profiling_(false) { | 370 is_profiling_(false) { |
| 387 } | 371 } |
| 388 | 372 |
| 389 | 373 |
| 390 CpuProfiler::CpuProfiler(Isolate* isolate, | 374 CpuProfiler::CpuProfiler(Isolate* isolate, |
| 391 CpuProfilesCollection* test_profiles, | 375 CpuProfilesCollection* test_profiles, |
| 392 ProfileGenerator* test_generator, | 376 ProfileGenerator* test_generator, |
| 393 ProfilerEventsProcessor* test_processor) | 377 ProfilerEventsProcessor* test_processor) |
| 394 : isolate_(isolate), | 378 : isolate_(isolate), |
| 395 profiles_(test_profiles), | 379 profiles_(test_profiles), |
| 396 next_profile_uid_(1), | 380 next_profile_uid_(1), |
| 397 generator_(test_generator), | 381 generator_(test_generator), |
| 398 processor_(test_processor), | 382 processor_(test_processor), |
| 399 need_to_stop_sampler_(false), | |
| 400 is_profiling_(false) { | 383 is_profiling_(false) { |
| 401 } | 384 } |
| 402 | 385 |
| 403 | 386 |
| 404 CpuProfiler::~CpuProfiler() { | 387 CpuProfiler::~CpuProfiler() { |
| 405 ASSERT(!is_profiling_); | 388 ASSERT(!is_profiling_); |
| 406 delete profiles_; | 389 delete profiles_; |
| 407 } | 390 } |
| 408 | 391 |
| 409 | 392 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 440 is_profiling_ = true; | 423 is_profiling_ = true; |
| 441 // Enumerate stuff we already have in the heap. | 424 // Enumerate stuff we already have in the heap. |
| 442 ASSERT(isolate_->heap()->HasBeenSetUp()); | 425 ASSERT(isolate_->heap()->HasBeenSetUp()); |
| 443 if (!FLAG_prof_browser_mode) { | 426 if (!FLAG_prof_browser_mode) { |
| 444 logger->LogCodeObjects(); | 427 logger->LogCodeObjects(); |
| 445 } | 428 } |
| 446 logger->LogCompiledFunctions(); | 429 logger->LogCompiledFunctions(); |
| 447 logger->LogAccessorCallbacks(); | 430 logger->LogAccessorCallbacks(); |
| 448 LogBuiltins(); | 431 LogBuiltins(); |
| 449 // Enable stack sampling. | 432 // Enable stack sampling. |
| 450 if (Sampler::CanSampleOnProfilerEventsProcessorThread()) { | 433 sampler->SetHasProcessingThread(true); |
| 451 sampler->SetHasProcessingThread(true); | |
| 452 } | |
| 453 sampler->IncreaseProfilingDepth(); | 434 sampler->IncreaseProfilingDepth(); |
| 454 if (!sampler->IsActive()) { | |
| 455 sampler->Start(); | |
| 456 need_to_stop_sampler_ = true; | |
| 457 } | |
| 458 processor_->StartSynchronously(); | 435 processor_->StartSynchronously(); |
| 459 } | 436 } |
| 460 } | 437 } |
| 461 | 438 |
| 462 | 439 |
| 463 CpuProfile* CpuProfiler::StopProfiling(const char* title) { | 440 CpuProfile* CpuProfiler::StopProfiling(const char* title) { |
| 464 if (!is_profiling_) return NULL; | 441 if (!is_profiling_) return NULL; |
| 465 StopProcessorIfLastProfile(title); | 442 StopProcessorIfLastProfile(title); |
| 466 CpuProfile* result = profiles_->StopProfiling(title); | 443 CpuProfile* result = profiles_->StopProfiling(title); |
| 467 if (result != NULL) { | 444 if (result != NULL) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 480 | 457 |
| 481 | 458 |
| 482 void CpuProfiler::StopProcessorIfLastProfile(const char* title) { | 459 void CpuProfiler::StopProcessorIfLastProfile(const char* title) { |
| 483 if (profiles_->IsLastProfile(title)) StopProcessor(); | 460 if (profiles_->IsLastProfile(title)) StopProcessor(); |
| 484 } | 461 } |
| 485 | 462 |
| 486 | 463 |
| 487 void CpuProfiler::StopProcessor() { | 464 void CpuProfiler::StopProcessor() { |
| 488 Logger* logger = isolate_->logger(); | 465 Logger* logger = isolate_->logger(); |
| 489 Sampler* sampler = reinterpret_cast<Sampler*>(logger->ticker_); | 466 Sampler* sampler = reinterpret_cast<Sampler*>(logger->ticker_); |
| 490 sampler->DecreaseProfilingDepth(); | |
| 491 is_profiling_ = false; | 467 is_profiling_ = false; |
| 492 processor_->StopSynchronously(); | 468 processor_->StopSynchronously(); |
| 493 delete processor_; | 469 delete processor_; |
| 494 delete generator_; | 470 delete generator_; |
| 495 processor_ = NULL; | 471 processor_ = NULL; |
| 496 generator_ = NULL; | 472 generator_ = NULL; |
| 497 if (Sampler::CanSampleOnProfilerEventsProcessorThread()) { | 473 sampler->SetHasProcessingThread(false); |
| 498 sampler->SetHasProcessingThread(false); | 474 sampler->DecreaseProfilingDepth(); |
| 499 } | |
| 500 if (need_to_stop_sampler_) { | |
| 501 sampler->Stop(); | |
| 502 need_to_stop_sampler_ = false; | |
| 503 } | |
| 504 logger->is_logging_ = saved_is_logging_; | 475 logger->is_logging_ = saved_is_logging_; |
| 505 } | 476 } |
| 506 | 477 |
| 507 | 478 |
| 508 void CpuProfiler::LogBuiltins() { | 479 void CpuProfiler::LogBuiltins() { |
| 509 Builtins* builtins = isolate_->builtins(); | 480 Builtins* builtins = isolate_->builtins(); |
| 510 ASSERT(builtins->is_initialized()); | 481 ASSERT(builtins->is_initialized()); |
| 511 for (int i = 0; i < Builtins::builtin_count; i++) { | 482 for (int i = 0; i < Builtins::builtin_count; i++) { |
| 512 CodeEventsContainer evt_rec(CodeEventRecord::REPORT_BUILTIN); | 483 CodeEventsContainer evt_rec(CodeEventRecord::REPORT_BUILTIN); |
| 513 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; | 484 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; |
| 514 Builtins::Name id = static_cast<Builtins::Name>(i); | 485 Builtins::Name id = static_cast<Builtins::Name>(i); |
| 515 rec->start = builtins->builtin(id)->address(); | 486 rec->start = builtins->builtin(id)->address(); |
| 516 rec->builtin_id = id; | 487 rec->builtin_id = id; |
| 517 processor_->Enqueue(evt_rec); | 488 processor_->Enqueue(evt_rec); |
| 518 } | 489 } |
| 519 } | 490 } |
| 520 | 491 |
| 521 | 492 |
| 522 } } // namespace v8::internal | 493 } } // namespace v8::internal |
| OLD | NEW |