-
Notifications
You must be signed in to change notification settings - Fork 6
/
get_worker_memory_usage.sh
executable file
·39 lines (30 loc) · 1.13 KB
/
get_worker_memory_usage.sh
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
#!/bin/bash
# Step 1: Get all processes matching the specific Gradle command
PIDS=$(pgrep -f 'org.gradle.wrapper.GradleWrapperMain -q execute -PmainClass=io.temporal.samples.moneytransfer.AccountTransferWorker')
if [ -z "$PIDS" ]; then
echo "No matching processes found."
exit 1
fi
# Step 2: For each PID, print the PID, -Xmx and -Xms values, and explanation text
echo "Checking JVM memory settings for each process..."
for PID in $PIDS; do
echo "--------------------------------------------"
echo "Process ID: $PID"
# Extract the -Xmx and -Xms values using ps and sed
XMX=$(ps -p $PID -o args= | sed -n 's/.*\(-Xmx[^ ]*\).*/\1/p')
XMS=$(ps -p $PID -o args= | sed -n 's/.*\(-Xms[^ ]*\).*/\1/p')
if [ -n "$XMS" ]; then
echo "-Xms: $XMS (Initial heap size for the JVM)"
else
echo "-Xms: Not set"
fi
# Print the values with explanation
if [ -n "$XMX" ]; then
echo "-Xmx: $XMX (Maximum heap size for the JVM)"
else
echo "-Xmx: Not set"
fi
# Step 3: Report the actual memory usage in megabytes
MEM_USAGE=$(ps -p $PID -o rss= | awk '{print $1/1024 " MB"}')
echo "Actual memory usage: $MEM_USAGE"
done