OLD | NEW |
1 // Copyright 2009-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2009-2010 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/profiler/heap-profiler.h" | 5 #include "src/profiler/heap-profiler.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/debug/debug.h" | 8 #include "src/debug/debug.h" |
9 #include "src/profiler/allocation-tracker.h" | 9 #include "src/profiler/allocation-tracker.h" |
10 #include "src/profiler/heap-snapshot-generator-inl.h" | 10 #include "src/profiler/heap-snapshot-generator-inl.h" |
11 #include "src/profiler/sampling-heap-profiler.h" | 11 #include "src/profiler/sampling-heap-profiler.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
16 HeapProfiler::HeapProfiler(Heap* heap) | 16 HeapProfiler::HeapProfiler(Heap* heap) |
17 : ids_(new HeapObjectsMap(heap)), | 17 : ids_(new HeapObjectsMap(heap)), |
18 names_(new StringsStorage(heap)), | 18 names_(new StringsStorage(heap)), |
19 is_tracking_object_moves_(false) { | 19 is_tracking_object_moves_(false), |
20 } | 20 get_retainer_infos_callback_(nullptr) {} |
21 | |
22 | 21 |
23 static void DeleteHeapSnapshot(HeapSnapshot** snapshot_ptr) { | 22 static void DeleteHeapSnapshot(HeapSnapshot** snapshot_ptr) { |
24 delete *snapshot_ptr; | 23 delete *snapshot_ptr; |
25 } | 24 } |
26 | 25 |
27 | 26 |
28 HeapProfiler::~HeapProfiler() { | 27 HeapProfiler::~HeapProfiler() { |
29 snapshots_.Iterate(DeleteHeapSnapshot); | 28 snapshots_.Iterate(DeleteHeapSnapshot); |
30 snapshots_.Clear(); | 29 snapshots_.Clear(); |
31 } | 30 } |
(...skipping 22 matching lines...) Expand all Loading... |
54 } | 53 } |
55 | 54 |
56 | 55 |
57 v8::RetainedObjectInfo* HeapProfiler::ExecuteWrapperClassCallback( | 56 v8::RetainedObjectInfo* HeapProfiler::ExecuteWrapperClassCallback( |
58 uint16_t class_id, Object** wrapper) { | 57 uint16_t class_id, Object** wrapper) { |
59 if (wrapper_callbacks_.length() <= class_id) return NULL; | 58 if (wrapper_callbacks_.length() <= class_id) return NULL; |
60 return wrapper_callbacks_[class_id]( | 59 return wrapper_callbacks_[class_id]( |
61 class_id, Utils::ToLocal(Handle<Object>(wrapper))); | 60 class_id, Utils::ToLocal(Handle<Object>(wrapper))); |
62 } | 61 } |
63 | 62 |
| 63 void HeapProfiler::SetGetRetainerInfosCallback( |
| 64 v8::HeapProfiler::GetRetainerInfosCallback callback) { |
| 65 get_retainer_infos_callback_ = callback; |
| 66 } |
| 67 |
| 68 v8::HeapProfiler::RetainerInfos HeapProfiler::GetRetainerInfos( |
| 69 Isolate* isolate) { |
| 70 v8::HeapProfiler::RetainerInfos infos; |
| 71 if (get_retainer_infos_callback_ != nullptr) |
| 72 infos = |
| 73 get_retainer_infos_callback_(reinterpret_cast<v8::Isolate*>(isolate)); |
| 74 return infos; |
| 75 } |
64 | 76 |
65 HeapSnapshot* HeapProfiler::TakeSnapshot( | 77 HeapSnapshot* HeapProfiler::TakeSnapshot( |
66 v8::ActivityControl* control, | 78 v8::ActivityControl* control, |
67 v8::HeapProfiler::ObjectNameResolver* resolver) { | 79 v8::HeapProfiler::ObjectNameResolver* resolver) { |
68 HeapSnapshot* result = new HeapSnapshot(this); | 80 HeapSnapshot* result = new HeapSnapshot(this); |
69 { | 81 { |
70 HeapSnapshotGenerator generator(result, control, resolver, heap()); | 82 HeapSnapshotGenerator generator(result, control, resolver, heap()); |
71 if (!generator.GenerateSnapshot()) { | 83 if (!generator.GenerateSnapshot()) { |
72 delete result; | 84 delete result; |
73 result = NULL; | 85 result = NULL; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 ids_.reset(new HeapObjectsMap(heap())); | 229 ids_.reset(new HeapObjectsMap(heap())); |
218 if (!is_tracking_allocations()) is_tracking_object_moves_ = false; | 230 if (!is_tracking_allocations()) is_tracking_object_moves_ = false; |
219 } | 231 } |
220 | 232 |
221 | 233 |
222 Heap* HeapProfiler::heap() const { return ids_->heap(); } | 234 Heap* HeapProfiler::heap() const { return ids_->heap(); } |
223 | 235 |
224 | 236 |
225 } // namespace internal | 237 } // namespace internal |
226 } // namespace v8 | 238 } // namespace v8 |
OLD | NEW |