| 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 28 matching lines...) Expand all Loading... |
| 39 #include "../include/v8-profiler.h" | 39 #include "../include/v8-profiler.h" |
| 40 | 40 |
| 41 namespace v8 { | 41 namespace v8 { |
| 42 namespace internal { | 42 namespace internal { |
| 43 | 43 |
| 44 static const int kEventsBufferSize = 256*KB; | 44 static const int kEventsBufferSize = 256*KB; |
| 45 static const int kTickSamplesBufferChunkSize = 64*KB; | 45 static const int kTickSamplesBufferChunkSize = 64*KB; |
| 46 static const int kTickSamplesBufferChunksCount = 16; | 46 static const int kTickSamplesBufferChunksCount = 16; |
| 47 | 47 |
| 48 | 48 |
| 49 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator) | 49 ProfilerEventsProcessor::ProfilerEventsProcessor(Isolate* isolate, |
| 50 : Thread("v8:ProfEvntProc"), | 50 ProfileGenerator* generator) |
| 51 : Thread(isolate, "v8:ProfEvntProc"), |
| 51 generator_(generator), | 52 generator_(generator), |
| 52 running_(true), | 53 running_(true), |
| 53 ticks_buffer_(sizeof(TickSampleEventRecord), | 54 ticks_buffer_(sizeof(TickSampleEventRecord), |
| 54 kTickSamplesBufferChunkSize, | 55 kTickSamplesBufferChunkSize, |
| 55 kTickSamplesBufferChunksCount), | 56 kTickSamplesBufferChunksCount), |
| 56 enqueue_order_(0) { | 57 enqueue_order_(0) { |
| 57 } | 58 } |
| 58 | 59 |
| 59 | 60 |
| 60 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag, | 61 void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 rec->start = start; | 177 rec->start = start; |
| 177 rec->entry = generator_->NewCodeEntry(tag, prefix, name); | 178 rec->entry = generator_->NewCodeEntry(tag, prefix, name); |
| 178 rec->size = size; | 179 rec->size = size; |
| 179 events_buffer_.Enqueue(evt_rec); | 180 events_buffer_.Enqueue(evt_rec); |
| 180 } | 181 } |
| 181 | 182 |
| 182 | 183 |
| 183 void ProfilerEventsProcessor::AddCurrentStack() { | 184 void ProfilerEventsProcessor::AddCurrentStack() { |
| 184 TickSampleEventRecord record; | 185 TickSampleEventRecord record; |
| 185 TickSample* sample = &record.sample; | 186 TickSample* sample = &record.sample; |
| 186 sample->state = Top::current_vm_state(); | 187 sample->state = Isolate::Current()->current_vm_state(); |
| 187 sample->pc = reinterpret_cast<Address>(sample); // Not NULL. | 188 sample->pc = reinterpret_cast<Address>(sample); // Not NULL. |
| 188 sample->tos = NULL; | 189 sample->tos = NULL; |
| 189 sample->frames_count = 0; | 190 sample->frames_count = 0; |
| 190 for (StackTraceFrameIterator it; | 191 for (StackTraceFrameIterator it; |
| 191 !it.done() && sample->frames_count < TickSample::kMaxFramesCount; | 192 !it.done() && sample->frames_count < TickSample::kMaxFramesCount; |
| 192 it.Advance()) { | 193 it.Advance()) { |
| 193 sample->stack[sample->frames_count++] = it.frame()->pc(); | 194 sample->stack[sample->frames_count++] = it.frame()->pc(); |
| 194 } | 195 } |
| 195 record.order = enqueue_order_; | 196 record.order = enqueue_order_; |
| 196 ticks_from_vm_buffer_.Enqueue(record); | 197 ticks_from_vm_buffer_.Enqueue(record); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 YieldCPU(); | 266 YieldCPU(); |
| 266 } | 267 } |
| 267 | 268 |
| 268 // Process remaining tick events. | 269 // Process remaining tick events. |
| 269 ticks_buffer_.FlushResidualRecords(); | 270 ticks_buffer_.FlushResidualRecords(); |
| 270 // Perform processing until we have tick events, skip remaining code events. | 271 // Perform processing until we have tick events, skip remaining code events. |
| 271 while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { } | 272 while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { } |
| 272 } | 273 } |
| 273 | 274 |
| 274 | 275 |
| 275 CpuProfiler* CpuProfiler::singleton_ = NULL; | |
| 276 Atomic32 CpuProfiler::is_profiling_ = false; | |
| 277 | |
| 278 void CpuProfiler::StartProfiling(const char* title) { | 276 void CpuProfiler::StartProfiling(const char* title) { |
| 279 ASSERT(singleton_ != NULL); | 277 ASSERT(Isolate::Current()->cpu_profiler() != NULL); |
| 280 singleton_->StartCollectingProfile(title); | 278 Isolate::Current()->cpu_profiler()->StartCollectingProfile(title); |
| 281 } | 279 } |
| 282 | 280 |
| 283 | 281 |
| 284 void CpuProfiler::StartProfiling(String* title) { | 282 void CpuProfiler::StartProfiling(String* title) { |
| 285 ASSERT(singleton_ != NULL); | 283 ASSERT(Isolate::Current()->cpu_profiler() != NULL); |
| 286 singleton_->StartCollectingProfile(title); | 284 Isolate::Current()->cpu_profiler()->StartCollectingProfile(title); |
| 287 } | 285 } |
| 288 | 286 |
| 289 | 287 |
| 290 CpuProfile* CpuProfiler::StopProfiling(const char* title) { | 288 CpuProfile* CpuProfiler::StopProfiling(const char* title) { |
| 291 return is_profiling() ? singleton_->StopCollectingProfile(title) : NULL; | 289 return is_profiling() ? |
| 290 Isolate::Current()->cpu_profiler()->StopCollectingProfile(title) : NULL; |
| 292 } | 291 } |
| 293 | 292 |
| 294 | 293 |
| 295 CpuProfile* CpuProfiler::StopProfiling(Object* security_token, String* title) { | 294 CpuProfile* CpuProfiler::StopProfiling(Object* security_token, String* title) { |
| 296 return is_profiling() ? | 295 return is_profiling() ? |
| 297 singleton_->StopCollectingProfile(security_token, title) : NULL; | 296 Isolate::Current()->cpu_profiler()->StopCollectingProfile( |
| 297 security_token, title) : NULL; |
| 298 } | 298 } |
| 299 | 299 |
| 300 | 300 |
| 301 int CpuProfiler::GetProfilesCount() { | 301 int CpuProfiler::GetProfilesCount() { |
| 302 ASSERT(singleton_ != NULL); | 302 ASSERT(Isolate::Current()->cpu_profiler() != NULL); |
| 303 // The count of profiles doesn't depend on a security token. | 303 // The count of profiles doesn't depend on a security token. |
| 304 return singleton_->profiles_->Profiles( | 304 return Isolate::Current()->cpu_profiler()->profiles_->Profiles( |
| 305 TokenEnumerator::kNoSecurityToken)->length(); | 305 TokenEnumerator::kNoSecurityToken)->length(); |
| 306 } | 306 } |
| 307 | 307 |
| 308 | 308 |
| 309 CpuProfile* CpuProfiler::GetProfile(Object* security_token, int index) { | 309 CpuProfile* CpuProfiler::GetProfile(Object* security_token, int index) { |
| 310 ASSERT(singleton_ != NULL); | 310 ASSERT(Isolate::Current()->cpu_profiler() != NULL); |
| 311 const int token = singleton_->token_enumerator_->GetTokenId(security_token); | 311 CpuProfiler* profiler = Isolate::Current()->cpu_profiler(); |
| 312 return singleton_->profiles_->Profiles(token)->at(index); | 312 const int token = profiler->token_enumerator_->GetTokenId(security_token); |
| 313 return profiler->profiles_->Profiles(token)->at(index); |
| 313 } | 314 } |
| 314 | 315 |
| 315 | 316 |
| 316 CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) { | 317 CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) { |
| 317 ASSERT(singleton_ != NULL); | 318 ASSERT(Isolate::Current()->cpu_profiler() != NULL); |
| 318 const int token = singleton_->token_enumerator_->GetTokenId(security_token); | 319 CpuProfiler* profiler = Isolate::Current()->cpu_profiler(); |
| 319 return singleton_->profiles_->GetProfile(token, uid); | 320 const int token = profiler->token_enumerator_->GetTokenId(security_token); |
| 321 return profiler->profiles_->GetProfile(token, uid); |
| 320 } | 322 } |
| 321 | 323 |
| 322 | 324 |
| 323 TickSample* CpuProfiler::TickSampleEvent() { | 325 TickSample* CpuProfiler::TickSampleEvent(Isolate* isolate) { |
| 324 if (CpuProfiler::is_profiling()) { | 326 if (CpuProfiler::is_profiling(isolate)) { |
| 325 return singleton_->processor_->TickSampleEvent(); | 327 return isolate->cpu_profiler()->processor_->TickSampleEvent(); |
| 326 } else { | 328 } else { |
| 327 return NULL; | 329 return NULL; |
| 328 } | 330 } |
| 329 } | 331 } |
| 330 | 332 |
| 331 | 333 |
| 332 void CpuProfiler::CallbackEvent(String* name, Address entry_point) { | 334 void CpuProfiler::CallbackEvent(String* name, Address entry_point) { |
| 333 singleton_->processor_->CallbackCreateEvent( | 335 Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent( |
| 334 Logger::CALLBACK_TAG, CodeEntry::kEmptyNamePrefix, name, entry_point); | 336 Logger::CALLBACK_TAG, CodeEntry::kEmptyNamePrefix, name, entry_point); |
| 335 } | 337 } |
| 336 | 338 |
| 337 | 339 |
| 338 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, | 340 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 339 Code* code, const char* comment) { | 341 Code* code, const char* comment) { |
| 340 singleton_->processor_->CodeCreateEvent( | 342 Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent( |
| 341 tag, comment, code->address(), code->ExecutableSize()); | 343 tag, comment, code->address(), code->ExecutableSize()); |
| 342 } | 344 } |
| 343 | 345 |
| 344 | 346 |
| 345 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, | 347 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 346 Code* code, String* name) { | 348 Code* code, String* name) { |
| 347 singleton_->processor_->CodeCreateEvent( | 349 Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent( |
| 348 tag, | 350 tag, |
| 349 name, | 351 name, |
| 350 Heap::empty_string(), | 352 HEAP->empty_string(), |
| 351 v8::CpuProfileNode::kNoLineNumberInfo, | 353 v8::CpuProfileNode::kNoLineNumberInfo, |
| 352 code->address(), | 354 code->address(), |
| 353 code->ExecutableSize(), | 355 code->ExecutableSize(), |
| 354 NULL); | 356 NULL); |
| 355 } | 357 } |
| 356 | 358 |
| 357 | 359 |
| 358 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, | 360 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 359 Code* code, | 361 Code* code, |
| 360 SharedFunctionInfo* shared, | 362 SharedFunctionInfo* shared, |
| 361 String* name) { | 363 String* name) { |
| 362 singleton_->processor_->CodeCreateEvent( | 364 Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent( |
| 363 tag, | 365 tag, |
| 364 name, | 366 name, |
| 365 Heap::empty_string(), | 367 HEAP->empty_string(), |
| 366 v8::CpuProfileNode::kNoLineNumberInfo, | 368 v8::CpuProfileNode::kNoLineNumberInfo, |
| 367 code->address(), | 369 code->address(), |
| 368 code->ExecutableSize(), | 370 code->ExecutableSize(), |
| 369 shared->address()); | 371 shared->address()); |
| 370 } | 372 } |
| 371 | 373 |
| 372 | 374 |
| 373 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, | 375 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 374 Code* code, | 376 Code* code, |
| 375 SharedFunctionInfo* shared, | 377 SharedFunctionInfo* shared, |
| 376 String* source, int line) { | 378 String* source, int line) { |
| 377 singleton_->processor_->CodeCreateEvent( | 379 Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent( |
| 378 tag, | 380 tag, |
| 379 shared->DebugName(), | 381 shared->DebugName(), |
| 380 source, | 382 source, |
| 381 line, | 383 line, |
| 382 code->address(), | 384 code->address(), |
| 383 code->ExecutableSize(), | 385 code->ExecutableSize(), |
| 384 shared->address()); | 386 shared->address()); |
| 385 } | 387 } |
| 386 | 388 |
| 387 | 389 |
| 388 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, | 390 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 389 Code* code, int args_count) { | 391 Code* code, int args_count) { |
| 390 singleton_->processor_->CodeCreateEvent( | 392 Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent( |
| 391 tag, | 393 tag, |
| 392 args_count, | 394 args_count, |
| 393 code->address(), | 395 code->address(), |
| 394 code->ExecutableSize()); | 396 code->ExecutableSize()); |
| 395 } | 397 } |
| 396 | 398 |
| 397 | 399 |
| 398 void CpuProfiler::CodeMoveEvent(Address from, Address to) { | 400 void CpuProfiler::CodeMoveEvent(Address from, Address to) { |
| 399 singleton_->processor_->CodeMoveEvent(from, to); | 401 Isolate::Current()->cpu_profiler()->processor_->CodeMoveEvent(from, to); |
| 400 } | 402 } |
| 401 | 403 |
| 402 | 404 |
| 403 void CpuProfiler::CodeDeleteEvent(Address from) { | 405 void CpuProfiler::CodeDeleteEvent(Address from) { |
| 404 singleton_->processor_->CodeDeleteEvent(from); | 406 Isolate::Current()->cpu_profiler()->processor_->CodeDeleteEvent(from); |
| 405 } | 407 } |
| 406 | 408 |
| 407 | 409 |
| 408 void CpuProfiler::SharedFunctionInfoMoveEvent(Address from, Address to) { | 410 void CpuProfiler::SharedFunctionInfoMoveEvent(Address from, Address to) { |
| 409 singleton_->processor_->SharedFunctionInfoMoveEvent(from, to); | 411 CpuProfiler* profiler = Isolate::Current()->cpu_profiler(); |
| 412 profiler->processor_->SharedFunctionInfoMoveEvent(from, to); |
| 410 } | 413 } |
| 411 | 414 |
| 412 | 415 |
| 413 void CpuProfiler::GetterCallbackEvent(String* name, Address entry_point) { | 416 void CpuProfiler::GetterCallbackEvent(String* name, Address entry_point) { |
| 414 singleton_->processor_->CallbackCreateEvent( | 417 Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent( |
| 415 Logger::CALLBACK_TAG, "get ", name, entry_point); | 418 Logger::CALLBACK_TAG, "get ", name, entry_point); |
| 416 } | 419 } |
| 417 | 420 |
| 418 | 421 |
| 419 void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) { | 422 void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) { |
| 420 singleton_->processor_->RegExpCodeCreateEvent( | 423 Isolate::Current()->cpu_profiler()->processor_->RegExpCodeCreateEvent( |
| 421 Logger::REG_EXP_TAG, | 424 Logger::REG_EXP_TAG, |
| 422 "RegExp: ", | 425 "RegExp: ", |
| 423 source, | 426 source, |
| 424 code->address(), | 427 code->address(), |
| 425 code->ExecutableSize()); | 428 code->ExecutableSize()); |
| 426 } | 429 } |
| 427 | 430 |
| 428 | 431 |
| 429 void CpuProfiler::SetterCallbackEvent(String* name, Address entry_point) { | 432 void CpuProfiler::SetterCallbackEvent(String* name, Address entry_point) { |
| 430 singleton_->processor_->CallbackCreateEvent( | 433 Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent( |
| 431 Logger::CALLBACK_TAG, "set ", name, entry_point); | 434 Logger::CALLBACK_TAG, "set ", name, entry_point); |
| 432 } | 435 } |
| 433 | 436 |
| 434 | 437 |
| 435 CpuProfiler::CpuProfiler() | 438 CpuProfiler::CpuProfiler() |
| 436 : profiles_(new CpuProfilesCollection()), | 439 : profiles_(new CpuProfilesCollection()), |
| 437 next_profile_uid_(1), | 440 next_profile_uid_(1), |
| 438 token_enumerator_(new TokenEnumerator()), | 441 token_enumerator_(new TokenEnumerator()), |
| 439 generator_(NULL), | 442 generator_(NULL), |
| 440 processor_(NULL) { | 443 processor_(NULL), |
| 444 is_profiling_(false) { |
| 441 } | 445 } |
| 442 | 446 |
| 443 | 447 |
| 444 CpuProfiler::~CpuProfiler() { | 448 CpuProfiler::~CpuProfiler() { |
| 445 delete token_enumerator_; | 449 delete token_enumerator_; |
| 446 delete profiles_; | 450 delete profiles_; |
| 447 } | 451 } |
| 448 | 452 |
| 449 | 453 |
| 450 void CpuProfiler::StartCollectingProfile(const char* title) { | 454 void CpuProfiler::StartCollectingProfile(const char* title) { |
| 451 if (profiles_->StartProfiling(title, next_profile_uid_++)) { | 455 if (profiles_->StartProfiling(title, next_profile_uid_++)) { |
| 452 StartProcessorIfNotStarted(); | 456 StartProcessorIfNotStarted(); |
| 453 } | 457 } |
| 454 processor_->AddCurrentStack(); | 458 processor_->AddCurrentStack(); |
| 455 } | 459 } |
| 456 | 460 |
| 457 | 461 |
| 458 void CpuProfiler::StartCollectingProfile(String* title) { | 462 void CpuProfiler::StartCollectingProfile(String* title) { |
| 459 StartCollectingProfile(profiles_->GetName(title)); | 463 StartCollectingProfile(profiles_->GetName(title)); |
| 460 } | 464 } |
| 461 | 465 |
| 462 | 466 |
| 463 void CpuProfiler::StartProcessorIfNotStarted() { | 467 void CpuProfiler::StartProcessorIfNotStarted() { |
| 464 if (processor_ == NULL) { | 468 if (processor_ == NULL) { |
| 465 // Disable logging when using the new implementation. | 469 // Disable logging when using the new implementation. |
| 466 saved_logging_nesting_ = Logger::logging_nesting_; | 470 saved_logging_nesting_ = LOGGER->logging_nesting_; |
| 467 Logger::logging_nesting_ = 0; | 471 LOGGER->logging_nesting_ = 0; |
| 468 generator_ = new ProfileGenerator(profiles_); | 472 generator_ = new ProfileGenerator(profiles_); |
| 469 processor_ = new ProfilerEventsProcessor(generator_); | 473 processor_ = new ProfilerEventsProcessor(Isolate::Current(), generator_); |
| 470 NoBarrier_Store(&is_profiling_, true); | 474 NoBarrier_Store(&is_profiling_, true); |
| 471 processor_->Start(); | 475 processor_->Start(); |
| 472 // Enumerate stuff we already have in the heap. | 476 // Enumerate stuff we already have in the heap. |
| 473 if (Heap::HasBeenSetup()) { | 477 if (HEAP->HasBeenSetup()) { |
| 474 if (!FLAG_prof_browser_mode) { | 478 if (!FLAG_prof_browser_mode) { |
| 475 bool saved_log_code_flag = FLAG_log_code; | 479 bool saved_log_code_flag = FLAG_log_code; |
| 476 FLAG_log_code = true; | 480 FLAG_log_code = true; |
| 477 Logger::LogCodeObjects(); | 481 LOGGER->LogCodeObjects(); |
| 478 FLAG_log_code = saved_log_code_flag; | 482 FLAG_log_code = saved_log_code_flag; |
| 479 } | 483 } |
| 480 Logger::LogCompiledFunctions(); | 484 LOGGER->LogCompiledFunctions(); |
| 481 Logger::LogAccessorCallbacks(); | 485 LOGGER->LogAccessorCallbacks(); |
| 482 } | 486 } |
| 483 // Enable stack sampling. | 487 // Enable stack sampling. |
| 484 Sampler* sampler = reinterpret_cast<Sampler*>(Logger::ticker_); | 488 Sampler* sampler = reinterpret_cast<Sampler*>(LOGGER->ticker_); |
| 485 if (!sampler->IsActive()) sampler->Start(); | 489 if (!sampler->IsActive()) sampler->Start(); |
| 486 sampler->IncreaseProfilingDepth(); | 490 sampler->IncreaseProfilingDepth(); |
| 487 } | 491 } |
| 488 } | 492 } |
| 489 | 493 |
| 490 | 494 |
| 491 CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) { | 495 CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) { |
| 492 const double actual_sampling_rate = generator_->actual_sampling_rate(); | 496 const double actual_sampling_rate = generator_->actual_sampling_rate(); |
| 493 StopProcessorIfLastProfile(title); | 497 StopProcessorIfLastProfile(title); |
| 494 CpuProfile* result = | 498 CpuProfile* result = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 507 const double actual_sampling_rate = generator_->actual_sampling_rate(); | 511 const double actual_sampling_rate = generator_->actual_sampling_rate(); |
| 508 const char* profile_title = profiles_->GetName(title); | 512 const char* profile_title = profiles_->GetName(title); |
| 509 StopProcessorIfLastProfile(profile_title); | 513 StopProcessorIfLastProfile(profile_title); |
| 510 int token = token_enumerator_->GetTokenId(security_token); | 514 int token = token_enumerator_->GetTokenId(security_token); |
| 511 return profiles_->StopProfiling(token, profile_title, actual_sampling_rate); | 515 return profiles_->StopProfiling(token, profile_title, actual_sampling_rate); |
| 512 } | 516 } |
| 513 | 517 |
| 514 | 518 |
| 515 void CpuProfiler::StopProcessorIfLastProfile(const char* title) { | 519 void CpuProfiler::StopProcessorIfLastProfile(const char* title) { |
| 516 if (profiles_->IsLastProfile(title)) { | 520 if (profiles_->IsLastProfile(title)) { |
| 517 Sampler* sampler = reinterpret_cast<Sampler*>(Logger::ticker_); | 521 Sampler* sampler = reinterpret_cast<Sampler*>(LOGGER->ticker_); |
| 518 sampler->DecreaseProfilingDepth(); | 522 sampler->DecreaseProfilingDepth(); |
| 519 sampler->Stop(); | 523 sampler->Stop(); |
| 520 processor_->Stop(); | 524 processor_->Stop(); |
| 521 processor_->Join(); | 525 processor_->Join(); |
| 522 delete processor_; | 526 delete processor_; |
| 523 delete generator_; | 527 delete generator_; |
| 524 processor_ = NULL; | 528 processor_ = NULL; |
| 525 NoBarrier_Store(&is_profiling_, false); | 529 NoBarrier_Store(&is_profiling_, false); |
| 526 generator_ = NULL; | 530 generator_ = NULL; |
| 527 Logger::logging_nesting_ = saved_logging_nesting_; | 531 LOGGER->logging_nesting_ = saved_logging_nesting_; |
| 528 } | 532 } |
| 529 } | 533 } |
| 530 | 534 |
| 531 } } // namespace v8::internal | 535 } } // namespace v8::internal |
| 532 | 536 |
| 533 #endif // ENABLE_LOGGING_AND_PROFILING | 537 #endif // ENABLE_LOGGING_AND_PROFILING |
| 534 | 538 |
| 535 namespace v8 { | 539 namespace v8 { |
| 536 namespace internal { | 540 namespace internal { |
| 537 | 541 |
| 538 void CpuProfiler::Setup() { | 542 void CpuProfiler::Setup() { |
| 539 #ifdef ENABLE_LOGGING_AND_PROFILING | 543 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 540 if (singleton_ == NULL) { | 544 Isolate* isolate = Isolate::Current(); |
| 541 singleton_ = new CpuProfiler(); | 545 if (isolate->cpu_profiler() == NULL) { |
| 546 isolate->set_cpu_profiler(new CpuProfiler()); |
| 542 } | 547 } |
| 543 #endif | 548 #endif |
| 544 } | 549 } |
| 545 | 550 |
| 546 | 551 |
| 547 void CpuProfiler::TearDown() { | 552 void CpuProfiler::TearDown() { |
| 548 #ifdef ENABLE_LOGGING_AND_PROFILING | 553 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 549 if (singleton_ != NULL) { | 554 Isolate* isolate = Isolate::Current(); |
| 550 delete singleton_; | 555 if (isolate->cpu_profiler() != NULL) { |
| 556 delete isolate->cpu_profiler(); |
| 551 } | 557 } |
| 552 singleton_ = NULL; | 558 isolate->set_cpu_profiler(NULL); |
| 553 #endif | 559 #endif |
| 554 } | 560 } |
| 555 | 561 |
| 556 } } // namespace v8::internal | 562 } } // namespace v8::internal |
| OLD | NEW |