fixed profiler bug with variable options (#254)

This commit is contained in:
evonneng authored and GitHub committed 2022-08-08 09:53:12 -07:00
1 parent a95f47cd08
commit 6281896e1d
1 file changed
+12 -3
+12 -3
View File
@@ -16,7 +16,7 @@ helpFunction_top()
} }
while getopts "t:o:p:a:" opt; do while getopts "t:o:p" opt; do
case "$opt" in case "$opt" in
t ) type="$OPTARG" ;; t ) type="$OPTARG" ;;
o ) output_file="$OPTARG" ;; o ) output_file="$OPTARG" ;;
@@ -24,20 +24,29 @@ while getopts "t:o:p:a:" opt; do
? ) helpFunction ;; ? ) helpFunction ;;
esac esac
done done
if [ -z "$type" ]; then if [ -z "$type" ]; then
echo "Missing profiling type (flame / top)" echo "Missing profiling type (flame / top)"
fi fi
shift $((OPTIND-1))
program="$@"
program=${program/"--"/"-- --"}
# Print helpFunction in case parameters are empty # Print helpFunction in case parameters are empty
if [[ "$type" = "flame" ]]; then if [[ "$type" = "flame" ]]; then
if [ -z "$output_file" ] || [ -z "$program" ]; then if [ -z "$output_file" ] || [ -z "$program" ]; then
echo "Some or all of the parameters are empty"; echo "Some or all of the parameters are empty";
helpFunction_flame helpFunction_flame
fi fi
py-spy record -o "$output_file" python "$program" command=`echo py-spy record -o "$output_file" python "$program"`
echo "Running..." $command
eval "$command"
elif [[ "$type" = "top" ]]; then elif [[ "$type" = "top" ]]; then
if [ -z "$program" ]; then if [ -z "$program" ]; then
echo "Some or all of the parameters are empty"; echo "Some or all of the parameters are empty";
helpFunction_top helpFunction_top
fi fi
py-spy top python "$program" command=`echo py-spy top python "$program"`
echo "Running..." $command
eval "$command"
fi fi