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_INSPECTOR_V8_HEAP_PROFILER_AGENT_IMPL_H_ 6 #define V8_INSPECTOR_V8_HEAP_PROFILER_AGENT_IMPL_H_ 7 8 #include <memory> 9 10 #include "src/base/macros.h" 11 #include "src/inspector/protocol/Forward.h" 12 #include "src/inspector/protocol/HeapProfiler.h" 13 14 #include "include/v8.h" 15 16 namespace v8_inspector { 17 18 class V8InspectorSessionImpl; 19 20 using protocol::Maybe; 21 using protocol::Response; 22 23 class V8HeapProfilerAgentImpl : public protocol::HeapProfiler::Backend { 24 public: 25 V8HeapProfilerAgentImpl(V8InspectorSessionImpl*, protocol::FrontendChannel*, 26 protocol::DictionaryValue* state); 27 ~V8HeapProfilerAgentImpl() override; 28 void restore(); 29 30 void collectGarbage( 31 std::unique_ptr<CollectGarbageCallback> callback) override; 32 33 Response enable() override; 34 Response startTrackingHeapObjects(Maybe<bool> trackAllocations) override; 35 Response stopTrackingHeapObjects( 36 Maybe<bool> reportProgress, 37 Maybe<bool> treatGlobalObjectsAsRoots) override; 38 39 Response disable() override; 40 41 Response takeHeapSnapshot(Maybe<bool> reportProgress, 42 Maybe<bool> treatGlobalObjectsAsRoots) override; 43 44 Response getObjectByHeapObjectId( 45 const String16& heapSnapshotObjectId, Maybe<String16> objectGroup, 46 std::unique_ptr<protocol::Runtime::RemoteObject>* result) override; 47 Response addInspectedHeapObject( 48 const String16& inspectedHeapObjectId) override; 49 Response getHeapObjectId(const String16& objectId, 50 String16* heapSnapshotObjectId) override; 51 52 Response startSampling(Maybe<double> samplingInterval) override; 53 Response stopSampling( 54 std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfile>*) override; 55 Response getSamplingProfile( 56 std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfile>*) override; 57 58 private: 59 struct AsyncGC; 60 class GCTask; 61 62 void startTrackingHeapObjectsInternal(bool trackAllocations); 63 void stopTrackingHeapObjectsInternal(); 64 void requestHeapStatsUpdate(); 65 static void onTimer(void*); 66 67 V8InspectorSessionImpl* m_session; 68 v8::Isolate* m_isolate; 69 protocol::HeapProfiler::Frontend m_frontend; 70 protocol::DictionaryValue* m_state; 71 bool m_hasTimer; 72 std::shared_ptr<AsyncGC> m_async_gc; 73 74 DISALLOW_COPY_AND_ASSIGN(V8HeapProfilerAgentImpl); 75 }; 76 77 } // namespace v8_inspector 78 79 #endif // V8_INSPECTOR_V8_HEAP_PROFILER_AGENT_IMPL_H_ 80