Skip to content

Commit 5b69d8a

Browse files
baltzelltongtongcao
authored andcommitted
feat: generalize asprof wrapper script (#1123)
* check for recon-util in $PATH * add flexibility * cleanup help printout * cleanup
1 parent cb4aed2 commit 5b69d8a

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

libexec/profile

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
11
#!/bin/bash
22

3-
set -e
4-
5-
# configure:
6-
event=cpu #nativemem
3+
event=cpu
74
format=flat
8-
nevents=1000
95
seconds=12
10-
yaml=etc/services/data-ai-uber.yml
11-
while getopts y:n:f:e:s:h opt
6+
usage1="Usage: profile [-h] [-s seconds] [-w seconds] [-e event] [-f format] [--] executable args"
7+
usage2="Usage: profile [options] executable args\nOptions:\n\t[-h] [-s seconds] [-w seconds]\n\t[-e cpu|alloc|nativemem|lock|cache-misses]\n\t[-f flat|traces|collapsed|flamegraph|tree|jfr|otlp]"
8+
9+
while getopts s:f:e:o:w:h opt
1210
do
1311
case $opt in
1412
s) seconds=$OPTARG ;;
15-
y) yaml=$OPTARG ;;
16-
n) nevents=$OPTARG ;;
1713
f) format=$OPTARG ;;
1814
e) event=$OPTARG ;;
19-
h) echo "\nUsage: profile [-y YAML] [-n #] [-e EVENT] datafile" && exit 0 ;;
15+
o) stub=$OPTARG ;;
16+
w) warmup=$OPTARG ;;
17+
h) echo -e $usage2 && exit 0 ;;
18+
--) break ;;
19+
\?) echo $usage1 && exit 1 ;;
20+
# :) echo $usage1 && exit 2 ;;
2021
esac
2122
done
23+
2224
shift $((OPTIND-1))
23-
data=$1
24-
stub=$(basename $data)
25-
stub=${stub%%.*}
25+
executable=$1
26+
arguments=${@:2}
2627

2728
which asprof >& /dev/null
28-
[ "$?" -ne 0 ] && echo 'ERROR: asprof is not in $PATH.' && exit 9
29+
[ "$?" -ne 0 ] && echo 'ERROR: asprof is not in $PATH.' && echo -e $usage2 && exit 3
30+
31+
which $executable >& /dev/null
32+
[ "$?" -ne 0 ] && echo "ERROR: $executable is not in \$PATH." && echo -e $usage2 && exit 4
33+
34+
echo "Running asprof on '$executable $arguments' ..."
35+
36+
set -e
37+
38+
$executable $arguments >& asprof_$stub.log
2939

30-
recon-util -y $yaml -n $nevents -o pro_$stub.hipo -i $data >& pro_$stub.log &
3140
pid_bash=$!
3241

3342
echo PID1=$pid_bash
@@ -38,14 +47,15 @@ echo PID2=$pid_java
3847

3948
ps waux && ps -p $pid_java
4049

41-
echo "Waiting for 60 seconds of CoatJava warmup ..."
42-
for x in $(seq 60); do let y=60-$x && echo -e -n "\r$y ..." && sleep 1; done
50+
echo "Waiting for $warmup seconds of warmup ..."
51+
for x in $(seq $warmup); do let y=$warmup-$x && echo -e -n "\r$y ..." && sleep 1; done
4352

44-
tail -n 42 pro_$stub.log
53+
# This 42 is probably for recon-util:
54+
tail -n 42 asprof_$stub.log
4555

46-
asprof --title "Coatjava - asprof - $event" -e $event \
47-
-d $seconds -o $format -f pro_${format}_${event}_$stub $pid_java
56+
asprof --title "Coatjava:asprof:$executable:$event" -e $event \
57+
-d $seconds -o $format -f asprof_${format}_${event}_$stub $pid_java
4858

4959
kill -9 $pid_java
50-
rm -f pro_$stub.hipo
60+
rm -f asprof_$stub.hipo
5161

0 commit comments

Comments
 (0)