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_V8PROFILERAGENTIMPL_H_ 6 #define V8_INSPECTOR_V8PROFILERAGENTIMPL_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::Response; 24 25 class V8ProfilerAgentImpl : public protocol::Profiler::Backend { 26 public: 27 V8ProfilerAgentImpl(V8InspectorSessionImpl*, protocol::FrontendChannel*, 28 protocol::DictionaryValue* state); 29 ~V8ProfilerAgentImpl() override; 30 enabled()31 bool enabled() const { return m_enabled; } 32 void restore(); 33 34 Response enable() override; 35 Response disable() override; 36 Response setSamplingInterval(int) override; 37 Response start() override; 38 Response stop(std::unique_ptr<protocol::Profiler::Profile>*) override; 39 40 void consoleProfile(const String16& title); 41 void consoleProfileEnd(const String16& title); 42 43 bool idleStarted(); 44 bool idleFinished(); 45 46 void collectSample(); 47 48 private: 49 String16 nextProfileId(); 50 51 void startProfiling(const String16& title); 52 std::unique_ptr<protocol::Profiler::Profile> stopProfiling( 53 const String16& title, bool serialize); 54 55 bool isRecording() const; 56 57 V8InspectorSessionImpl* m_session; 58 v8::Isolate* m_isolate; 59 v8::CpuProfiler* m_profiler; 60 protocol::DictionaryValue* m_state; 61 protocol::Profiler::Frontend m_frontend; 62 bool m_enabled; 63 bool m_recordingCPUProfile; 64 class ProfileDescriptor; 65 std::vector<ProfileDescriptor> m_startedProfiles; 66 String16 m_frontendInitiatedProfileId; 67 68 DISALLOW_COPY_AND_ASSIGN(V8ProfilerAgentImpl); 69 }; 70 71 } // namespace v8_inspector 72 73 #endif // V8_INSPECTOR_V8PROFILERAGENTIMPL_H_ 74