Skip to content

Instantly share code, notes, and snippets.

@Estecka
Created February 9, 2021 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Estecka/45a369c4a139c3b67f36148215548c29 to your computer and use it in GitHub Desktop.
Save Estecka/45a369c4a139c3b67f36148215548c29 to your computer and use it in GitHub Desktop.
Valgrind for 42 projects.
#!/bin/bash
EXEC=./a.out # Put your executable's path here.
LOG=valgrind
valgrind \
--tool=memcheck \
--leak-check=full \
--leak-resolution=high \
--track-origins=yes \
--show-reachable=yes \
--log-file=${LOG}.log \
$EXEC $@ \
;
# Separate the logs from multiple processes into multiple log files.
grep '==[0-9]*==' <valgrind.log --only-matching | sort --unique | tr -d = |
while read -r pid;
do \
pidlog=${LOG}.${pid}.log;
echo $pidlog;
grep "$pid" <${LOG}.log >$pidlog;
grep -A1 "valgrind" $pidlog | grep $EXEC;
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment