Created
November 21, 2017 07:50
-
-
Save StefanHamminga/eef90fd72f9fa0e7a560524f378c973f to your computer and use it in GitHub Desktop.
Bash function to build, sanitise, debug and PGO profile a single source C++ file such as a (header-only) library test file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function compile++ { | |
local outfn="${1%.*}" | |
ionice -c 3 \ | |
nice -n 19 \ | |
g++ \ | |
-std=gnu++17 \ | |
-pipe \ | |
-march=haswell \ | |
-mtune=skylake \ | |
-O3 \ | |
-fconstexpr-loop-limit=2147483647 \ | |
-fstack-protector-strong \ | |
-flto \ | |
-fno-fat-lto-objects \ | |
-fuse-linker-plugin \ | |
-fdiagnostics-color=always \ | |
-fbounds-check \ | |
-fstack-check \ | |
-fsanitize=undefined,address \ | |
-ggdb \ | |
-Wl\,--unresolved-symbols=report-all \ | |
-Wl\,--print-memory-usage \ | |
-Wno-packed-bitfield-compat \ | |
-Wall \ | |
-Wextra \ | |
-Wuninitialized \ | |
-Wnull-dereference \ | |
-Wdouble-promotion \ | |
-Wchkp \ | |
-Wmisleading-indentation \ | |
-Wduplicated-cond \ | |
-Wduplicated-branches \ | |
-Wlogical-op \ | |
-Wrestrict \ | |
-Wshadow \ | |
-Wformat=2 \ | |
-Wno-pmf-conversions \ | |
-Wuseless-cast \ | |
-o "${outfn}" "$1" || return $? | |
# Valgrind does not combine with the run-time sanitizer: | |
# valgrind --track-origins=yes --leak-check=full ./"${outfn}" | |
echo "*** Running with full instrumentation (run-time sanitizer) and debugging:" && sleep 30s && \ | |
./"${outfn}" | |
if [ $? -eq 0 ]; then | |
ionice -c 3 \ | |
nice -n 19 \ | |
g++ \ | |
-std=gnu++17 \ | |
-pipe \ | |
-march=haswell \ | |
-mtune=skylake \ | |
-O3 \ | |
-fconstexpr-loop-limit=2147483647 \ | |
-flto \ | |
-fno-fat-lto-objects \ | |
-fuse-linker-plugin \ | |
-fdiagnostics-color=always \ | |
-fprofile-generate \ | |
--coverage \ | |
-o "${outfn}" "$1" && \ | |
echo "*** Running optimized and PGO instrumented:" && sleep 30s &&\ | |
./"${outfn}" && \ | |
ionice -c 3 \ | |
nice -n 19 \ | |
g++ \ | |
-std=gnu++17 \ | |
-pipe \ | |
-march=haswell \ | |
-mtune=skylake \ | |
-O3 \ | |
-fconstexpr-loop-limit=2147483647 \ | |
-flto \ | |
-fno-fat-lto-objects \ | |
-fuse-linker-plugin \ | |
-fdiagnostics-color=always \ | |
-fprofile-use \ | |
-o "${outfn}.pgo" "$1" && \ | |
echo "*** Running optimized and PGO profiled:" && sleep 30s && \ | |
./"${outfn}.pgo" | |
gcov "$1" -mrblf > /dev/null | |
else | |
gdb -ex "set logging file /tmp/gdb-$1-`date +%Y-%m-%d_%H:%M:%S`.txt" -ex "set logging on" -ex run -ex bt -ex quit "${outfn}" | |
fi | |
} | |
complete -f -X '!*.@(cpp|cxx|c++|CPP|CXX|C++)' compile++ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment