From e9857f2a0e8a9599de801e28b3c7c898aa0e79a1 Mon Sep 17 00:00:00 2001 From: Raymond Conn Date: Sun, 28 Feb 2016 20:50:44 -0500 Subject: [PATCH 1/2] update parsing to work with headers of remote thread dumps. When a remote thread dump is captured the os thread information is missing --- analyze.js | 8 +++++++- tests.js | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/analyze.js b/analyze.js index 6584bd0..648652b 100644 --- a/analyze.js +++ b/analyze.js @@ -315,6 +315,12 @@ function Thread(line) { this.tid = match.value; line = match.shorterString; + if(this.tid === undefined){ + match = _extract(/ - Thread t@([0-9a-fx]+)/,line) + this.tid = match.value + line = match.shorterString + } + match = _extract(/ prio=([0-9]+)/, line); this.prio = match.value; line = match.shorterString; @@ -589,7 +595,7 @@ function Analyzer(text) { var lines = text.split('\n'); for (var i = 0; i < lines.length; i++) { var line = lines[i]; - while (line.charAt(0) === '"' && line.indexOf('prio=') === -1) { + while (line.charAt(0) === '"' && line.indexOf('prio=') === -1 && line.indexOf('t@') === -1) { // Multi line thread name i++; if (i >= lines.length) { diff --git a/tests.js b/tests.js index f10862a..2c21922 100644 --- a/tests.js +++ b/tests.js @@ -124,6 +124,13 @@ QUnit.test( "thread header 13", function(assert) { assert.equal(new Thread(header).group, undefined); }); +QUnit.test("thread header 14", function(assert){ + var header = '"http-bio-8810-exec-147" - Thread t@96965'; + assert.equal(new Thread(header).name,'http-bio-8810-exec-147'); + assert.equal(new Thread(header).tid, '96965'); + assert.equal(new Thread(header).group, undefined); +}); + // A thread should be considered running if it has a stack trace and // is RUNNABLE QUnit.test("thread.running", function(assert) { @@ -311,6 +318,37 @@ QUnit.test( "analyze thread waiting for traditional lock", function(assert) { assert.equal(thread.synchronizerClasses['47114712gris'], null); }); +QUnit.test(" analyze thread waiting for locks 2", function(assert){ + var threadDump= [ + '"http-5525-116" - Thread t@151', + ' java.lang.Thread.State: BLOCKED', + ' at org.apache.log4j.Category.callAppenders(Category.java:205)', + ' - waiting to lock <259a4a41> (a org.apache.log4j.spi.RootLogger) owned by "http-5525-127" t@162', + ' at org.apache.log4j.Category.forcedLog(Category.java:391)', + ' at org.apache.log4j.Category.log(Category.java:856)', + ' at org.apache.juli.logging.impl.Log4JLogger.error(Log4JLogger.java:251)', + ' at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:274)', + ' at java.lang.Thread.run(Thread.java:662)', + '', + ' Locked ownable synchronizers:', + ' - None', + ].join('\n'); + + var analyzer = new Analyzer(threadDump); + var threads = analyzer.threads; + assert.equal(threads.length, 1); + var thread = threads[0]; + + assert.equal(thread.wantNotificationOn, null); + assert.equal(thread.wantToAcquire, '259a4a41'); + + var locksHeld = [ /* None */ ]; + assert.deepEqual(thread.locksHeld, locksHeld); + + assert.equal(thread.synchronizerClasses['259a4a41'], 'org.apache.log4j.spi.RootLogger'); + assert.equal(thread.synchronizerClasses['47114712gris'], null); +}); + QUnit.test( "analyze thread holding locks", function(assert) { var threadDump = [ '"ApplicationImpl pooled thread 8" daemon prio=4 tid=10d96d000 nid=0x11e68a000 runnable [11e689000]', From 6684303283f2b9b67440486cf3c0a777216aaba1 Mon Sep 17 00:00:00 2001 From: Raymond Conn Date: Sun, 28 Feb 2016 21:17:05 -0500 Subject: [PATCH 2/2] fixing jslint errors --- analyze.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/analyze.js b/analyze.js index 648652b..1b8539d 100644 --- a/analyze.js +++ b/analyze.js @@ -316,9 +316,9 @@ function Thread(line) { line = match.shorterString; if(this.tid === undefined){ - match = _extract(/ - Thread t@([0-9a-fx]+)/,line) - this.tid = match.value - line = match.shorterString + match = _extract(/ - Thread t@([0-9a-fx]+)/,line); + this.tid = match.value; + line = match.shorterString; } match = _extract(/ prio=([0-9]+)/, line);