blob: 4197d4d54c9076015c8ffb10ea42fd40ad0c92d4 [file] [log] [blame]
Ben Murdochb0fe1622011-05-05 13:52:32 +01001// Copyright 2009-2010 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5#ifndef V8_HEAP_PROFILER_H_
6#define V8_HEAP_PROFILER_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/heap-snapshot-generator-inl.h"
9#include "src/isolate.h"
10#include "src/smart-pointers.h"
Steve Block6ded16b2010-05-10 14:33:55 +010011
Steve Blocka7e24c12009-10-30 11:49:00 +000012namespace v8 {
13namespace internal {
14
Kristian Monsen9dcf7e22010-06-28 14:14:28 +010015class HeapSnapshot;
Kristian Monsen9dcf7e22010-06-28 14:14:28 +010016
Steve Blocka7e24c12009-10-30 11:49:00 +000017class HeapProfiler {
18 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000019 explicit HeapProfiler(Heap* heap);
20 ~HeapProfiler();
Kristian Monsen9dcf7e22010-06-28 14:14:28 +010021
Ben Murdochb8a8cc12014-11-26 15:28:44 +000022 size_t GetMemorySizeUsedByProfiler();
Kristian Monsen9dcf7e22010-06-28 14:14:28 +010023
Ben Murdochb8a8cc12014-11-26 15:28:44 +000024 HeapSnapshot* TakeSnapshot(
25 const char* name,
26 v8::ActivityControl* control,
27 v8::HeapProfiler::ObjectNameResolver* resolver);
28 HeapSnapshot* TakeSnapshot(
29 String* name,
30 v8::ActivityControl* control,
31 v8::HeapProfiler::ObjectNameResolver* resolver);
32
33 void StartHeapObjectsTracking(bool track_allocations);
34 void StopHeapObjectsTracking();
35 AllocationTracker* allocation_tracker() const {
36 return allocation_tracker_.get();
37 }
38 HeapObjectsMap* heap_object_map() const { return ids_.get(); }
39 StringsStorage* names() const { return names_.get(); }
40
41 SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
42 int GetSnapshotsCount();
43 HeapSnapshot* GetSnapshot(int index);
44 SnapshotObjectId GetSnapshotObjectId(Handle<Object> obj);
45 void DeleteAllSnapshots();
46 void RemoveSnapshot(HeapSnapshot* snapshot);
47
48 void ObjectMoveEvent(Address from, Address to, int size);
49
50 void AllocationEvent(Address addr, int size);
51
52 void UpdateObjectSizeEvent(Address addr, int size);
Ben Murdoch3bec4d22010-07-22 14:51:16 +010053
Steve Block44f0eee2011-05-26 01:26:41 +010054 void DefineWrapperClass(
55 uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback);
56
57 v8::RetainedObjectInfo* ExecuteWrapperClassCallback(uint16_t class_id,
58 Object** wrapper);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000059 void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info);
60
61 bool is_tracking_object_moves() const { return is_tracking_object_moves_; }
62 bool is_tracking_allocations() const {
63 return !allocation_tracker_.is_empty();
Ben Murdoch3bec4d22010-07-22 14:51:16 +010064 }
65
Ben Murdochb8a8cc12014-11-26 15:28:44 +000066 Handle<HeapObject> FindHeapObjectById(SnapshotObjectId id);
67 void ClearHeapObjectMap();
Kristian Monsen9dcf7e22010-06-28 14:14:28 +010068
Ben Murdochb8a8cc12014-11-26 15:28:44 +000069 private:
70 Heap* heap() const { return ids_->heap(); }
71
72 // Mapping from HeapObject addresses to objects' uids.
73 SmartPointer<HeapObjectsMap> ids_;
74 List<HeapSnapshot*> snapshots_;
75 SmartPointer<StringsStorage> names_;
Kristian Monsen9dcf7e22010-06-28 14:14:28 +010076 unsigned next_snapshot_uid_;
Steve Block44f0eee2011-05-26 01:26:41 +010077 List<v8::HeapProfiler::WrapperInfoCallback> wrapper_callbacks_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000078 SmartPointer<AllocationTracker> allocation_tracker_;
79 bool is_tracking_object_moves_;
Steve Blocka7e24c12009-10-30 11:49:00 +000080};
81
Steve Blocka7e24c12009-10-30 11:49:00 +000082} } // namespace v8::internal
83
84#endif // V8_HEAP_PROFILER_H_