Skip to content

Commit

Permalink
improve multiply var declaration/read
Browse files Browse the repository at this point in the history
- read multiply var instead array
- simplify the multiply local var deceleration
  • Loading branch information
oldratlee committed Jan 12, 2020
1 parent b03c065 commit 943689c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
4 changes: 1 addition & 3 deletions bin/echo-args
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ readonly ec=$'\033' # escape char
readonly eend=$'\033[0m' # escape end

echoArg() {
local index=$1
local count=$2
local value=$3
local index="$1" count="$2" value="$3"

# if stdout is console, turn on color output.
[ -t 1 ] &&
Expand Down
3 changes: 1 addition & 2 deletions bin/find-in-jars
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ readonly total_count="$(echo $(echo "$jar_files" | wc -l))"
findInJarFiles() {
$is_console && local -r grep_color_option='--color=always'

local counter=1
local jar_file
local counter=1 jar_file
while read jar_file; do
printResponsiveMessage "finding in jar($((counter++))/$total_count): $jar_file"

Expand Down
17 changes: 4 additions & 13 deletions bin/show-busy-java-threads
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,10 @@ __complete_pid_user_by_ps() {
echo "$ps_out" | logAndCat "${ps_cmd_line[@]}" > "${store_file_prefix}$(( i + 1 ))_ps"
fi

local idx=0
local -a line
while IFS=" " read -a line ; do
local idx=0 threadId pcpu
while read threadId pcpu ; do
(( idx < count )) || break

local threadId="${line[0]}"
local pcpu="${line[1]}"

# output field: pid, threadId, pcpu, user
local output_fields="$( echo "$ps_out" |
awk -v "threadId=$threadId" -v "pcpu=$pcpu" '$2==threadId {
Expand All @@ -379,14 +375,9 @@ findBusyJavaThreadsByTop() {
}

printStackOfThreads() {
local -a line
local idx=0
while IFS=" " read -a line ; do
local pid="${line[0]}"
local threadId="${line[1]}"
local idx=0 pid threadId pcpu user
while read pid threadId pcpu user ; do
local threadId0x="0x`printf %x ${threadId}`"
local pcpu="${line[2]}"
local user="${line[3]}"

(( idx++ ))
local jstackFile="${store_file_prefix}$(( i + 1 ))_jstack_${pid}"
Expand Down

0 comments on commit 943689c

Please sign in to comment.