Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/heap-profiler.cc

Issue 12907006: Isolatify HeapProfiler (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Prohibited construction and destruction of v8::HeapProfiler Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/heap-profiler.h ('k') | src/isolate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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::ResetSnapshots() { 47 void HeapProfiler::DeleteAllSnapshots() {
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
113 void HeapProfiler::DefineWrapperClass( 54 void HeapProfiler::DefineWrapperClass(
114 uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback) { 55 uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback) {
115 ASSERT(class_id != v8::HeapProfiler::kPersistentHandleNoClassId); 56 ASSERT(class_id != v8::HeapProfiler::kPersistentHandleNoClassId);
116 if (wrapper_callbacks_.length() <= class_id) { 57 if (wrapper_callbacks_.length() <= class_id) {
117 wrapper_callbacks_.AddBlock( 58 wrapper_callbacks_.AddBlock(
118 NULL, class_id - wrapper_callbacks_.length() + 1); 59 NULL, class_id - wrapper_callbacks_.length() + 1);
119 } 60 }
120 wrapper_callbacks_[class_id] = callback; 61 wrapper_callbacks_[class_id] = callback;
121 } 62 }
122 63
123 64
124 v8::RetainedObjectInfo* HeapProfiler::ExecuteWrapperClassCallback( 65 v8::RetainedObjectInfo* HeapProfiler::ExecuteWrapperClassCallback(
125 uint16_t class_id, Object** wrapper) { 66 uint16_t class_id, Object** wrapper) {
126 if (wrapper_callbacks_.length() <= class_id) return NULL; 67 if (wrapper_callbacks_.length() <= class_id) return NULL;
127 return wrapper_callbacks_[class_id]( 68 return wrapper_callbacks_[class_id](
128 class_id, Utils::ToLocal(Handle<Object>(wrapper))); 69 class_id, Utils::ToLocal(Handle<Object>(wrapper)));
129 } 70 }
130 71
131 72
132 HeapSnapshot* HeapProfiler::TakeSnapshotImpl( 73 HeapSnapshot* HeapProfiler::TakeSnapshot(
133 const char* name, 74 const char* name,
134 int type, 75 int type,
135 v8::ActivityControl* control, 76 v8::ActivityControl* control,
136 v8::HeapProfiler::ObjectNameResolver* resolver) { 77 v8::HeapProfiler::ObjectNameResolver* resolver) {
137 HeapSnapshot::Type s_type = static_cast<HeapSnapshot::Type>(type); 78 HeapSnapshot::Type s_type = static_cast<HeapSnapshot::Type>(type);
138 HeapSnapshot* result = 79 HeapSnapshot* result =
139 snapshots_->NewSnapshot(s_type, name, next_snapshot_uid_++); 80 snapshots_->NewSnapshot(s_type, name, next_snapshot_uid_++);
140 bool generation_completed = true; 81 bool generation_completed = true;
141 switch (s_type) { 82 switch (s_type) {
142 case HeapSnapshot::kFull: { 83 case HeapSnapshot::kFull: {
143 HeapSnapshotGenerator generator(result, control, resolver, heap()); 84 HeapSnapshotGenerator generator(result, control, resolver, heap());
144 generation_completed = generator.GenerateSnapshot(); 85 generation_completed = generator.GenerateSnapshot();
145 break; 86 break;
146 } 87 }
147 default: 88 default:
148 UNREACHABLE(); 89 UNREACHABLE();
149 } 90 }
150 if (!generation_completed) { 91 if (!generation_completed) {
151 delete result; 92 delete result;
152 result = NULL; 93 result = NULL;
153 } 94 }
154 snapshots_->SnapshotGenerationFinished(result); 95 snapshots_->SnapshotGenerationFinished(result);
155 return result; 96 return result;
156 } 97 }
157 98
158 99
159 HeapSnapshot* HeapProfiler::TakeSnapshotImpl( 100 HeapSnapshot* HeapProfiler::TakeSnapshot(
160 String* name, 101 String* name,
161 int type, 102 int type,
162 v8::ActivityControl* control, 103 v8::ActivityControl* control,
163 v8::HeapProfiler::ObjectNameResolver* resolver) { 104 v8::HeapProfiler::ObjectNameResolver* resolver) {
164 return TakeSnapshotImpl(snapshots_->names()->GetName(name), type, control, 105 return TakeSnapshot(snapshots_->names()->GetName(name), type, control,
165 resolver); 106 resolver);
166 } 107 }
167 108
168 void HeapProfiler::StartHeapObjectsTrackingImpl() { 109 void HeapProfiler::StartHeapObjectsTracking() {
169 snapshots_->StartHeapObjectsTracking(); 110 snapshots_->StartHeapObjectsTracking();
170 } 111 }
171 112
172 113
173 SnapshotObjectId HeapProfiler::PushHeapObjectsStatsImpl(OutputStream* stream) { 114 SnapshotObjectId HeapProfiler::PushHeapObjectsStats(OutputStream* stream) {
174 return snapshots_->PushHeapObjectsStats(stream); 115 return snapshots_->PushHeapObjectsStats(stream);
175 } 116 }
176 117
177 118
178 void HeapProfiler::StopHeapObjectsTrackingImpl() { 119 void HeapProfiler::StopHeapObjectsTracking() {
179 snapshots_->StopHeapObjectsTracking(); 120 snapshots_->StopHeapObjectsTracking();
180 } 121 }
181 122
182 123
183 size_t HeapProfiler::GetMemorySizeUsedByProfiler() { 124 size_t HeapProfiler::GetMemorySizeUsedByProfiler() {
184 HeapProfiler* profiler = Isolate::Current()->heap_profiler(); 125 return snapshots_->GetUsedMemorySize();
185 ASSERT(profiler != NULL);
186 size_t size = profiler->snapshots_->GetUsedMemorySize();
187 return size;
188 } 126 }
189 127
190 128
191 int HeapProfiler::GetSnapshotsCount() { 129 int HeapProfiler::GetSnapshotsCount() {
192 HeapProfiler* profiler = Isolate::Current()->heap_profiler(); 130 return snapshots_->snapshots()->length();
193 ASSERT(profiler != NULL);
194 return profiler->snapshots_->snapshots()->length();
195 } 131 }
196 132
197 133
198 HeapSnapshot* HeapProfiler::GetSnapshot(int index) { 134 HeapSnapshot* HeapProfiler::GetSnapshot(int index) {
199 HeapProfiler* profiler = Isolate::Current()->heap_profiler(); 135 return snapshots_->snapshots()->at(index);
200 ASSERT(profiler != NULL);
201 return profiler->snapshots_->snapshots()->at(index);
202 } 136 }
203 137
204 138
205 HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) { 139 HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) {
206 HeapProfiler* profiler = Isolate::Current()->heap_profiler(); 140 return snapshots_->GetSnapshot(uid);
207 ASSERT(profiler != NULL);
208 return profiler->snapshots_->GetSnapshot(uid);
209 } 141 }
210 142
211 143
212 SnapshotObjectId HeapProfiler::GetSnapshotObjectId(Handle<Object> obj) { 144 SnapshotObjectId HeapProfiler::GetSnapshotObjectId(Handle<Object> obj) {
213 if (!obj->IsHeapObject()) 145 if (!obj->IsHeapObject())
214 return v8::HeapProfiler::kUnknownObjectId; 146 return v8::HeapProfiler::kUnknownObjectId;
215 HeapProfiler* profiler = Isolate::Current()->heap_profiler(); 147 return snapshots_->FindObjectId(HeapObject::cast(*obj)->address());
216 ASSERT(profiler != NULL);
217 return profiler->snapshots_->FindObjectId(HeapObject::cast(*obj)->address());
218 } 148 }
219 149
220 150
221 void HeapProfiler::DeleteAllSnapshots() {
222 HeapProfiler* profiler = Isolate::Current()->heap_profiler();
223 ASSERT(profiler != NULL);
224 profiler->ResetSnapshots();
225 }
226
227
228 void HeapProfiler::ObjectMoveEvent(Address from, Address to) { 151 void HeapProfiler::ObjectMoveEvent(Address from, Address to) {
229 snapshots_->ObjectMoveEvent(from, to); 152 snapshots_->ObjectMoveEvent(from, to);
230 } 153 }
231 154
232 155
233 } } // namespace v8::internal 156 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap-profiler.h ('k') | src/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698