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

Unified Diff: tools/traceline/traceline/scripts/heap.js

Issue 20494: Import Traceline, a Windows performance trace event logger. (Closed)
Patch Set: Feedback. Created 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/traceline/traceline/scripts/crit_sec.py ('k') | tools/traceline/traceline/scripts/scstats.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/traceline/traceline/scripts/heap.js
diff --git a/tools/traceline/traceline/scripts/heap.js b/tools/traceline/traceline/scripts/heap.js
new file mode 100755
index 0000000000000000000000000000000000000000..e8b57a781fa1c99dcac472076f2598393b0a1e49
--- /dev/null
+++ b/tools/traceline/traceline/scripts/heap.js
@@ -0,0 +1,69 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// You should run this with v8, like v8_shell_sample alloc.js datafile.json
+
+function toHex(num) {
+ var str = "";
+ var table = "0123456789abcdef";
+ while (num != 0) {
+ str = table.charAt(num & 0xf) + str;
+ num >>= 4;
+ }
+ return str;
+}
+
+function dump(obj) {
+ for (var key in obj) {
+ print('key: ' + key);
+ print(' ' + obj[key]);
+ }
+}
+
+function TopN(n) {
+ this.n = n;
+ this.min = 0;
+ this.sorted = [ ];
+}
+
+TopN.prototype.add =
+function(num, data) {
+ if (num < this.min)
+ return;
+
+ this.sorted.push([num, data]);
+ this.sorted.sort(function(a, b) { return b[0] - a[0] });
+ if (this.sorted.length > this.n)
+ this.sorted.pop();
+
+ this.min = this.sorted[this.sorted.lenth - 1];
+};
+
+TopN.prototype.datas =
+function() {
+ var datas = [ ];
+ for (var i = 0, il = this.sorted.length; i < il; ++i) {
+ datas.push(this.sorted[i][1]);
+ }
+ return datas;
+};
+
+function parseEvents(z) {
+ var topper = new TopN(1000);
+
+ // Find the largest allocation.
+ for (var i = 0, il = z.length; i < il; ++i) {
+ var e = z[i];
+
+ if (e['eventtype'] == 'EVENT_TYPE_ALLOCHEAP') {
+ var size = e['heapsize'];
+ topper.add(e['heapsize'], e);
+ }
+ }
+
+ var datas = topper.datas();
+ for (var i = 0, il = datas.length; i < il; ++i) {
+ dump(datas[i]);
+ }
+}
« no previous file with comments | « tools/traceline/traceline/scripts/crit_sec.py ('k') | tools/traceline/traceline/scripts/scstats.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698