1 // Copyright 2015 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_INSPECTOR_V8_PROFILER_AGENT_IMPL_H_ 6 #define V8_INSPECTOR_V8_PROFILER_AGENT_IMPL_H_ 7 8 #include <vector> 9 10 #include "src/base/macros.h" 11 #include "src/inspector/protocol/Forward.h" 12 #include "src/inspector/protocol/Profiler.h" 13 14 namespace v8 { 15 class CpuProfiler; 16 class Isolate; 17 } 18 19 namespace v8_inspector { 20 21 class V8InspectorSessionImpl; 22 23 using protocol::Maybe; 24 using protocol::Response; 25 26 class V8ProfilerAgentImpl : public protocol::Profiler::Backend { 27 public: 28 V8ProfilerAgentImpl(V8InspectorSessionImpl*, protocol::FrontendChannel*, 29 protocol::DictionaryValue* state); 30 ~V8ProfilerAgentImpl() override; 31 enabled()32 bool enabled() const { return m_enabled; } 33 void restore(); 34 35 Response enable() override; 36 Response disable() override; 37 Response setSamplingInterval(int) override; 38 Response start() override; 39 Response stop(std::unique_ptr<protocol::Profiler::Profile>*) override; 40 41 Response startPreciseCoverage(Maybe<bool> binary, 42 Maybe<bool> detailed) override; 43 Response stopPreciseCoverage() override; 44 Response takePreciseCoverage( 45 std::unique_ptr<protocol::Array<protocol::Profiler::ScriptCoverage>>* 46 out_result) override; 47 Response getBestEffortCoverage( 48 std::unique_ptr<protocol::Array<protocol::Profiler::ScriptCoverage>>* 49 out_result) override; 50 51 Response startTypeProfile() override; 52 Response stopTypeProfile() override; 53 Response takeTypeProfile( 54 std::unique_ptr<protocol::Array<protocol::Profiler::ScriptTypeProfile>>* 55 out_result) override; 56 57 void consoleProfile(const String16& title); 58 void consoleProfileEnd(const String16& title); 59 60 private: 61 String16 nextProfileId(); 62 63 void startProfiling(const String16& title); 64 std::unique_ptr<protocol::Profiler::Profile> stopProfiling( 65 const String16& title, bool serialize); 66 67 V8InspectorSessionImpl* m_session; 68 v8::Isolate* m_isolate; 69 v8::CpuProfiler* m_profiler = nullptr; 70 protocol::DictionaryValue* m_state; 71 protocol::Profiler::Frontend m_frontend; 72 bool m_enabled = false; 73 bool m_recordingCPUProfile = false; 74 class ProfileDescriptor; 75 std::vector<ProfileDescriptor> m_startedProfiles; 76 String16 m_frontendInitiatedProfileId; 77 int m_startedProfilesCount = 0; 78 79 DISALLOW_COPY_AND_ASSIGN(V8ProfilerAgentImpl); 80 }; 81 82 } // namespace v8_inspector 83 84 #endif // V8_INSPECTOR_V8_PROFILER_AGENT_IMPL_H_ 85