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