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;
17 function parseEvents(z) {
21 for (var i = 0, il = z.length; i < il; ++i) {
24 if (e['eventtype'] == 'EVENT_TYPE_ENTER_CS' ||
25 e['eventtype'] == 'EVENT_TYPE_TRYENTER_CS' ||
26 e['eventtype'] == 'EVENT_TYPE_LEAVE_CS') {
27 cs = e['critical_section'];
35 // Verify that the locks get unlocked, and operations stay on the same thread.
36 for (var key in crits) {
41 for (var j = 0, jl = es.length; j < jl; ++j) {
43 if (e['eventtype'] == 'EVENT_TYPE_ENTER_CS') {
45 } else if (e['eventtype'] == 'EVENT_TYPE_TRYENTER_CS') {
48 } else if (e['eventtype'] == 'EVENT_TYPE_LEAVE_CS') {
49 if (tid_stack.length == 0) {
52 var tid = tid_stack.pop()
53 if (tid['thread'] != e['thread']) {
60 // Look for long-held / contended locks. We can't really know it is
61 // contended without looking if anyone is waiting on the embedded event...
62 // Just look for locks are are held a long time? Not so good...
63 for (var key in crits) {
68 for (var j = 0, jl = es.length; j < jl; ++j) {
70 if (e['eventtype'] == 'EVENT_TYPE_ENTER_CS') {
72 } else if (e['eventtype'] == 'EVENT_TYPE_TRYENTER_CS') {
75 } else if (e['eventtype'] == 'EVENT_TYPE_LEAVE_CS') {
76 if (tid_stack.length == 0) {
79 var tid = tid_stack.pop();
80 var dur = e['ms'] - tid['ms'];
82 print('Lock: 0x' + toHex(cs) + ' for ' + dur + ' at: ' + e['ms']);