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

Unified Diff: tools/traceline/traceline/scripts/crit_sec.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/alloc.py ('k') | tools/traceline/traceline/scripts/crit_sec.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/traceline/traceline/scripts/crit_sec.js
diff --git a/tools/traceline/traceline/scripts/crit_sec.js b/tools/traceline/traceline/scripts/crit_sec.js
new file mode 100755
index 0000000000000000000000000000000000000000..018309a5d6836cb2767a25a582e43d5a8053426b
--- /dev/null
+++ b/tools/traceline/traceline/scripts/crit_sec.js
@@ -0,0 +1,87 @@
+// 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 parseEvents(z) {
+ var crits = { }
+ var calls = { }
+
+ for (var i = 0, il = z.length; i < il; ++i) {
+ var e = z[i];
+
+ if (e['eventtype'] == 'EVENT_TYPE_ENTER_CS' ||
+ e['eventtype'] == 'EVENT_TYPE_TRYENTER_CS' ||
+ e['eventtype'] == 'EVENT_TYPE_LEAVE_CS') {
+ cs = e['critical_section'];
+ if (!(cs in crits)) {
+ crits[cs] = [ ];
+ }
+ crits[cs].push(e);
+ }
+ }
+
+ // Verify that the locks get unlocked, and operations stay on the same thread.
+ for (var key in crits) {
+ var cs = key;
+ var es = crits[key];
+
+ var tid_stack = [ ];
+ for (var j = 0, jl = es.length; j < jl; ++j) {
+ var e = es[j];
+ if (e['eventtype'] == 'EVENT_TYPE_ENTER_CS') {
+ tid_stack.push(e);
+ } else if (e['eventtype'] == 'EVENT_TYPE_TRYENTER_CS') {
+ if (e['retval'] != 0)
+ tid_stack.push(e);
+ } else if (e['eventtype'] == 'EVENT_TYPE_LEAVE_CS') {
+ if (tid_stack.length == 0) {
+ print('fail ' + e);
+ }
+ var tid = tid_stack.pop()
+ if (tid['thread'] != e['thread']) {
+ print('fail ' + tid);
+ }
+ }
+ }
+ }
+
+ // Look for long-held / contended locks. We can't really know it is
+ // contended without looking if anyone is waiting on the embedded event...
+ // Just look for locks are are held a long time? Not so good...
+ for (var key in crits) {
+ var cs = key;
+ var es = crits[key];
+
+ var tid_stack = [ ];
+ for (var j = 0, jl = es.length; j < jl; ++j) {
+ var e = es[j];
+ if (e['eventtype'] == 'EVENT_TYPE_ENTER_CS') {
+ tid_stack.push(e);
+ } else if (e['eventtype'] == 'EVENT_TYPE_TRYENTER_CS') {
+ if (e['retval'] != 0)
+ tid_stack.push(e);
+ } else if (e['eventtype'] == 'EVENT_TYPE_LEAVE_CS') {
+ if (tid_stack.length == 0) {
+ print('fail ' + e);
+ }
+ var tid = tid_stack.pop();
+ var dur = e['ms'] - tid['ms'];
+ if (dur > 0.1) {
+ print('Lock: 0x' + toHex(cs) + ' for ' + dur + ' at: ' + e['ms']);
+ }
+ }
+ }
+ }
+}
« no previous file with comments | « tools/traceline/traceline/scripts/alloc.py ('k') | tools/traceline/traceline/scripts/crit_sec.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698