| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium 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 #ifndef CONTENT_RENDERER_DEVTOOLS_V8_SAMPLING_PROFILER_H_ | 5 #ifndef CONTENT_RENDERER_DEVTOOLS_V8_SAMPLING_PROFILER_H_ |
| 6 #define CONTENT_RENDERER_DEVTOOLS_V8_SAMPLING_PROFILER_H_ | 6 #define CONTENT_RENDERER_DEVTOOLS_V8_SAMPLING_PROFILER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/single_thread_task_runner.h" | |
| 12 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/trace_event/trace_log.h" | 12 #include "base/trace_event/trace_log.h" |
| 14 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 15 | 14 |
| 16 namespace content { | 15 namespace content { |
| 17 | 16 |
| 18 class Sampler; | 17 class Sampler; |
| 19 class V8SamplingThread; | 18 class V8SamplingThread; |
| 20 | 19 |
| 21 // The class monitors enablement of V8 CPU profiler and | 20 // The class monitors enablement of V8 CPU profiler and |
| 22 // spawns a sampling thread when needed. | 21 // spawns a sampling thread when needed. |
| 23 class CONTENT_EXPORT V8SamplingProfiler final | 22 class CONTENT_EXPORT V8SamplingProfiler final |
| 24 : public base::trace_event::TraceLog::EnabledStateObserver { | 23 : public base::trace_event::TraceLog::AsyncEnabledStateObserver { |
| 25 public: | 24 public: |
| 26 explicit V8SamplingProfiler(bool underTest = false); | 25 explicit V8SamplingProfiler(bool underTest = false); |
| 27 ~V8SamplingProfiler() override; | 26 ~V8SamplingProfiler() override; |
| 28 | 27 |
| 29 // Implementation of TraceLog::EnabledStateObserver | 28 // Implementation of TraceLog::EnabledStateObserver |
| 30 void OnTraceLogEnabled() override; | 29 void OnTraceLogEnabled() override; |
| 31 void OnTraceLogDisabled() override; | 30 void OnTraceLogDisabled() override; |
| 32 | 31 |
| 33 void EnableSamplingEventForTesting(int code_added_events, int sample_events); | 32 void EnableSamplingEventForTesting(int code_added_events, int sample_events); |
| 34 void WaitSamplingEventForTesting(); | 33 void WaitSamplingEventForTesting(); |
| 35 | 34 |
| 36 private: | 35 private: |
| 37 void StartSamplingThread(); | 36 void StartSamplingThread(); |
| 38 void StopSamplingThread(); | 37 void StopSamplingThread(); |
| 39 | 38 |
| 40 std::unique_ptr<base::WaitableEvent> waitable_event_for_testing_; | 39 std::unique_ptr<base::WaitableEvent> waitable_event_for_testing_; |
| 41 std::unique_ptr<V8SamplingThread> sampling_thread_; | 40 std::unique_ptr<V8SamplingThread> sampling_thread_; |
| 42 std::unique_ptr<Sampler> render_thread_sampler_; | 41 std::unique_ptr<Sampler> render_thread_sampler_; |
| 43 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 42 base::WeakPtrFactory<V8SamplingProfiler> weak_factory_; |
| 44 | 43 |
| 45 DISALLOW_COPY_AND_ASSIGN(V8SamplingProfiler); | 44 DISALLOW_COPY_AND_ASSIGN(V8SamplingProfiler); |
| 46 }; | 45 }; |
| 47 | 46 |
| 48 } // namespace content | 47 } // namespace content |
| 49 | 48 |
| 50 #endif // CONTENT_RENDERER_DEVTOOLS_V8_SAMPLING_PROFILER_H_ | 49 #endif // CONTENT_RENDERER_DEVTOOLS_V8_SAMPLING_PROFILER_H_ |
| OLD | NEW |