• 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_V8HEAPPROFILERAGENTIMPL_H_
6 #define V8_INSPECTOR_V8HEAPPROFILERAGENTIMPL_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 
50  private:
51   void startTrackingHeapObjectsInternal(bool trackAllocations);
52   void stopTrackingHeapObjectsInternal();
53   void requestHeapStatsUpdate();
54   static void onTimer(void*);
55 
56   V8InspectorSessionImpl* m_session;
57   v8::Isolate* m_isolate;
58   protocol::HeapProfiler::Frontend m_frontend;
59   protocol::DictionaryValue* m_state;
60   bool m_hasTimer;
61 
62   DISALLOW_COPY_AND_ASSIGN(V8HeapProfilerAgentImpl);
63 };
64 
65 }  // namespace v8_inspector
66 
67 #endif  // V8_INSPECTOR_V8HEAPPROFILERAGENTIMPL_H_
68