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