File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -295,13 +295,19 @@ __top_threadId_cpu() {
295295 # so as to prevent top command output format being change by .toprc user config file unexpectedly
296296 # 3. use option `-d 0.5`(update interval 0.5 second) and `-n 2`(update 2 times),
297297 # and use second time update data to get cpu percentage of thread in 0.5 second interval
298+ # 4. top v3.3, there is 1 black line between 2 update;
299+ # but top v3.2, there is 2 blank lines between 2 update!
298300 HOME=" $tmp_store_dir " top -H -b -d $top_delay -n 2 |
299- awk ' {
300- if (idx == 3 && $NF == "java") # $NF(last field) is command field
301- # only print 4th text block(idx == 3), aka. process info of second top update
302- print $1 " " $9 # $1 is thread id field, $9 is %cpu field
303- if ($0 == "")
304- idx++
301+ awk ' BEGIN { blockIndex = 0; currentLineHasText = 0; prevLineHasText = 0; } {
302+ currentLineHasText = ($0 != "")
303+ if (prevLineHasText && !currentLineHasText)
304+ blockIndex++ # from text line to empty line, increase block index
305+
306+ if (blockIndex == 3 && $NF == "java") # $NF(last field) is command field
307+ # only print 4th text block(blockIndex == 3), aka. process info of second top update
308+ print $1 " " $9 # $1 is thread id field, $9 is %cpu field
309+
310+ prevLineHasText = currentLineHasText # update prevLineHasText
305311 }' | sort -k2,2nr
306312}
307313
You can’t perform that action at this time.
0 commit comments