FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
infrastructure-examples/java/util/java-thread-high-cpu.sh at main · codejsha/infrastructure-examples · GitHub
codejsha
/
infrastructure-examples
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
6
Code
Issues
0
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
infrastructure-examples
/
java
/
util
/
java-thread-high-cpu.sh
Copy path
More file actions
More file actions
Latest commit
History
History
History
42 lines (34 loc) · 1.12 KB
Breadcrumbs
infrastructure-examples
/
java
/
util
/
java-thread-high-cpu.sh
Copy path
File metadata and controls
42 lines (34 loc) · 1.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!
/bin/bash
trap
'
echo "${BASH_SOURCE[0]}: line ${LINENO}: status ${?}: user ${USER}: func ${FUNCNAME[0]}"
'
ERR
set
-o errexit
set
-o errtrace
#
## Usage:
#
## bash ./java-thread-high-cpu.sh <PID>
PID=
"
${1}
"
JAVA_HOME=
"
/usr/lib/jvm/java-11
"
#
JAVA_HOME="/usr/lib/jvm/java-1.8.0"
LOOP_COUNT=
"
1
"
TOP_THREAD_COUNT=
"
5
"
INTERVAL_SECONDS=
"
5
"
if
[
-z
"
${PID}
"
]
;
then
echo
"
Usage: bash ./java-thread-high-cpu.sh <PID>
"
exit
fi
if
[
-z
"
${JAVA_HOME}
"
]
;
then
echo
"
[ERROR] The JAVA_HOME (
${JAVA_HOME}
) does not exist!
"
exit
fi
for
IDX1
in
$(
seq 1
${LOOP_COUNT}
)
do
echo
"
[INFO] Print
${IDX1}
times...
"
ps -eLo pid,ppid,tid,pcpu,comm
|
grep
${PID}
>
ps-
${PID}
-
${IDX1}
.out
${JAVA_HOME}
/bin/jstack -l
${PID}
>
threaddump-
${PID}
-
${IDX1}
.tdump
top -b -n 1 -p
${PID}
>
top-
${PID}
-
${IDX1}
.out
HIGH_CPU_THREADS=(
$(
cat ps-
${PID}
-
${IDX1}
.out
|
awk
'
{ print $4" "$3 }
'
\
|
sort --reverse --numeric-sort
|
head --lines=
${TOP_THREAD_COUNT}
|
awk
'
{ print $2 }
'
)
)
for
IDX2
in
$(
seq 0
$((
${TOP_THREAD_COUNT}
-
1
))
)
do
printf
'
0x%x\n
'
${HIGH_CPU_THREADS[$IDX2]}
done
sleep
${INTERVAL_SECONDS}
done
Back
|
FazBrowse Home
|
New Git URL