ref: 65d8a293dceaf150ab412a18ab4fcf602c5ba00b
parent: e579183070a3bc60cc6f9976d2faeaf8d28f6211
author: cancel <cancel@cancel.fm>
date: Thu Nov 29 14:42:14 EST 2018
Add timing stats option to build tool
--- a/tool
+++ b/tool
@@ -21,6 +21,7 @@
-d Enable compiler safeguards like -fstack-protector.
You should probably do this if you plan to give the
compiled binary to other people.
+ -s Print statistics about compile time and binary size.
-h or --help Print this message and exit.
EOF
}
@@ -38,8 +39,9 @@
verbose=0
protections_enabled=0
+stats_enabled=0
-while getopts c:dhv-: opt_val; do
+while getopts c:dhsv-: opt_val; do
case "$opt_val" in
-)
case "$OPTARG" in
@@ -54,6 +56,7 @@
c) compiler_exe="$OPTARG";;
h) print_usage; exit 0;;
d) protections_enabled=1;;
+ s) stats_enabled=1;;
v) verbose=1;;
\?) print_usage >&2; exit 1;;
*) break;;
@@ -79,6 +82,18 @@
"$@"
}
+TIMEFORMAT='%3R'
+
+last_time=
+
+timed_stats() {
+ if [[ $stats_enabled = 1 ]]; then
+ { last_time=$( { time "$@" 1>&3- 2>&4-; } 2>&1 ); } 3>&1 4>&2
+ else
+ "$@"
+ fi
+}
+
if [[ ($os == bsd) || ($os == unknown) ]]; then
warn "Build script not tested on this platform"
fi
@@ -175,9 +190,14 @@
add source_files cli_main.c
try_make_dir "$build_dir"
try_make_dir "$build_dir/$build_subdir"
+ local out_path=$build_dir/$build_subdir/$out_exe
# bash versions quirk: empty arrays might give error on expansion, use +
# trick to avoid expanding second operand
- verbose_echo "$compiler_exe" "${compiler_flags[@]}" -o "$build_dir/$build_subdir/$out_exe" "${source_files[@]}" ${libraries[@]+"${libraries[@]}"}
+ verbose_echo timed_stats "$compiler_exe" "${compiler_flags[@]}" -o "$out_path" "${source_files[@]}" ${libraries[@]+"${libraries[@]}"}
+ if [[ $stats_enabled = 1 ]]; then
+ echo "time: $last_time"
+ stat -c "size: %s" -- "$out_path"
+ fi
}
print_info() {