How to redirect Valgrind's output to a file?

前端 未结 4 2003
再見小時候
再見小時候 2021-01-30 02:08

While working with Valgrind tool, i need to log the details produced by valgrind tool. How can I accomplish that? I tried something like,

 valgrind a.out | test
         


        
相关标签:
4条回答
  • 2021-01-30 02:23

    By default, Valgrind writes its output to stderr. So you need to do something like:

    valgrind a.out > log.txt 2>&1
    

    Alternatively, you can tell Valgrind to write somewhere else; see http://valgrind.org/docs/manual/manual-core.html#manual-core.comment (but I've never tried this).

    0 讨论(0)
  • 2021-01-30 02:30

    You can also set the options --log-fd if you just want to read your logs with a less. For example :

    valgrind --log-fd=1 ls | less
    
    0 讨论(0)
  • 2021-01-30 02:31

    In addition to the other answers (particularly by Lekakis), some string replacements can also be used in the option --log-file= as elaborated in the Valgrind's user manual.

    Four replacements were available at the time of writing:

    • %p: Prints the current process ID
      • valgrind --log-file="myFile-%p.dat" <application-name>
    • %n: Prints file sequence number unique for the current process
      • valgrind --log-file="myFile-%p-%n.dat" <application-name>
    • %q{ENV}: Prints contents of the environment variable ENV
      • valgrind --log-file="myFile-%q{HOME}.dat" <application-name>
    • %%: Prints %
      • valgrind --log-file="myFile-%%.dat" <application-name>
    0 讨论(0)
  • 2021-01-30 02:47
    valgrind --log-file="filename"
    
    0 讨论(0)
提交回复
热议问题