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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 #ifdef ENABLE_CPP_PROFILES_PROCESSOR | 549 #ifdef ENABLE_CPP_PROFILES_PROCESSOR |
550 if (Logger::state() == GC) continue; | 550 TickSample* sample = CpuProfiler::TickSampleEvent(); |
551 | 551 if (sample == NULL) continue; |
552 TickSample* sample = NULL; | 552 sample->pc = NULL; // Impossible value if sampling succeeds. |
| 553 sample->frames_count = 0; |
553 #else | 554 #else |
554 TickSample sample_obj; | 555 TickSample sample_obj; |
555 TickSample* sample = &sample_obj; | 556 TickSample* sample = &sample_obj; |
| 557 #endif // ENABLE_CPP_PROFILES_PROCESSOR |
556 | 558 |
557 // We always sample the VM state. | 559 // We always sample the VM state. |
558 sample->state = Logger::state(); | 560 sample->state = Logger::state(); |
559 #endif // ENABLE_CPP_PROFILES_PROCESSOR | |
560 | |
561 // If profiling, we record the pc and sp of the profiled thread. | 561 // If profiling, we record the pc and sp of the profiled thread. |
562 if (sampler_->IsProfiling() | 562 if (sampler_->IsProfiling() |
563 && KERN_SUCCESS == thread_suspend(profiled_thread_)) { | 563 && KERN_SUCCESS == thread_suspend(profiled_thread_)) { |
564 #if V8_HOST_ARCH_X64 | 564 #if V8_HOST_ARCH_X64 |
565 thread_state_flavor_t flavor = x86_THREAD_STATE64; | 565 thread_state_flavor_t flavor = x86_THREAD_STATE64; |
566 x86_thread_state64_t state; | 566 x86_thread_state64_t state; |
567 mach_msg_type_number_t count = x86_THREAD_STATE64_COUNT; | 567 mach_msg_type_number_t count = x86_THREAD_STATE64_COUNT; |
568 #if __DARWIN_UNIX03 | 568 #if __DARWIN_UNIX03 |
569 #define REGISTER_FIELD(name) __r ## name | 569 #define REGISTER_FIELD(name) __r ## name |
570 #else | 570 #else |
571 #define REGISTER_FIELD(name) r ## name | 571 #define REGISTER_FIELD(name) r ## name |
572 #endif // __DARWIN_UNIX03 | 572 #endif // __DARWIN_UNIX03 |
573 #elif V8_HOST_ARCH_IA32 | 573 #elif V8_HOST_ARCH_IA32 |
574 thread_state_flavor_t flavor = i386_THREAD_STATE; | 574 thread_state_flavor_t flavor = i386_THREAD_STATE; |
575 i386_thread_state_t state; | 575 i386_thread_state_t state; |
576 mach_msg_type_number_t count = i386_THREAD_STATE_COUNT; | 576 mach_msg_type_number_t count = i386_THREAD_STATE_COUNT; |
577 #if __DARWIN_UNIX03 | 577 #if __DARWIN_UNIX03 |
578 #define REGISTER_FIELD(name) __e ## name | 578 #define REGISTER_FIELD(name) __e ## name |
579 #else | 579 #else |
580 #define REGISTER_FIELD(name) e ## name | 580 #define REGISTER_FIELD(name) e ## name |
581 #endif // __DARWIN_UNIX03 | 581 #endif // __DARWIN_UNIX03 |
582 #else | 582 #else |
583 #error Unsupported Mac OS X host architecture. | 583 #error Unsupported Mac OS X host architecture. |
584 #endif // V8_HOST_ARCH | 584 #endif // V8_HOST_ARCH |
585 | 585 |
586 if (thread_get_state(profiled_thread_, | 586 if (thread_get_state(profiled_thread_, |
587 flavor, | 587 flavor, |
588 reinterpret_cast<natural_t*>(&state), | 588 reinterpret_cast<natural_t*>(&state), |
589 &count) == KERN_SUCCESS) { | 589 &count) == KERN_SUCCESS) { |
590 #ifdef ENABLE_CPP_PROFILES_PROCESSOR | 590 sample->pc = reinterpret_cast<Address>(state.REGISTER_FIELD(ip)); |
591 sample = CpuProfiler::TickSampleEvent(); | 591 sample->sp = reinterpret_cast<Address>(state.REGISTER_FIELD(sp)); |
592 #endif | 592 sample->fp = reinterpret_cast<Address>(state.REGISTER_FIELD(bp)); |
593 if (sample != NULL) { | 593 sampler_->SampleStack(sample); |
594 sample->pc = reinterpret_cast<Address>(state.REGISTER_FIELD(ip)); | |
595 sample->sp = reinterpret_cast<Address>(state.REGISTER_FIELD(sp)); | |
596 sample->fp = reinterpret_cast<Address>(state.REGISTER_FIELD(bp)); | |
597 sampler_->SampleStack(sample); | |
598 } | |
599 } | 594 } |
600 thread_resume(profiled_thread_); | 595 thread_resume(profiled_thread_); |
601 } | 596 } |
602 | 597 |
603 #ifndef ENABLE_CPP_PROFILES_PROCESSOR | 598 #ifndef ENABLE_CPP_PROFILES_PROCESSOR |
604 // Invoke tick handler with program counter and stack pointer. | 599 // Invoke tick handler with program counter and stack pointer. |
605 sampler_->Tick(sample); | 600 sampler_->Tick(sample); |
606 #endif | 601 #endif |
607 } | 602 } |
608 } | 603 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 | 659 |
665 // Deallocate Mach port for thread. | 660 // Deallocate Mach port for thread. |
666 if (IsProfiling()) { | 661 if (IsProfiling()) { |
667 mach_port_deallocate(data_->task_self_, data_->profiled_thread_); | 662 mach_port_deallocate(data_->task_self_, data_->profiled_thread_); |
668 } | 663 } |
669 } | 664 } |
670 | 665 |
671 #endif // ENABLE_LOGGING_AND_PROFILING | 666 #endif // ENABLE_LOGGING_AND_PROFILING |
672 | 667 |
673 } } // namespace v8::internal | 668 } } // namespace v8::internal |
OLD | NEW |