Hello I'm trying to run valgrind on several input files to find out if there are any memory leaks in my program and want to get the program output alongside valgrind's heap summary into seperate files, I'd appreciate some help
I tried running the following lines:
for i in {0..99}
do
valgrind --leak-check=full --leak-resolution=med --track-origins=yes --vgdb=no
./IndustrialTakeover<./tests/input/in${i}.txt>./tests/valgrind_check/program/output${i}.txt
done
but this doesn't provide the heap summary output into a file of their own
and then I tried running :
for i in {0..99}
do
valgrind --log-file=./tests/valgrind_check/valgrind_message/output${i}.txt
--leak-check=full --leak-resolution=med --track-origins=yes --vgdb=no
./IndustrialTakeover<./tests/input/in${i}.txt>./tests/valgrind_check/program/output${i}.txt
done
but it also didn't work and I got the message
valgrind: Use --help for more information.
--leak-check=full: command not found
valgrind: no program specified
, would appreciate some help!
CodePudding user response:
the solution to this problem is using the following lines:
for i in {0..99} ;
do
valgrind valgrind --log-file=./tests/valgrind_check/valgrindmessage/output${i}.txt --leak-check=full --leak-resolution=med --track-origins=no --vgdb=no./IndustrialTakeover<./tests/input/in${i}.txt>./tests/valgrind_check/program/output${i}.txt ;
done
but ofcourse you'll have to replace the range in the for loop, app with your own app and paths with your own paths.
CodePudding user response:
A more Valgrind-y way of doing this is to incorporate the pid into the log file name, like this:
valgrind valgrind --log-file=./tests/valgrind_check/valgrindmessage/valgrind.%p.log --leak-check=full --leak-resolution=med --track-origins=no --vgdb=no./IndustrialTakeover<./tests/input/in${i}.txt>./tests/valgrind_check/program/output${i}.txt ;
Valgrind will replace the %p with the pid.
This is particularly useful if you are using --trace-children=yes
as it will also generate one log per process spawned.