Skip to content

Commit

Permalink
! show-busy-java-threads: improve extract block logic of awk
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Mar 31, 2021
1 parent 2775555 commit d8df80f
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions bin/show-busy-java-threads
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,13 @@ __top_threadId_cpu() {
fi

echo "$top_out" |
awk 'BEGIN { blockIndex = 0; currentLineHasText = 0; prevLineHasText = 0; } {
currentLineHasText = ($0 != "")
if (prevLineHasText && !currentLineHasText)
blockIndex++ # from text line to empty line, increase block index
if (blockIndex == 3 && ($NF == "java" || $NF == "jsvc")) # $NF(last field) is command field
# only print 4th text block(blockIndex == 3), aka. process info of second top update
print $1 " " $9 # $1 is thread id field, $9 is %cpu field
prevLineHasText = currentLineHasText # update prevLineHasText
awk '{
# from text line to empty line, increase block index
if (previousLine && !$0) blockIndex++
# only print 4th text block(blockIndex == 3), aka. process info of second top update
if (blockIndex == 3 && ($NF == "java" || $NF == "jsvc")) # $NF(last field) is command field
print $1, $9 # $1 is thread id field, $9 is %cpu field
previousLine = $0
}' | sort -k2,2nr
}

Expand Down

0 comments on commit d8df80f

Please sign in to comment.