-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·50 lines (44 loc) · 1.05 KB
/
entrypoint.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
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env sh
set -e
capture() {
echo "duration: $2s"
if [ -z "$2" ]; then
exit 131 # duration not provided
fi
case $1 in
'')
pid=$(ps -e -opid= --sort -%cpu | head -n1)
;;
''|*[!0-9]*)
pid="$(pgrep $1 || exit 132)" # process not found
;;
*)
pid="$1"
;;
esac
echo "pid: $1"
echo "is it java?"
exe=$(readlink "/proc/$pid/exe")
case "$exe" in
*java*)
echo "yes"
cat /proc/$pid/cmdline | grep -qFe '-XX:+PreserveFramePointer' || exit 133
set +e
jcmd $pid Compiler.perfmap
set -e
if [ $? -ne 0 ]; then
cp /libperfmap.so /proc/$pid/root
java -cp /attach-main.jar net.virtualvoid.perf.AttachOnce $pid
nspid=$(cat proc/$pid/status | grep NSpid | cut -f3)
cp /proc/$pid/root/tmp/perf-$nspid.map /tmp/perf-$pid.map
fi
;;
*)
echo "no"
;;
esac
echo "capturing..."
profile --stack-storage-size=65536 -adf -p $pid $2 | tee /out/profile
}
capture "$1" "$2" 1>&2
burn convert --type=folded /out/profile