Search code examples
bashshellvalgrind

How can I redirect valgrind output (Heap summary) alongside my program's output in a command?


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!


Solution

  • 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.