Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Side by Side Diff: src/platform-macos.cc

Issue 1582004: C++ profiles processor: wire up to VM. (Closed)
Patch Set: Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 Sampler* sampler_; 537 Sampler* sampler_;
538 // Note: for profiled_thread_ Mach primitives are used instead of PThread's 538 // Note: for profiled_thread_ Mach primitives are used instead of PThread's
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. 547 // Loop until the sampler is disengaged, keeping the specified samling freq.
548 while (sampler_->IsActive()) { 548 for ( ; sampler_->IsActive(); OS::Sleep(sampler_->interval_)) {
549 TickSample sample; 549 #ifdef ENABLE_CPP_PROFILES_PROCESSOR
550 if (Logger::state() == GC) continue;
551
552 TickSample* sample = NULL;
553 #else
554 TickSample sample_obj, *sample = &sample_obj;
550 555
551 // We always sample the VM state. 556 // We always sample the VM state.
552 sample.state = Logger::state(); 557 sample->state = Logger::state();
558 #endif // ENABLE_CPP_PROFILES_PROCESSOR
553 559
554 // If profiling, we record the pc and sp of the profiled thread. 560 // If profiling, we record the pc and sp of the profiled thread.
555 if (sampler_->IsProfiling() 561 if (sampler_->IsProfiling()
556 && KERN_SUCCESS == thread_suspend(profiled_thread_)) { 562 && KERN_SUCCESS == thread_suspend(profiled_thread_)) {
557 #if V8_HOST_ARCH_X64 563 #if V8_HOST_ARCH_X64
558 thread_state_flavor_t flavor = x86_THREAD_STATE64; 564 thread_state_flavor_t flavor = x86_THREAD_STATE64;
559 x86_thread_state64_t state; 565 x86_thread_state64_t state;
560 mach_msg_type_number_t count = x86_THREAD_STATE64_COUNT; 566 mach_msg_type_number_t count = x86_THREAD_STATE64_COUNT;
561 #if __DARWIN_UNIX03 567 #if __DARWIN_UNIX03
562 #define REGISTER_FIELD(name) __r ## name 568 #define REGISTER_FIELD(name) __r ## name
(...skipping 10 matching lines...) Expand all
573 #define REGISTER_FIELD(name) e ## name 579 #define REGISTER_FIELD(name) e ## name
574 #endif // __DARWIN_UNIX03 580 #endif // __DARWIN_UNIX03
575 #else 581 #else
576 #error Unsupported Mac OS X host architecture. 582 #error Unsupported Mac OS X host architecture.
577 #endif // V8_HOST_ARCH 583 #endif // V8_HOST_ARCH
578 584
579 if (thread_get_state(profiled_thread_, 585 if (thread_get_state(profiled_thread_,
580 flavor, 586 flavor,
581 reinterpret_cast<natural_t*>(&state), 587 reinterpret_cast<natural_t*>(&state),
582 &count) == KERN_SUCCESS) { 588 &count) == KERN_SUCCESS) {
583 sample.pc = reinterpret_cast<Address>(state.REGISTER_FIELD(ip)); 589 #ifdef ENABLE_CPP_PROFILES_PROCESSOR
584 sample.sp = reinterpret_cast<Address>(state.REGISTER_FIELD(sp)); 590 sample = CpuProfiler::TickSampleEvent();
585 sample.fp = reinterpret_cast<Address>(state.REGISTER_FIELD(bp)); 591 #endif
586 sampler_->SampleStack(&sample); 592 if (sample != NULL) {
593 sample->pc = reinterpret_cast<Address>(state.REGISTER_FIELD(ip));
594 sample->sp = reinterpret_cast<Address>(state.REGISTER_FIELD(sp));
595 sample->fp = reinterpret_cast<Address>(state.REGISTER_FIELD(bp));
596 sampler_->SampleStack(sample);
597 }
587 } 598 }
588 thread_resume(profiled_thread_); 599 thread_resume(profiled_thread_);
589 } 600 }
590 601
602 #ifndef ENABLE_CPP_PROFILES_PROCESSOR
591 // Invoke tick handler with program counter and stack pointer. 603 // Invoke tick handler with program counter and stack pointer.
592 sampler_->Tick(&sample); 604 sampler_->Tick(sample);
593 605 #endif
594 // Wait until next sampling.
595 usleep(sampler_->interval_ * 1000);
596 } 606 }
597 } 607 }
598 }; 608 };
599 609
600 #undef REGISTER_FIELD 610 #undef REGISTER_FIELD
601 611
602 612
603 // Entry point for sampler thread. 613 // Entry point for sampler thread.
604 static void* SamplerEntry(void* arg) { 614 static void* SamplerEntry(void* arg) {
605 Sampler::PlatformData* data = 615 Sampler::PlatformData* data =
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 663
654 // Deallocate Mach port for thread. 664 // Deallocate Mach port for thread.
655 if (IsProfiling()) { 665 if (IsProfiling()) {
656 mach_port_deallocate(data_->task_self_, data_->profiled_thread_); 666 mach_port_deallocate(data_->task_self_, data_->profiled_thread_);
657 } 667 }
658 } 668 }
659 669
660 #endif // ENABLE_LOGGING_AND_PROFILING 670 #endif // ENABLE_LOGGING_AND_PROFILING
661 671
662 } } // namespace v8::internal 672 } } // namespace v8::internal
OLDNEW
« src/platform-linux.cc ('K') | « src/platform-linux.cc ('k') | src/platform-win32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698