Friday, January 15, 2010

simple thread dump analysis Awk scripts

Here are the Thread.state we usually see and pay attention to:
* RUNNABLE
* BLOCKED
* WAITING
* TIMED_WAITING

If want to know what kind of status of thread dump i picked up from app server when CPU% is pretty high or want to find blocking threads, this is useful give you some insights, you can develop yours in 10 mins:)

BEGIN {RS="\n\"";IGNORECASE = 1;count1=0;count2=0;count3=0;count4=0;count5=0}

($0~ /workmanager\(/){

if ($0~ /State: runnable/) {

count1=count1+1;

}


if ($0~ /State: TIMED_WAITING on/){

count2=count2+1;

}

if ($0~ /State: WAITING\n/) {

count3=count3+1;

}

if ($0~ /State: WAITING on /) {

count4=count4+1;

}

if ($0~ /State: Blocked on /) {

count5=count5+1;

}


{

sum=sum+1;
}

}

END{
print "# of runnable threads is:" count1;
print "# of timed_Waiting on condition threads is: " count2;
print "# of Waiting threads is: " count3;
print "# of Waiting on condition threads is: " count4;
print "# of Blocked threads is: " count5;
print "Total num of threads: " sum;
}
-------------------
Sample output:

# of runnable threads is:10
# of timed_Waiting on condition threads is: 85
# of Waiting threads is: 0
# of Waiting on condition threads is: 3
# of Blocked threads is: 2
Total num of threads: 100


BTW, i found "timed_Waiting on" and "Blocked" threads number is huge, then you got problem on synchronization probably, dig into it.

No comments:

Post a Comment