1 // Copyright 2016 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_PROFILER_TRACING_CPU_PROFILER_H_ 6 #define V8_PROFILER_TRACING_CPU_PROFILER_H_ 7 8 #include <memory> 9 10 #include "include/v8-platform.h" 11 #include "src/base/atomic-utils.h" 12 #include "src/base/macros.h" 13 #include "src/base/platform/mutex.h" 14 15 namespace v8 { 16 namespace internal { 17 18 class CpuProfiler; 19 class Isolate; 20 21 class TracingCpuProfilerImpl final 22 : private v8::TracingController::TraceStateObserver { 23 public: 24 explicit TracingCpuProfilerImpl(Isolate*); 25 ~TracingCpuProfilerImpl() override; 26 27 // v8::TracingController::TraceStateObserver 28 void OnTraceEnabled() final; 29 void OnTraceDisabled() final; 30 31 private: 32 void StartProfiling(); 33 void StopProfiling(); 34 35 Isolate* isolate_; 36 std::unique_ptr<CpuProfiler> profiler_; 37 bool profiling_enabled_; 38 base::Mutex mutex_; 39 40 DISALLOW_COPY_AND_ASSIGN(TracingCpuProfilerImpl); 41 }; 42 43 } // namespace internal 44 } // namespace v8 45 46 #endif // V8_PROFILER_TRACING_CPU_PROFILER_H_ 47