OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 // because the latter doesn't provide thread manipulation primitives required. | 539 // because the latter doesn't provide thread manipulation primitives required. |
540 // For details, consult "Mac OS X Internals" book, Section 7.3. | 540 // For details, consult "Mac OS X Internals" book, Section 7.3. |
541 mach_port_t task_self_; | 541 mach_port_t task_self_; |
542 thread_act_t profiled_thread_; | 542 thread_act_t profiled_thread_; |
543 pthread_t sampler_thread_; | 543 pthread_t sampler_thread_; |
544 | 544 |
545 // Sampler thread handler. | 545 // Sampler thread handler. |
546 void Runner() { | 546 void Runner() { |
547 // Loop until the sampler is disengaged, keeping the specified samling freq. | 547 // Loop until the sampler is disengaged, keeping the specified samling freq. |
548 for ( ; sampler_->IsActive(); OS::Sleep(sampler_->interval_)) { | 548 for ( ; sampler_->IsActive(); OS::Sleep(sampler_->interval_)) { |
| 549 TickSample sample_obj; |
| 550 TickSample* sample = NULL; |
549 #ifdef ENABLE_CPP_PROFILES_PROCESSOR | 551 #ifdef ENABLE_CPP_PROFILES_PROCESSOR |
550 TickSample* sample = CpuProfiler::TickSampleEvent(); | 552 sample = CpuProfiler::TickSampleEvent(); |
551 if (sample == NULL) continue; | 553 #endif |
552 sample->pc = NULL; // Impossible value if sampling succeeds. | 554 if (sample == NULL) sample = &sample_obj; |
553 sample->frames_count = 0; | |
554 #else | |
555 TickSample sample_obj; | |
556 TickSample* sample = &sample_obj; | |
557 #endif // ENABLE_CPP_PROFILES_PROCESSOR | |
558 | 555 |
559 // We always sample the VM state. | 556 // We always sample the VM state. |
560 sample->state = VMState::current_state(); | 557 sample->state = VMState::current_state(); |
561 // If profiling, we record the pc and sp of the profiled thread. | 558 // If profiling, we record the pc and sp of the profiled thread. |
562 if (sampler_->IsProfiling() | 559 if (sampler_->IsProfiling() |
563 && KERN_SUCCESS == thread_suspend(profiled_thread_)) { | 560 && KERN_SUCCESS == thread_suspend(profiled_thread_)) { |
564 #if V8_HOST_ARCH_X64 | 561 #if V8_HOST_ARCH_X64 |
565 thread_state_flavor_t flavor = x86_THREAD_STATE64; | 562 thread_state_flavor_t flavor = x86_THREAD_STATE64; |
566 x86_thread_state64_t state; | 563 x86_thread_state64_t state; |
567 mach_msg_type_number_t count = x86_THREAD_STATE64_COUNT; | 564 mach_msg_type_number_t count = x86_THREAD_STATE64_COUNT; |
(...skipping 20 matching lines...) Expand all Loading... |
588 reinterpret_cast<natural_t*>(&state), | 585 reinterpret_cast<natural_t*>(&state), |
589 &count) == KERN_SUCCESS) { | 586 &count) == KERN_SUCCESS) { |
590 sample->pc = reinterpret_cast<Address>(state.REGISTER_FIELD(ip)); | 587 sample->pc = reinterpret_cast<Address>(state.REGISTER_FIELD(ip)); |
591 sample->sp = reinterpret_cast<Address>(state.REGISTER_FIELD(sp)); | 588 sample->sp = reinterpret_cast<Address>(state.REGISTER_FIELD(sp)); |
592 sample->fp = reinterpret_cast<Address>(state.REGISTER_FIELD(bp)); | 589 sample->fp = reinterpret_cast<Address>(state.REGISTER_FIELD(bp)); |
593 sampler_->SampleStack(sample); | 590 sampler_->SampleStack(sample); |
594 } | 591 } |
595 thread_resume(profiled_thread_); | 592 thread_resume(profiled_thread_); |
596 } | 593 } |
597 | 594 |
598 #ifndef ENABLE_CPP_PROFILES_PROCESSOR | |
599 // Invoke tick handler with program counter and stack pointer. | 595 // Invoke tick handler with program counter and stack pointer. |
600 sampler_->Tick(sample); | 596 sampler_->Tick(sample); |
601 #endif | |
602 } | 597 } |
603 } | 598 } |
604 }; | 599 }; |
605 | 600 |
606 #undef REGISTER_FIELD | 601 #undef REGISTER_FIELD |
607 | 602 |
608 | 603 |
609 // Entry point for sampler thread. | 604 // Entry point for sampler thread. |
610 static void* SamplerEntry(void* arg) { | 605 static void* SamplerEntry(void* arg) { |
611 Sampler::PlatformData* data = | 606 Sampler::PlatformData* data = |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 | 654 |
660 // Deallocate Mach port for thread. | 655 // Deallocate Mach port for thread. |
661 if (IsProfiling()) { | 656 if (IsProfiling()) { |
662 mach_port_deallocate(data_->task_self_, data_->profiled_thread_); | 657 mach_port_deallocate(data_->task_self_, data_->profiled_thread_); |
663 } | 658 } |
664 } | 659 } |
665 | 660 |
666 #endif // ENABLE_LOGGING_AND_PROFILING | 661 #endif // ENABLE_LOGGING_AND_PROFILING |
667 | 662 |
668 } } // namespace v8::internal | 663 } } // namespace v8::internal |
OLD | NEW |