@@ -259,26 +259,26 @@ cleanupWhenExit() {
259259}
260260trap " cleanupWhenExit" EXIT
261261
262-
263262headInfo () {
264263 colorEcho " 0;34;42" ================================================================================
265264 echo " $( date " +%Y-%m-%d %H:%M:%S.%N" ) [$(( i + 1 )) /$update_count ]: ${COMMAND_LINE[@]} "
266265 colorEcho " 0;34;42" ================================================================================
267266 echo
268267}
269268
269+ if [ -n " ${pid} " ]; then
270+ readonly ps_process_select_options=" -p $pid "
271+ else
272+ readonly ps_process_select_options=" -C java"
273+ fi
274+
270275# output field: pid, thread id(lwp), pcpu, user
271276# order by pcpu(percentage of cpu usage)
272277findBusyJavaThreadsByPs () {
273- if [ -n " ${pid} " ]; then
274- local -r ps_options=" -p $pid "
275- else
276- local -r ps_options=" -C java"
277- fi
278278 # 1. sort by %cpu by ps option `--sort -pcpu`
279279 # 2. use wide output(unlimited width) by ps option `-ww`
280280 # avoid trunk user column to username_fo+ or $uid alike
281- ps $ps_options -wwLo pid,lwp,pcpu,user --sort -pcpu --no-headers | head -n " ${count} "
281+ ps $ps_process_select_options -wwLo pid,lwp,pcpu,user --sort -pcpu --no-headers | head -n " ${count} "
282282}
283283
284284# top with output field: thread id, %cpu
@@ -313,13 +313,8 @@ __top_threadId_cpu() {
313313
314314# output format is same as function findBusyJavaThreadsByPs
315315findBusyJavaThreadsByTop () {
316- if [ -n " ${pid} " ]; then
317- local -r ps_options=" -p $pid "
318- else
319- local -r ps_options=" -C java"
320- fi
321316 # ps output field: pid, thread id(lwp), user
322- local -r ps_out=" $( ps $ps_options -wwLo pid,lwp,user --no-headers) "
317+ local -r ps_out=" $( ps $ps_process_select_options -wwLo pid,lwp,user --no-headers) "
323318
324319 local idx=0
325320 local -a line
0 commit comments