Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
- remove redundant parenthesis, reduce code indentation
- utils function -> util functions
  • Loading branch information
oldratlee committed Jan 1, 2018
1 parent ee71655 commit db43daa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion find-in-jars
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ else
fi

################################################################################
# utils
# util funtions
################################################################################

[ -t 1 ] && readonly is_console=true || readonly is_console=false
Expand Down
2 changes: 1 addition & 1 deletion parseOpts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# @author Jerry Lee (oldratlee at gmail dot com)

#####################################################################
# Utils Funtions
# Util Funtions
#####################################################################

# NOTE: $'foo' is the escape sequence syntax of bash
Expand Down
32 changes: 15 additions & 17 deletions show-busy-java-threads
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ readonly -a COMMAND_LINE=("$0" "$@")
readonly USER="`whoami`"

################################################################################
# utils funtions
# util funtions
################################################################################

# NOTE: $'foo' is the escape sequence syntax of bash
Expand Down Expand Up @@ -190,22 +190,20 @@ printStackOfThreads() {
((counter++))
local jstackFile=/tmp/${uuid}_${pid}
[ -f "${jstackFile}" ] || {
{
if [ "${user}" == "${USER}" ]; then
# run without sudo, when java process user is current user
"$jstack_path" ${force} $mix_native_frames $more_lock_info ${pid} > ${jstackFile}
elif [ $UID == 0 ]; then
# if java process user is not current user, must run jstack with sudo
sudo -u "${user}" "$jstack_path" ${force} $mix_native_frames $more_lock_info ${pid} > ${jstackFile}
else
# current user is not root user, so can not run with sudo; print error message and rerun suggestion
redPrint "[$counter] Fail to jstack busy(${pcpu}%) thread(${threadId}/${threadId0x}) stack of java process(${pid}) under user(${user})."
redPrint "User of java process($user) is not current user($USER), need sudo to rerun:"
yellowPrint " sudo ${COMMAND_LINE[@]}"
normalPrint
continue
fi
} || {
if [ "${user}" == "${USER}" ]; then
# run without sudo, when java process user is current user
"$jstack_path" ${force} $mix_native_frames $more_lock_info ${pid} > ${jstackFile}
elif [ $UID == 0 ]; then
# if java process user is not current user, must run jstack with sudo
sudo -u "${user}" "$jstack_path" ${force} $mix_native_frames $more_lock_info ${pid} > ${jstackFile}
else
# current user is not root user, so can not run with sudo; print error message and rerun suggestion
redPrint "[$counter] Fail to jstack busy(${pcpu}%) thread(${threadId}/${threadId0x}) stack of java process(${pid}) under user(${user})."
redPrint "User of java process($user) is not current user($USER), need sudo to rerun:"
yellowPrint " sudo ${COMMAND_LINE[@]}"
normalPrint
continue
fi || {
redPrint "[$counter] Fail to jstack busy(${pcpu}%) thread(${threadId}/${threadId0x}) stack of java process(${pid}) under user(${user})."
normalPrint
rm ${jstackFile}
Expand Down
2 changes: 1 addition & 1 deletion test-cases/parseOpts-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BASE=`dirname $0`


#################################################
# Utils Functions
# Util Functions
#################################################

# NOTE: $'foo' is the escape sequence syntax of bash
Expand Down

0 comments on commit db43daa

Please sign in to comment.