| 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 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "heap-profiler.h" | 30 #include "heap-profiler.h" |
| 31 #include "heap-snapshot-generator-inl.h" | 31 #include "heap-snapshot-generator-inl.h" |
| 32 | 32 |
| 33 namespace v8 { | 33 namespace v8 { |
| 34 namespace internal { | 34 namespace internal { |
| 35 | 35 |
| 36 HeapProfiler::HeapProfiler(Heap* heap) | 36 HeapProfiler::HeapProfiler(Heap* heap) |
| 37 : snapshots_(new HeapSnapshotsCollection(heap)), | 37 : snapshots_(new HeapSnapshotsCollection(heap)), |
| 38 next_snapshot_uid_(1) { | 38 next_snapshot_uid_(1), |
| 39 is_tracking_allocations_(0) { |
| 39 } | 40 } |
| 40 | 41 |
| 41 | 42 |
| 42 HeapProfiler::~HeapProfiler() { | 43 HeapProfiler::~HeapProfiler() { |
| 43 delete snapshots_; | 44 delete snapshots_; |
| 44 } | 45 } |
| 45 | 46 |
| 46 | 47 |
| 47 void HeapProfiler::DeleteAllSnapshots() { | 48 void HeapProfiler::DeleteAllSnapshots() { |
| 48 Heap* the_heap = heap(); | 49 Heap* the_heap = heap(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 67 if (wrapper_callbacks_.length() <= class_id) return NULL; | 68 if (wrapper_callbacks_.length() <= class_id) return NULL; |
| 68 return wrapper_callbacks_[class_id]( | 69 return wrapper_callbacks_[class_id]( |
| 69 class_id, Utils::ToLocal(Handle<Object>(wrapper))); | 70 class_id, Utils::ToLocal(Handle<Object>(wrapper))); |
| 70 } | 71 } |
| 71 | 72 |
| 72 | 73 |
| 73 HeapSnapshot* HeapProfiler::TakeSnapshot( | 74 HeapSnapshot* HeapProfiler::TakeSnapshot( |
| 74 const char* name, | 75 const char* name, |
| 75 v8::ActivityControl* control, | 76 v8::ActivityControl* control, |
| 76 v8::HeapProfiler::ObjectNameResolver* resolver) { | 77 v8::HeapProfiler::ObjectNameResolver* resolver) { |
| 78 is_tracking_allocations_++; |
| 77 HeapSnapshot* result = snapshots_->NewSnapshot(name, next_snapshot_uid_++); | 79 HeapSnapshot* result = snapshots_->NewSnapshot(name, next_snapshot_uid_++); |
| 78 { | 80 { |
| 79 HeapSnapshotGenerator generator(result, control, resolver, heap()); | 81 HeapSnapshotGenerator generator(result, control, resolver, heap()); |
| 80 if (!generator.GenerateSnapshot()) { | 82 if (!generator.GenerateSnapshot()) { |
| 81 delete result; | 83 delete result; |
| 82 result = NULL; | 84 result = NULL; |
| 83 } | 85 } |
| 84 } | 86 } |
| 85 snapshots_->SnapshotGenerationFinished(result); | 87 snapshots_->SnapshotGenerationFinished(result); |
| 86 return result; | 88 return result; |
| 87 } | 89 } |
| 88 | 90 |
| 89 | 91 |
| 90 HeapSnapshot* HeapProfiler::TakeSnapshot( | 92 HeapSnapshot* HeapProfiler::TakeSnapshot( |
| 91 String* name, | 93 String* name, |
| 92 v8::ActivityControl* control, | 94 v8::ActivityControl* control, |
| 93 v8::HeapProfiler::ObjectNameResolver* resolver) { | 95 v8::HeapProfiler::ObjectNameResolver* resolver) { |
| 94 return TakeSnapshot(snapshots_->names()->GetName(name), control, resolver); | 96 return TakeSnapshot(snapshots_->names()->GetName(name), control, resolver); |
| 95 } | 97 } |
| 96 | 98 |
| 97 | 99 |
| 98 void HeapProfiler::StartHeapObjectsTracking() { | 100 void HeapProfiler::StartHeapObjectsTracking() { |
| 99 snapshots_->StartHeapObjectsTracking(); | 101 if (++is_tracking_allocations_ == 1) { |
| 102 snapshots_->StartHeapObjectsTracking(); |
| 103 } |
| 100 } | 104 } |
| 101 | 105 |
| 102 | 106 |
| 103 SnapshotObjectId HeapProfiler::PushHeapObjectsStats(OutputStream* stream) { | 107 SnapshotObjectId HeapProfiler::PushHeapObjectsStats(OutputStream* stream) { |
| 104 return snapshots_->PushHeapObjectsStats(stream); | 108 return snapshots_->PushHeapObjectsStats(stream); |
| 105 } | 109 } |
| 106 | 110 |
| 107 | 111 |
| 108 void HeapProfiler::StopHeapObjectsTracking() { | 112 void HeapProfiler::StopHeapObjectsTracking() { |
| 109 snapshots_->StopHeapObjectsTracking(); | 113 snapshots_->StopHeapObjectsTracking(); |
| 114 is_tracking_allocations_ = 0; |
| 110 } | 115 } |
| 111 | 116 |
| 112 | 117 |
| 113 size_t HeapProfiler::GetMemorySizeUsedByProfiler() { | 118 size_t HeapProfiler::GetMemorySizeUsedByProfiler() { |
| 114 return snapshots_->GetUsedMemorySize(); | 119 return snapshots_->GetUsedMemorySize(); |
| 115 } | 120 } |
| 116 | 121 |
| 117 | 122 |
| 118 int HeapProfiler::GetSnapshotsCount() { | 123 int HeapProfiler::GetSnapshotsCount() { |
| 119 return snapshots_->snapshots()->length(); | 124 return snapshots_->snapshots()->length(); |
| 120 } | 125 } |
| 121 | 126 |
| 122 | 127 |
| 123 HeapSnapshot* HeapProfiler::GetSnapshot(int index) { | 128 HeapSnapshot* HeapProfiler::GetSnapshot(int index) { |
| 124 return snapshots_->snapshots()->at(index); | 129 return snapshots_->snapshots()->at(index); |
| 125 } | 130 } |
| 126 | 131 |
| 127 | 132 |
| 128 SnapshotObjectId HeapProfiler::GetSnapshotObjectId(Handle<Object> obj) { | 133 SnapshotObjectId HeapProfiler::GetSnapshotObjectId(Handle<Object> obj) { |
| 129 if (!obj->IsHeapObject()) | 134 if (!obj->IsHeapObject()) |
| 130 return v8::HeapProfiler::kUnknownObjectId; | 135 return v8::HeapProfiler::kUnknownObjectId; |
| 131 return snapshots_->FindObjectId(HeapObject::cast(*obj)->address()); | 136 return snapshots_->FindObjectId(HeapObject::cast(*obj)->address()); |
| 132 } | 137 } |
| 133 | 138 |
| 134 | 139 |
| 135 void HeapProfiler::ObjectMoveEvent(Address from, Address to) { | 140 void HeapProfiler::ObjectMoveEvent(Address from, Address to, int size) { |
| 136 snapshots_->ObjectMoveEvent(from, to); | 141 snapshots_->ObjectMoveEvent(from, to, size); |
| 137 } | 142 } |
| 138 | 143 |
| 144 |
| 145 void HeapProfiler::NewObjectEvent(Address addr, int size) { |
| 146 snapshots_->NewObjectEvent(addr, size); |
| 147 } |
| 148 |
| 149 |
| 139 void HeapProfiler::SetRetainedObjectInfo(UniqueId id, | 150 void HeapProfiler::SetRetainedObjectInfo(UniqueId id, |
| 140 RetainedObjectInfo* info) { | 151 RetainedObjectInfo* info) { |
| 141 // TODO(yurus, marja): Don't route this information through GlobalHandles. | 152 // TODO(yurus, marja): Don't route this information through GlobalHandles. |
| 142 heap()->isolate()->global_handles()->SetRetainedObjectInfo(id, info); | 153 heap()->isolate()->global_handles()->SetRetainedObjectInfo(id, info); |
| 143 } | 154 } |
| 144 | 155 |
| 156 |
| 157 int* HeapProfiler::is_tracking_allocations_address() { |
| 158 return &is_tracking_allocations_; |
| 159 } |
| 160 |
| 161 |
| 162 int HeapProfiler::CheckAllocationsTracking() { |
| 163 return snapshots_->CheckAllocationsTracking(); |
| 164 } |
| 165 |
| 166 |
| 145 } } // namespace v8::internal | 167 } } // namespace v8::internal |
| OLD | NEW |