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