| 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 26 matching lines...) Expand all Loading... |
| 37 : snapshots_(new HeapSnapshotsCollection(heap)), | 37 : snapshots_(new HeapSnapshotsCollection(heap)), |
| 38 next_snapshot_uid_(1) { | 38 next_snapshot_uid_(1) { |
| 39 } | 39 } |
| 40 | 40 |
| 41 | 41 |
| 42 HeapProfiler::~HeapProfiler() { | 42 HeapProfiler::~HeapProfiler() { |
| 43 delete snapshots_; | 43 delete snapshots_; |
| 44 } | 44 } |
| 45 | 45 |
| 46 | 46 |
| 47 void HeapProfiler::DeleteAllSnapshots() { | 47 void HeapProfiler::ResetSnapshots() { |
| 48 Heap* the_heap = heap(); | 48 Heap* the_heap = heap(); |
| 49 delete snapshots_; | 49 delete snapshots_; |
| 50 snapshots_ = new HeapSnapshotsCollection(the_heap); | 50 snapshots_ = new HeapSnapshotsCollection(the_heap); |
| 51 } | 51 } |
| 52 | 52 |
| 53 | 53 |
| 54 void HeapProfiler::SetUp() { |
| 55 Isolate* isolate = Isolate::Current(); |
| 56 if (isolate->heap_profiler() == NULL) { |
| 57 isolate->set_heap_profiler(new HeapProfiler(isolate->heap())); |
| 58 } |
| 59 } |
| 60 |
| 61 |
| 62 void HeapProfiler::TearDown() { |
| 63 Isolate* isolate = Isolate::Current(); |
| 64 delete isolate->heap_profiler(); |
| 65 isolate->set_heap_profiler(NULL); |
| 66 } |
| 67 |
| 68 |
| 69 HeapSnapshot* HeapProfiler::TakeSnapshot( |
| 70 const char* name, |
| 71 int type, |
| 72 v8::ActivityControl* control, |
| 73 v8::HeapProfiler::ObjectNameResolver* resolver) { |
| 74 ASSERT(Isolate::Current()->heap_profiler() != NULL); |
| 75 return Isolate::Current()->heap_profiler()->TakeSnapshotImpl(name, |
| 76 type, |
| 77 control, |
| 78 resolver); |
| 79 } |
| 80 |
| 81 |
| 82 HeapSnapshot* HeapProfiler::TakeSnapshot( |
| 83 String* name, |
| 84 int type, |
| 85 v8::ActivityControl* control, |
| 86 v8::HeapProfiler::ObjectNameResolver* resolver) { |
| 87 ASSERT(Isolate::Current()->heap_profiler() != NULL); |
| 88 return Isolate::Current()->heap_profiler()->TakeSnapshotImpl(name, |
| 89 type, |
| 90 control, |
| 91 resolver); |
| 92 } |
| 93 |
| 94 |
| 95 void HeapProfiler::StartHeapObjectsTracking() { |
| 96 ASSERT(Isolate::Current()->heap_profiler() != NULL); |
| 97 Isolate::Current()->heap_profiler()->StartHeapObjectsTrackingImpl(); |
| 98 } |
| 99 |
| 100 |
| 101 void HeapProfiler::StopHeapObjectsTracking() { |
| 102 ASSERT(Isolate::Current()->heap_profiler() != NULL); |
| 103 Isolate::Current()->heap_profiler()->StopHeapObjectsTrackingImpl(); |
| 104 } |
| 105 |
| 106 |
| 107 SnapshotObjectId HeapProfiler::PushHeapObjectsStats(v8::OutputStream* stream) { |
| 108 ASSERT(Isolate::Current()->heap_profiler() != NULL); |
| 109 return Isolate::Current()->heap_profiler()->PushHeapObjectsStatsImpl(stream); |
| 110 } |
| 111 |
| 112 |
| 54 void HeapProfiler::DefineWrapperClass( | 113 void HeapProfiler::DefineWrapperClass( |
| 55 uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback) { | 114 uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback) { |
| 56 ASSERT(class_id != v8::HeapProfiler::kPersistentHandleNoClassId); | 115 ASSERT(class_id != v8::HeapProfiler::kPersistentHandleNoClassId); |
| 57 if (wrapper_callbacks_.length() <= class_id) { | 116 if (wrapper_callbacks_.length() <= class_id) { |
| 58 wrapper_callbacks_.AddBlock( | 117 wrapper_callbacks_.AddBlock( |
| 59 NULL, class_id - wrapper_callbacks_.length() + 1); | 118 NULL, class_id - wrapper_callbacks_.length() + 1); |
| 60 } | 119 } |
| 61 wrapper_callbacks_[class_id] = callback; | 120 wrapper_callbacks_[class_id] = callback; |
| 62 } | 121 } |
| 63 | 122 |
| 64 | 123 |
| 65 v8::RetainedObjectInfo* HeapProfiler::ExecuteWrapperClassCallback( | 124 v8::RetainedObjectInfo* HeapProfiler::ExecuteWrapperClassCallback( |
| 66 uint16_t class_id, Object** wrapper) { | 125 uint16_t class_id, Object** wrapper) { |
| 67 if (wrapper_callbacks_.length() <= class_id) return NULL; | 126 if (wrapper_callbacks_.length() <= class_id) return NULL; |
| 68 return wrapper_callbacks_[class_id]( | 127 return wrapper_callbacks_[class_id]( |
| 69 class_id, Utils::ToLocal(Handle<Object>(wrapper))); | 128 class_id, Utils::ToLocal(Handle<Object>(wrapper))); |
| 70 } | 129 } |
| 71 | 130 |
| 72 | 131 |
| 73 HeapSnapshot* HeapProfiler::TakeSnapshot( | 132 HeapSnapshot* HeapProfiler::TakeSnapshotImpl( |
| 74 const char* name, | 133 const char* name, |
| 134 int type, |
| 75 v8::ActivityControl* control, | 135 v8::ActivityControl* control, |
| 76 v8::HeapProfiler::ObjectNameResolver* resolver) { | 136 v8::HeapProfiler::ObjectNameResolver* resolver) { |
| 77 HeapSnapshot* result = snapshots_->NewSnapshot(name, next_snapshot_uid_++); | 137 HeapSnapshot::Type s_type = static_cast<HeapSnapshot::Type>(type); |
| 78 { | 138 HeapSnapshot* result = |
| 79 HeapSnapshotGenerator generator(result, control, resolver, heap()); | 139 snapshots_->NewSnapshot(s_type, name, next_snapshot_uid_++); |
| 80 if (!generator.GenerateSnapshot()) { | 140 bool generation_completed = true; |
| 81 delete result; | 141 switch (s_type) { |
| 82 result = NULL; | 142 case HeapSnapshot::kFull: { |
| 143 HeapSnapshotGenerator generator(result, control, resolver, heap()); |
| 144 generation_completed = generator.GenerateSnapshot(); |
| 145 break; |
| 83 } | 146 } |
| 147 default: |
| 148 UNREACHABLE(); |
| 149 } |
| 150 if (!generation_completed) { |
| 151 delete result; |
| 152 result = NULL; |
| 84 } | 153 } |
| 85 snapshots_->SnapshotGenerationFinished(result); | 154 snapshots_->SnapshotGenerationFinished(result); |
| 86 return result; | 155 return result; |
| 87 } | 156 } |
| 88 | 157 |
| 89 | 158 |
| 90 HeapSnapshot* HeapProfiler::TakeSnapshot( | 159 HeapSnapshot* HeapProfiler::TakeSnapshotImpl( |
| 91 String* name, | 160 String* name, |
| 161 int type, |
| 92 v8::ActivityControl* control, | 162 v8::ActivityControl* control, |
| 93 v8::HeapProfiler::ObjectNameResolver* resolver) { | 163 v8::HeapProfiler::ObjectNameResolver* resolver) { |
| 94 return TakeSnapshot(snapshots_->names()->GetName(name), control, resolver); | 164 return TakeSnapshotImpl(snapshots_->names()->GetName(name), type, control, |
| 165 resolver); |
| 95 } | 166 } |
| 96 | 167 |
| 97 void HeapProfiler::StartHeapObjectsTracking() { | 168 void HeapProfiler::StartHeapObjectsTrackingImpl() { |
| 98 snapshots_->StartHeapObjectsTracking(); | 169 snapshots_->StartHeapObjectsTracking(); |
| 99 } | 170 } |
| 100 | 171 |
| 101 | 172 |
| 102 SnapshotObjectId HeapProfiler::PushHeapObjectsStats(OutputStream* stream) { | 173 SnapshotObjectId HeapProfiler::PushHeapObjectsStatsImpl(OutputStream* stream) { |
| 103 return snapshots_->PushHeapObjectsStats(stream); | 174 return snapshots_->PushHeapObjectsStats(stream); |
| 104 } | 175 } |
| 105 | 176 |
| 106 | 177 |
| 107 void HeapProfiler::StopHeapObjectsTracking() { | 178 void HeapProfiler::StopHeapObjectsTrackingImpl() { |
| 108 snapshots_->StopHeapObjectsTracking(); | 179 snapshots_->StopHeapObjectsTracking(); |
| 109 } | 180 } |
| 110 | 181 |
| 111 | 182 |
| 112 size_t HeapProfiler::GetMemorySizeUsedByProfiler() { | 183 size_t HeapProfiler::GetMemorySizeUsedByProfiler() { |
| 113 return snapshots_->GetUsedMemorySize(); | 184 HeapProfiler* profiler = Isolate::Current()->heap_profiler(); |
| 185 ASSERT(profiler != NULL); |
| 186 size_t size = profiler->snapshots_->GetUsedMemorySize(); |
| 187 return size; |
| 114 } | 188 } |
| 115 | 189 |
| 116 | 190 |
| 117 int HeapProfiler::GetSnapshotsCount() { | 191 int HeapProfiler::GetSnapshotsCount() { |
| 118 return snapshots_->snapshots()->length(); | 192 HeapProfiler* profiler = Isolate::Current()->heap_profiler(); |
| 193 ASSERT(profiler != NULL); |
| 194 return profiler->snapshots_->snapshots()->length(); |
| 119 } | 195 } |
| 120 | 196 |
| 121 | 197 |
| 122 HeapSnapshot* HeapProfiler::GetSnapshot(int index) { | 198 HeapSnapshot* HeapProfiler::GetSnapshot(int index) { |
| 123 return snapshots_->snapshots()->at(index); | 199 HeapProfiler* profiler = Isolate::Current()->heap_profiler(); |
| 200 ASSERT(profiler != NULL); |
| 201 return profiler->snapshots_->snapshots()->at(index); |
| 124 } | 202 } |
| 125 | 203 |
| 126 | 204 |
| 127 HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) { | 205 HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) { |
| 128 return snapshots_->GetSnapshot(uid); | 206 HeapProfiler* profiler = Isolate::Current()->heap_profiler(); |
| 207 ASSERT(profiler != NULL); |
| 208 return profiler->snapshots_->GetSnapshot(uid); |
| 129 } | 209 } |
| 130 | 210 |
| 131 | 211 |
| 132 SnapshotObjectId HeapProfiler::GetSnapshotObjectId(Handle<Object> obj) { | 212 SnapshotObjectId HeapProfiler::GetSnapshotObjectId(Handle<Object> obj) { |
| 133 if (!obj->IsHeapObject()) | 213 if (!obj->IsHeapObject()) |
| 134 return v8::HeapProfiler::kUnknownObjectId; | 214 return v8::HeapProfiler::kUnknownObjectId; |
| 135 return snapshots_->FindObjectId(HeapObject::cast(*obj)->address()); | 215 HeapProfiler* profiler = Isolate::Current()->heap_profiler(); |
| 216 ASSERT(profiler != NULL); |
| 217 return profiler->snapshots_->FindObjectId(HeapObject::cast(*obj)->address()); |
| 136 } | 218 } |
| 137 | 219 |
| 138 | 220 |
| 221 void HeapProfiler::DeleteAllSnapshots() { |
| 222 HeapProfiler* profiler = Isolate::Current()->heap_profiler(); |
| 223 ASSERT(profiler != NULL); |
| 224 profiler->ResetSnapshots(); |
| 225 } |
| 226 |
| 227 |
| 139 void HeapProfiler::ObjectMoveEvent(Address from, Address to) { | 228 void HeapProfiler::ObjectMoveEvent(Address from, Address to) { |
| 140 snapshots_->ObjectMoveEvent(from, to); | 229 snapshots_->ObjectMoveEvent(from, to); |
| 141 } | 230 } |
| 142 | 231 |
| 143 | 232 |
| 144 } } // namespace v8::internal | 233 } } // namespace v8::internal |
| OLD | NEW |