OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 virtual ~Sampler(); | 746 virtual ~Sampler(); |
747 | 747 |
748 int interval() const { return interval_; } | 748 int interval() const { return interval_; } |
749 | 749 |
750 // Performs stack sampling. | 750 // Performs stack sampling. |
751 void SampleStack(TickSample* sample) { | 751 void SampleStack(TickSample* sample) { |
752 DoSampleStack(sample); | 752 DoSampleStack(sample); |
753 IncSamplesTaken(); | 753 IncSamplesTaken(); |
754 } | 754 } |
755 | 755 |
756 // Performs platform-specific stack sampling. | |
757 void DoSample(); | |
758 | |
759 // This method is called for each sampling period with the current | 756 // This method is called for each sampling period with the current |
760 // program counter. | 757 // program counter. |
761 virtual void Tick(TickSample* sample) = 0; | 758 virtual void Tick(TickSample* sample) = 0; |
762 | 759 |
763 // Start and stop sampler. | 760 // Start and stop sampler. |
764 void Start(); | 761 void Start(); |
765 void Stop(); | 762 void Stop(); |
766 | 763 |
767 // Whether the sampling thread should use this Sampler for CPU profiling? | 764 // Is the sampler used for profiling? |
768 bool IsProfiling() const { | 765 bool IsProfiling() const { return NoBarrier_Load(&profiling_) > 0; } |
769 return NoBarrier_Load(&profiling_) > 0 && | 766 void IncreaseProfilingDepth() { NoBarrier_AtomicIncrement(&profiling_, 1); } |
770 !NoBarrier_Load(&has_processing_thread_); | 767 void DecreaseProfilingDepth() { NoBarrier_AtomicIncrement(&profiling_, -1); } |
771 } | |
772 // Perform platform-specific initialization before DoSample() may be invoked. | |
773 void StartSampling(); | |
774 // Perform platform-specific cleanup after samping. | |
775 void StopSampling(); | |
776 void IncreaseProfilingDepth() { | |
777 if (NoBarrier_AtomicIncrement(&profiling_, 1) == 1) { | |
778 StartSampling(); | |
779 } | |
780 } | |
781 void DecreaseProfilingDepth() { | |
782 if (!NoBarrier_AtomicIncrement(&profiling_, -1)) { | |
783 StopSampling(); | |
784 } | |
785 } | |
786 void SetHasProcessingThread(bool value) { | |
787 NoBarrier_Store(&has_processing_thread_, value); | |
788 } | |
789 | 768 |
790 // Whether the sampler is running (that is, consumes resources). | 769 // Whether the sampler is running (that is, consumes resources). |
791 bool IsActive() const { return NoBarrier_Load(&active_); } | 770 bool IsActive() const { return NoBarrier_Load(&active_); } |
792 | 771 |
793 Isolate* isolate() { return isolate_; } | 772 Isolate* isolate() { return isolate_; } |
794 | 773 |
795 // Used in tests to make sure that stack sampling is performed. | 774 // Used in tests to make sure that stack sampling is performed. |
796 int samples_taken() const { return samples_taken_; } | 775 int samples_taken() const { return samples_taken_; } |
797 void ResetSamplesTaken() { samples_taken_ = 0; } | 776 void ResetSamplesTaken() { samples_taken_ = 0; } |
798 | 777 |
799 class PlatformData; | 778 class PlatformData; |
800 PlatformData* data() { return data_; } | 779 PlatformData* data() { return data_; } |
801 | 780 |
802 PlatformData* platform_data() { return data_; } | 781 PlatformData* platform_data() { return data_; } |
803 | 782 |
804 protected: | 783 protected: |
805 virtual void DoSampleStack(TickSample* sample) = 0; | 784 virtual void DoSampleStack(TickSample* sample) = 0; |
806 | 785 |
807 private: | 786 private: |
808 void SetActive(bool value) { NoBarrier_Store(&active_, value); } | 787 void SetActive(bool value) { NoBarrier_Store(&active_, value); } |
809 void IncSamplesTaken() { if (++samples_taken_ < 0) samples_taken_ = 0; } | 788 void IncSamplesTaken() { if (++samples_taken_ < 0) samples_taken_ = 0; } |
810 | 789 |
811 Isolate* isolate_; | 790 Isolate* isolate_; |
812 const int interval_; | 791 const int interval_; |
813 Atomic32 profiling_; | 792 Atomic32 profiling_; |
814 Atomic32 active_; | 793 Atomic32 active_; |
815 Atomic32 has_processing_thread_; | |
816 PlatformData* data_; // Platform specific data. | 794 PlatformData* data_; // Platform specific data. |
817 int samples_taken_; // Counts stack samples taken. | 795 int samples_taken_; // Counts stack samples taken. |
818 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); | 796 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); |
819 }; | 797 }; |
820 | 798 |
821 | 799 |
822 } } // namespace v8::internal | 800 } } // namespace v8::internal |
823 | 801 |
824 #endif // V8_PLATFORM_H_ | 802 #endif // V8_PLATFORM_H_ |
OLD | NEW |