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

Side by Side Diff: runtime/vm/class_table.cc

Issue 173013004: Add accumulator to allocation profiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/class_table.h" 5 #include "vm/class_table.h"
6 #include "vm/flags.h" 6 #include "vm/flags.h"
7 #include "vm/freelist.h" 7 #include "vm/freelist.h"
8 #include "vm/heap.h" 8 #include "vm/heap.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/raw_object.h" 10 #include "vm/raw_object.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 allocated_size_before_gc_old_space = 0; 138 allocated_size_before_gc_old_space = 0;
139 allocated_size_before_gc_new_space = 0; 139 allocated_size_before_gc_new_space = 0;
140 live_after_gc_old_space = 0; 140 live_after_gc_old_space = 0;
141 live_after_gc_new_space = 0; 141 live_after_gc_new_space = 0;
142 live_size_after_gc_old_space = 0; 142 live_size_after_gc_old_space = 0;
143 live_size_after_gc_new_space = 0; 143 live_size_after_gc_new_space = 0;
144 allocated_since_gc_new_space = 0; 144 allocated_since_gc_new_space = 0;
145 allocated_since_gc_old_space = 0; 145 allocated_since_gc_old_space = 0;
146 allocated_size_since_gc_new_space = 0; 146 allocated_size_since_gc_new_space = 0;
147 allocated_size_since_gc_old_space = 0; 147 allocated_size_since_gc_old_space = 0;
148 accumulated_post_gc_new_space = 0;
149 accumulated_post_gc_old_space = 0;
150 accumulated_post_gc_size_new_space = 0;
151 accumulated_post_gc_size_old_space = 0;
152 accumulator_new_space_offset = 0;
153 accumulator_old_space_offset = 0;
154 accumulator_size_new_space_offset = 0;
155 accumulator_size_old_space_offset = 0;
148 } 156 }
149 157
150 158
151 void ClassHeapStats::ResetAtNewGC() { 159 void ClassHeapStats::ResetAtNewGC() {
152 allocated_before_gc_new_space = live_after_gc_new_space + 160 allocated_before_gc_new_space = live_after_gc_new_space +
153 allocated_since_gc_new_space; 161 allocated_since_gc_new_space;
154 allocated_size_before_gc_new_space = live_size_after_gc_new_space + 162 allocated_size_before_gc_new_space = live_size_after_gc_new_space +
155 allocated_size_since_gc_new_space; 163 allocated_size_since_gc_new_space;
164 // Accumulate allocations.
165 accumulated_post_gc_new_space +=
166 allocated_since_gc_new_space - accumulator_new_space_offset;
167 accumulated_post_gc_size_new_space +=
168 allocated_size_since_gc_new_space - accumulator_size_new_space_offset;
169 accumulator_new_space_offset = 0;
170 accumulator_size_new_space_offset = 0;
156 live_after_gc_new_space = 0; 171 live_after_gc_new_space = 0;
157 live_size_after_gc_new_space = 0; 172 live_size_after_gc_new_space = 0;
158 allocated_since_gc_new_space = 0; 173 allocated_since_gc_new_space = 0;
159 allocated_size_since_gc_new_space = 0; 174 allocated_size_since_gc_new_space = 0;
160 } 175 }
161 176
162 177
163 void ClassHeapStats::ResetAtOldGC() { 178 void ClassHeapStats::ResetAtOldGC() {
164 allocated_before_gc_old_space = live_after_gc_old_space + 179 allocated_before_gc_old_space = live_after_gc_old_space +
165 allocated_since_gc_old_space; 180 allocated_since_gc_old_space;
166 allocated_size_before_gc_old_space = live_size_after_gc_old_space + 181 allocated_size_before_gc_old_space = live_size_after_gc_old_space +
167 allocated_size_since_gc_old_space; 182 allocated_size_since_gc_old_space;
183 // Accumulate allocations.
184 accumulated_post_gc_old_space +=
185 allocated_since_gc_old_space - accumulator_old_space_offset;
186 accumulated_post_gc_size_old_space +=
187 allocated_size_since_gc_old_space - accumulator_size_old_space_offset;
188 accumulator_old_space_offset = 0;
189 accumulator_size_old_space_offset = 0;
168 live_after_gc_old_space = 0; 190 live_after_gc_old_space = 0;
169 live_size_after_gc_old_space = 0; 191 live_size_after_gc_old_space = 0;
170 allocated_since_gc_old_space = 0; 192 allocated_since_gc_old_space = 0;
171 allocated_size_since_gc_old_space = 0; 193 allocated_size_since_gc_old_space = 0;
172 } 194 }
173 195
174 196
175 void ClassHeapStats::UpdateSize(intptr_t instance_size) { 197 void ClassHeapStats::UpdateSize(intptr_t instance_size) {
176 ASSERT(instance_size > 0); 198 ASSERT(instance_size > 0);
177 // For classes with fixed instance size we do not emit code to update 199 // For classes with fixed instance size we do not emit code to update
178 // the size statistics. Update them here. 200 // the size statistics. Update them here.
179 allocated_size_before_gc_old_space = 201 allocated_size_before_gc_old_space =
180 allocated_before_gc_old_space * instance_size; 202 allocated_before_gc_old_space * instance_size;
181 allocated_size_before_gc_new_space = 203 allocated_size_before_gc_new_space =
182 allocated_before_gc_new_space * instance_size; 204 allocated_before_gc_new_space * instance_size;
183 live_size_after_gc_old_space = 205 live_size_after_gc_old_space =
184 live_after_gc_old_space * instance_size; 206 live_after_gc_old_space * instance_size;
185 live_size_after_gc_new_space = 207 live_size_after_gc_new_space =
186 live_after_gc_new_space * instance_size; 208 live_after_gc_new_space * instance_size;
187 allocated_size_since_gc_new_space = 209 allocated_size_since_gc_new_space =
188 allocated_since_gc_new_space * instance_size; 210 allocated_since_gc_new_space * instance_size;
189 allocated_size_since_gc_old_space = 211 allocated_size_since_gc_old_space =
190 allocated_since_gc_old_space * instance_size; 212 allocated_since_gc_old_space * instance_size;
191 } 213 }
192 214
193 215
216 void ClassHeapStats::ResetAccumulator() {
217 // Remember how much was allocated so we can subtract this from the result
218 // when printing.
219 accumulator_new_space_offset = allocated_since_gc_new_space;
220 accumulator_old_space_offset = allocated_since_gc_old_space;
221 accumulator_size_new_space_offset = allocated_size_since_gc_new_space;
222 accumulator_size_old_space_offset = allocated_size_since_gc_old_space;
223 accumulated_post_gc_new_space = 0;
224 accumulated_post_gc_old_space = 0;
225 accumulated_post_gc_size_new_space = 0;
226 accumulated_post_gc_size_old_space = 0;
227 }
228
229
194 void ClassHeapStats::PrintTOJSONArray(const Class& cls, JSONArray* array) { 230 void ClassHeapStats::PrintTOJSONArray(const Class& cls, JSONArray* array) {
195 JSONObject obj(array); 231 JSONObject obj(array);
196 obj.AddProperty("type", "ClassHeapStats"); 232 obj.AddProperty("type", "ClassHeapStats");
197 obj.AddProperty("class", cls); 233 obj.AddProperty("class", cls);
198 { 234 {
199 JSONArray new_stats(&obj, "new"); 235 JSONArray new_stats(&obj, "new");
200 new_stats.AddValue(allocated_before_gc_new_space); 236 new_stats.AddValue(allocated_before_gc_new_space);
201 new_stats.AddValue(allocated_size_before_gc_new_space); 237 new_stats.AddValue(allocated_size_before_gc_new_space);
202 new_stats.AddValue(live_after_gc_new_space); 238 new_stats.AddValue(live_after_gc_new_space);
203 new_stats.AddValue(live_size_after_gc_new_space); 239 new_stats.AddValue(live_size_after_gc_new_space);
204 new_stats.AddValue(allocated_since_gc_new_space); 240 new_stats.AddValue(allocated_since_gc_new_space);
205 new_stats.AddValue(allocated_size_since_gc_new_space); 241 new_stats.AddValue(allocated_size_since_gc_new_space);
242 new_stats.AddValue64(accumulated_post_gc_new_space +
243 allocated_since_gc_new_space -
244 accumulator_new_space_offset);
245 new_stats.AddValue64(accumulated_post_gc_size_new_space +
246 allocated_size_since_gc_new_space -
247 accumulator_size_new_space_offset);
206 } 248 }
207 { 249 {
208 JSONArray old_stats(&obj, "old"); 250 JSONArray old_stats(&obj, "old");
209 old_stats.AddValue(allocated_before_gc_old_space); 251 old_stats.AddValue(allocated_before_gc_old_space);
210 old_stats.AddValue(allocated_size_before_gc_old_space); 252 old_stats.AddValue(allocated_size_before_gc_old_space);
211 old_stats.AddValue(live_after_gc_old_space); 253 old_stats.AddValue(live_after_gc_old_space);
212 old_stats.AddValue(live_size_after_gc_old_space); 254 old_stats.AddValue(live_size_after_gc_old_space);
213 old_stats.AddValue(allocated_since_gc_old_space); 255 old_stats.AddValue(allocated_since_gc_old_space);
214 old_stats.AddValue(allocated_size_since_gc_old_space); 256 old_stats.AddValue(allocated_size_since_gc_old_space);
257 old_stats.AddValue64(accumulated_post_gc_old_space +
258 allocated_since_gc_old_space -
259 accumulator_old_space_offset);
260 old_stats.AddValue64(accumulated_post_gc_size_old_space +
261 allocated_size_since_gc_old_space -
262 accumulator_size_old_space_offset);
215 } 263 }
216 } 264 }
217 265
218 266
219 void ClassTable::UpdateAllocatedNew(intptr_t cid, intptr_t size) { 267 void ClassTable::UpdateAllocatedNew(intptr_t cid, intptr_t size) {
220 ClassHeapStats* stats = StatsAt(cid); 268 ClassHeapStats* stats = StatsAt(cid);
221 ASSERT(stats != NULL); 269 ASSERT(stats != NULL);
222 ASSERT(size != 0); 270 ASSERT(size != 0);
223 stats->allocated_since_gc_new_space++; 271 stats->allocated_since_gc_new_space++;
224 stats->allocated_size_since_gc_new_space += size; 272 stats->allocated_size_since_gc_new_space += size;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 if (ShouldUpdateSizeForClassId(i)) { 363 if (ShouldUpdateSizeForClassId(i)) {
316 intptr_t instance_size = cls.instance_size(); 364 intptr_t instance_size = cls.instance_size();
317 class_heap_stats_table_[i].UpdateSize(instance_size); 365 class_heap_stats_table_[i].UpdateSize(instance_size);
318 } 366 }
319 class_heap_stats_table_[i].PrintTOJSONArray(cls, &arr); 367 class_heap_stats_table_[i].PrintTOJSONArray(cls, &arr);
320 } 368 }
321 } 369 }
322 } 370 }
323 371
324 372
373 void ClassTable::ResetAllocationAccumulators() {
374 Class& cls = Class::Handle();
375 for (intptr_t i = 1; i < kNumPredefinedCids; i++) {
376 if (!HasValidClassAt(i) || (i == kFreeListElement) || (i == kSmiCid)) {
377 continue;
378 }
379 cls = At(i);
380 if (!(cls.is_finalized() || cls.is_prefinalized())) {
381 // Not finalized.
382 continue;
383 }
384 // Update size before resetting accumulator.
385 if (ShouldUpdateSizeForClassId(i)) {
386 intptr_t instance_size = cls.instance_size();
387 predefined_class_heap_stats_table_[i].UpdateSize(instance_size);
388 }
389 predefined_class_heap_stats_table_[i].ResetAccumulator();
390 }
391 for (intptr_t i = kNumPredefinedCids; i < top_; i++) {
392 if (!HasValidClassAt(i)) {
393 continue;
394 }
395 cls = At(i);
396 if (!(cls.is_finalized() || cls.is_prefinalized())) {
397 // Not finalized.
398 continue;
399 }
400 // Update size before resetting accumulator.
401 if (ShouldUpdateSizeForClassId(i)) {
402 intptr_t instance_size = cls.instance_size();
403 class_heap_stats_table_[i].UpdateSize(instance_size);
404 }
405 class_heap_stats_table_[i].ResetAccumulator();
406 }
407 }
408
409
325 void ClassTable::UpdateLiveOld(intptr_t cid, intptr_t size) { 410 void ClassTable::UpdateLiveOld(intptr_t cid, intptr_t size) {
326 ClassHeapStats* stats = StatsAt(cid); 411 ClassHeapStats* stats = StatsAt(cid);
327 ASSERT(stats != NULL); 412 ASSERT(stats != NULL);
328 ASSERT(size >= 0); 413 ASSERT(size >= 0);
329 stats->live_after_gc_old_space++; 414 stats->live_after_gc_old_space++;
330 stats->live_size_after_gc_old_space += size; 415 stats->live_size_after_gc_old_space += size;
331 } 416 }
332 417
333 418
334 void ClassTable::UpdateLiveNew(intptr_t cid, intptr_t size) { 419 void ClassTable::UpdateLiveNew(intptr_t cid, intptr_t size) {
335 ClassHeapStats* stats = StatsAt(cid); 420 ClassHeapStats* stats = StatsAt(cid);
336 ASSERT(stats != NULL); 421 ASSERT(stats != NULL);
337 ASSERT(size >= 0); 422 ASSERT(size >= 0);
338 stats->live_after_gc_new_space++; 423 stats->live_after_gc_new_space++;
339 stats->live_size_after_gc_new_space += size; 424 stats->live_size_after_gc_new_space += size;
340 } 425 }
341 426
342 427
343 } // namespace dart 428 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698