Skip to content

Commit

Permalink
Add configurable jstack profiling (#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
grafnu authored May 4, 2024
1 parent 351b5f8 commit b300a9a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ credentials.json
/udmis/build/
/udmis/out/
/udmis/var/
/udmis/profile/
/udmis/.idea/libraries/
/selfie/build/
/pubber/build/
Expand Down
22 changes: 22 additions & 0 deletions udmis/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ shift
ROOT=$(dirname $0)/..
cd $ROOT

PROFILE_BASE=profile/
mkdir -p $PROFILE_BASE

echo
echo Initial env:
env
Expand Down Expand Up @@ -78,5 +81,24 @@ echo Final java env:
env
echo

JSTACK=$(dirname $(realpath `which java`))/jstack
if [[ -n $PROFILE_SEC ]]; then
# BASHPID will be replaced with the java process becasue of the exec below
TPID=$BASHPID

echo Profiling java process $TPID usage every ${PROFILE_SEC}s
(
cd $PROFILE_BASE
while [[ -d /proc/$TPID ]]; do
sleep $PROFILE_SEC
outfile=stack_$(printf %08d $SECONDS).txt
echo Writing stack profile to $outfile
$JSTACK $TPID > $outfile
stale_files=$(ls -rt | head -n -1000)
[[ -n $stale_files ]] && rm $stale_files
done
) &
fi

# Run with exec to replace shell so java receives SIGTERM signal.
exec java -jar $POD_JAR $POD_CONFIG
1 change: 1 addition & 0 deletions udmis/etc/k8s_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ metadata:
data:
BITBOX_DISCOVERY:
ETCD_CLUSTER:
PROFILE_SEC: "60"
UDMI_NAMESPACE: @UDMI_NAMESPACE@
6 changes: 6 additions & 0 deletions udmis/etc/k8s_udmis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ spec:
name: config
key: ETCD_CLUSTER
optional: true
- name: PROFILE_SEC
valueFrom:
configMapKeyRef:
name: config
key: PROFILE_SEC
optional: true
- name: BITBOX_DISCOVERY
valueFrom:
configMapKeyRef:
Expand Down
1 change: 1 addition & 0 deletions udmis/etc/peringknife~k8s_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ metadata:
data:
BITBOX_DISCOVERY: prodev~udmi_target-discover
ETCD_CLUSTER: etcd-set-0.etcd-set
PROFILE_SEC: "10"
UDMI_NAMESPACE: @UDMI_NAMESPACE@

0 comments on commit b300a9a

Please sign in to comment.