v8-heap-profiler-agent-impl.h 2.74 KB
Newer Older
1 2 3 4
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef V8_INSPECTOR_V8_HEAP_PROFILER_AGENT_IMPL_H_
#define V8_INSPECTOR_V8_HEAP_PROFILER_AGENT_IMPL_H_
7

8 9
#include <memory>

10
#include "src/base/macros.h"
11 12 13
#include "src/inspector/protocol/Forward.h"
#include "src/inspector/protocol/HeapProfiler.h"

14 15 16
namespace v8 {
class Isolate;
}
17 18 19 20 21 22

namespace v8_inspector {

class V8InspectorSessionImpl;

using protocol::Maybe;
23
using protocol::Response;
24 25 26 27 28 29

class V8HeapProfilerAgentImpl : public protocol::HeapProfiler::Backend {
 public:
  V8HeapProfilerAgentImpl(V8InspectorSessionImpl*, protocol::FrontendChannel*,
                          protocol::DictionaryValue* state);
  ~V8HeapProfilerAgentImpl() override;
30 31
  V8HeapProfilerAgentImpl(const V8HeapProfilerAgentImpl&) = delete;
  V8HeapProfilerAgentImpl& operator=(const V8HeapProfilerAgentImpl&) = delete;
32 33
  void restore();

34 35
  void collectGarbage(
      std::unique_ptr<CollectGarbageCallback> callback) override;
36

37 38
  Response enable() override;
  Response startTrackingHeapObjects(Maybe<bool> trackAllocations) override;
Arno Renevier's avatar
Arno Renevier committed
39 40 41
  Response stopTrackingHeapObjects(Maybe<bool> reportProgress,
                                   Maybe<bool> treatGlobalObjectsAsRoots,
                                   Maybe<bool> captureNumericValue) override;
42

43
  Response disable() override;
44

45
  Response takeHeapSnapshot(Maybe<bool> reportProgress,
Arno Renevier's avatar
Arno Renevier committed
46 47
                            Maybe<bool> treatGlobalObjectsAsRoots,
                            Maybe<bool> captureNumericValue) override;
48

49 50
  Response getObjectByHeapObjectId(
      const String16& heapSnapshotObjectId, Maybe<String16> objectGroup,
51
      std::unique_ptr<protocol::Runtime::RemoteObject>* result) override;
52 53 54 55 56 57 58
  Response addInspectedHeapObject(
      const String16& inspectedHeapObjectId) override;
  Response getHeapObjectId(const String16& objectId,
                           String16* heapSnapshotObjectId) override;

  Response startSampling(Maybe<double> samplingInterval) override;
  Response stopSampling(
59
      std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfile>*) override;
60 61
  Response getSamplingProfile(
      std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfile>*) override;
62 63

 private:
64 65 66
  struct AsyncGC;
  class GCTask;

67 68 69 70 71 72 73 74 75 76
  void startTrackingHeapObjectsInternal(bool trackAllocations);
  void stopTrackingHeapObjectsInternal();
  void requestHeapStatsUpdate();
  static void onTimer(void*);

  V8InspectorSessionImpl* m_session;
  v8::Isolate* m_isolate;
  protocol::HeapProfiler::Frontend m_frontend;
  protocol::DictionaryValue* m_state;
  bool m_hasTimer;
77
  std::shared_ptr<AsyncGC> m_async_gc;
78 79 80 81
};

}  // namespace v8_inspector

82
#endif  // V8_INSPECTOR_V8_HEAP_PROFILER_AGENT_IMPL_H_