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

5 6
#ifndef V8_PROFILER_HEAP_PROFILER_H_
#define V8_PROFILER_HEAP_PROFILER_H_
7

8 9
#include <memory>

10
#include "src/isolate.h"
11
#include "src/list.h"
12

13 14 15
namespace v8 {
namespace internal {

16 17 18
// Forward declarations.
class AllocationTracker;
class HeapObjectsMap;
19
class HeapSnapshot;
20
class SamplingHeapProfiler;
21
class StringsStorage;
22

23 24
class HeapProfiler {
 public:
25 26
  explicit HeapProfiler(Heap* heap);
  ~HeapProfiler();
27

28
  size_t GetMemorySizeUsedByProfiler();
29

30
  HeapSnapshot* TakeSnapshot(
31 32
      v8::ActivityControl* control,
      v8::HeapProfiler::ObjectNameResolver* resolver);
33

34 35
  bool StartSamplingHeapProfiler(uint64_t sample_interval, int stack_depth,
                                 v8::HeapProfiler::SamplingFlags);
36
  void StopSamplingHeapProfiler();
37
  bool is_sampling_allocations() { return !!sampling_heap_profiler_; }
38 39
  AllocationProfile* GetAllocationProfile();

40
  void StartHeapObjectsTracking(bool track_allocations);
41
  void StopHeapObjectsTracking();
42 43 44 45 46
  AllocationTracker* allocation_tracker() const {
    return allocation_tracker_.get();
  }
  HeapObjectsMap* heap_object_map() const { return ids_.get(); }
  StringsStorage* names() const { return names_.get(); }
47

48 49
  SnapshotObjectId PushHeapObjectsStats(OutputStream* stream,
                                        int64_t* timestamp_us);
50 51 52 53
  int GetSnapshotsCount();
  HeapSnapshot* GetSnapshot(int index);
  SnapshotObjectId GetSnapshotObjectId(Handle<Object> obj);
  void DeleteAllSnapshots();
54
  void RemoveSnapshot(HeapSnapshot* snapshot);
55

56 57
  void ObjectMoveEvent(Address from, Address to, int size);

58
  void AllocationEvent(Address addr, int size);
59 60

  void UpdateObjectSizeEvent(Address addr, int size);
61

62
  void DefineWrapperClass(
63 64
      uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback);

65 66
  v8::RetainedObjectInfo* ExecuteWrapperClassCallback(uint16_t class_id,
                                                      Object** wrapper);
67 68
  void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info);

69
  bool is_tracking_object_moves() const { return is_tracking_object_moves_; }
70
  bool is_tracking_allocations() const { return !!allocation_tracker_; }
71

72
  Handle<HeapObject> FindHeapObjectById(SnapshotObjectId id);
73
  void ClearHeapObjectMap();
74

75 76
  Isolate* isolate() const { return heap()->isolate(); }

77
 private:
78
  Heap* heap() const;
79

80
  // Mapping from HeapObject addresses to objects' uids.
81
  std::unique_ptr<HeapObjectsMap> ids_;
82
  List<HeapSnapshot*> snapshots_;
83
  std::unique_ptr<StringsStorage> names_;
84
  List<v8::HeapProfiler::WrapperInfoCallback> wrapper_callbacks_;
85
  std::unique_ptr<AllocationTracker> allocation_tracker_;
86
  bool is_tracking_object_moves_;
87
  base::Mutex profiler_mutex_;
88 89 90
  std::unique_ptr<SamplingHeapProfiler> sampling_heap_profiler_;

  DISALLOW_COPY_AND_ASSIGN(HeapProfiler);
91 92
};

93 94
}  // namespace internal
}  // namespace v8
95

96
#endif  // V8_PROFILER_HEAP_PROFILER_H_