OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/log.h" | 5 #include "src/log.h" |
6 | 6 |
7 #include <cstdarg> | 7 #include <cstdarg> |
8 #include <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "src/v8.h" | 10 #include "src/v8.h" |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 int head_; // Index to the buffer head. | 645 int head_; // Index to the buffer head. |
646 base::Atomic32 tail_; // Index to the buffer tail. | 646 base::Atomic32 tail_; // Index to the buffer tail. |
647 bool overflow_; // Tell whether a buffer overflow has occurred. | 647 bool overflow_; // Tell whether a buffer overflow has occurred. |
648 // Sempahore used for buffer synchronization. | 648 // Sempahore used for buffer synchronization. |
649 base::Semaphore buffer_semaphore_; | 649 base::Semaphore buffer_semaphore_; |
650 | 650 |
651 // Tells whether profiler is engaged, that is, processing thread is stated. | 651 // Tells whether profiler is engaged, that is, processing thread is stated. |
652 bool engaged_; | 652 bool engaged_; |
653 | 653 |
654 // Tells whether worker thread should continue running. | 654 // Tells whether worker thread should continue running. |
655 bool running_; | 655 base::Atomic32 running_; |
656 | 656 |
657 // Tells whether we are currently recording tick samples. | 657 // Tells whether we are currently recording tick samples. |
658 bool paused_; | 658 bool paused_; |
659 }; | 659 }; |
660 | 660 |
661 | 661 |
662 // | 662 // |
663 // Ticker used to provide ticks to the profiler and the sliding state | 663 // Ticker used to provide ticks to the profiler and the sliding state |
664 // window. | 664 // window. |
665 // | 665 // |
(...skipping 30 matching lines...) Expand all Loading... |
696 // | 696 // |
697 // Profiler implementation. | 697 // Profiler implementation. |
698 // | 698 // |
699 Profiler::Profiler(Isolate* isolate) | 699 Profiler::Profiler(Isolate* isolate) |
700 : base::Thread(Options("v8:Profiler")), | 700 : base::Thread(Options("v8:Profiler")), |
701 isolate_(isolate), | 701 isolate_(isolate), |
702 head_(0), | 702 head_(0), |
703 overflow_(false), | 703 overflow_(false), |
704 buffer_semaphore_(0), | 704 buffer_semaphore_(0), |
705 engaged_(false), | 705 engaged_(false), |
706 running_(false), | |
707 paused_(false) { | 706 paused_(false) { |
708 base::NoBarrier_Store(&tail_, 0); | 707 base::NoBarrier_Store(&tail_, 0); |
| 708 base::NoBarrier_Store(&running_, 0); |
709 } | 709 } |
710 | 710 |
711 | 711 |
712 void Profiler::Engage() { | 712 void Profiler::Engage() { |
713 if (engaged_) return; | 713 if (engaged_) return; |
714 engaged_ = true; | 714 engaged_ = true; |
715 | 715 |
716 std::vector<base::OS::SharedLibraryAddress> addresses = | 716 std::vector<base::OS::SharedLibraryAddress> addresses = |
717 base::OS::GetSharedLibraryAddresses(); | 717 base::OS::GetSharedLibraryAddresses(); |
718 for (size_t i = 0; i < addresses.size(); ++i) { | 718 for (size_t i = 0; i < addresses.size(); ++i) { |
719 LOG(isolate_, SharedLibraryEvent( | 719 LOG(isolate_, SharedLibraryEvent( |
720 addresses[i].library_path, addresses[i].start, addresses[i].end)); | 720 addresses[i].library_path, addresses[i].start, addresses[i].end)); |
721 } | 721 } |
722 | 722 |
723 // Start thread processing the profiler buffer. | 723 // Start thread processing the profiler buffer. |
724 running_ = true; | 724 base::NoBarrier_Store(&running_, 1); |
725 Start(); | 725 Start(); |
726 | 726 |
727 // Register to get ticks. | 727 // Register to get ticks. |
728 Logger* logger = isolate_->logger(); | 728 Logger* logger = isolate_->logger(); |
729 logger->ticker_->SetProfiler(this); | 729 logger->ticker_->SetProfiler(this); |
730 | 730 |
731 logger->ProfilerBeginEvent(); | 731 logger->ProfilerBeginEvent(); |
732 } | 732 } |
733 | 733 |
734 | 734 |
735 void Profiler::Disengage() { | 735 void Profiler::Disengage() { |
736 if (!engaged_) return; | 736 if (!engaged_) return; |
737 | 737 |
738 // Stop receiving ticks. | 738 // Stop receiving ticks. |
739 isolate_->logger()->ticker_->ClearProfiler(); | 739 isolate_->logger()->ticker_->ClearProfiler(); |
740 | 740 |
741 // Terminate the worker thread by setting running_ to false, | 741 // Terminate the worker thread by setting running_ to false, |
742 // inserting a fake element in the queue and then wait for | 742 // inserting a fake element in the queue and then wait for |
743 // the thread to terminate. | 743 // the thread to terminate. |
744 running_ = false; | 744 base::NoBarrier_Store(&running_, 0); |
745 TickSample sample; | 745 TickSample sample; |
746 // Reset 'paused_' flag, otherwise semaphore may not be signalled. | 746 // Reset 'paused_' flag, otherwise semaphore may not be signalled. |
747 resume(); | 747 resume(); |
748 Insert(&sample); | 748 Insert(&sample); |
749 Join(); | 749 Join(); |
750 | 750 |
751 LOG(isolate_, UncheckedStringEvent("profiler", "end")); | 751 LOG(isolate_, UncheckedStringEvent("profiler", "end")); |
752 } | 752 } |
753 | 753 |
754 | 754 |
755 void Profiler::Run() { | 755 void Profiler::Run() { |
756 TickSample sample; | 756 TickSample sample; |
757 bool overflow = Remove(&sample); | 757 bool overflow = Remove(&sample); |
758 while (running_) { | 758 while (base::NoBarrier_Load(&running_)) { |
759 LOG(isolate_, TickEvent(&sample, overflow)); | 759 LOG(isolate_, TickEvent(&sample, overflow)); |
760 overflow = Remove(&sample); | 760 overflow = Remove(&sample); |
761 } | 761 } |
762 } | 762 } |
763 | 763 |
764 | 764 |
765 // | 765 // |
766 // Logger class implementation. | 766 // Logger class implementation. |
767 // | 767 // |
768 | 768 |
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1938 if (jit_logger_) { | 1938 if (jit_logger_) { |
1939 removeCodeEventListener(jit_logger_); | 1939 removeCodeEventListener(jit_logger_); |
1940 delete jit_logger_; | 1940 delete jit_logger_; |
1941 jit_logger_ = NULL; | 1941 jit_logger_ = NULL; |
1942 } | 1942 } |
1943 | 1943 |
1944 return log_->Close(); | 1944 return log_->Close(); |
1945 } | 1945 } |
1946 | 1946 |
1947 } } // namespace v8::internal | 1947 } } // namespace v8::internal |
OLD | NEW |