1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // You should run this with v8, like v8_shell alloc.js datafile.json
9 var table = "0123456789abcdef";
11 str = table.charAt(num & 0xf) + str;
18 for (var key in obj) {
20 print(' ' + obj[key]);
35 this.sorted.push([num, data]);
36 this.sorted.sort(function(a, b) { return b[0] - a[0] });
37 if (this.sorted.length > this.n)
40 this.min = this.sorted[this.sorted.lenth - 1];
43 TopN.prototype.datas =
46 for (var i = 0, il = this.sorted.length; i < il; ++i) {
47 datas.push(this.sorted[i][1]);
52 function parseEvents(z) {
53 var topper = new TopN(1000);
55 // Find the largest allocation.
56 for (var i = 0, il = z.length; i < il; ++i) {
59 if (e['eventtype'] == 'EVENT_TYPE_ALLOCHEAP') {
60 var size = e['heapsize'];
61 topper.add(e['heapsize'], e);
65 var datas = topper.datas();
66 for (var i = 0, il = datas.length; i < il; ++i) {