11#! /bin/bash
22
3- set -e
4-
5- # configure:
6- event=cpu # nativemem
3+ event=cpu
74format=flat
8- nevents=1000
95seconds=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
1210do
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
2122done
23+
2224shift $(( OPTIND- 1 ))
23- data=$1
24- stub=$( basename $data )
25- stub=${stub%% .* }
25+ executable=$1
26+ arguments=${@: 2}
2627
2728which 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 &
3140pid_bash=$!
3241
3342echo PID1=$pid_bash
@@ -38,14 +47,15 @@ echo PID2=$pid_java
3847
3948ps 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
4959kill -9 $pid_java
50- rm -f pro_ $stub .hipo
60+ rm -f asprof_ $stub .hipo
5161
0 commit comments