System information
202 System Analysis and Tuning Guide
1. By default, Valgrind sends its messages to the file descriptor 2, which is the stan-
dard error output. You can tell Valgrind to send its messages to any other file de-
scriptor with the --log-fd=file_descriptor_number option.
2. The second and probably more useful way is to send Valgrind's messages to a file
with --log-file=filename. This option accepts several variables, for ex-
ample, %p gets replaced with the PID of the currently profiled process. This way
you can send messages to different files based on their PID. %q{env_var} is re-
placed with the value of the related env_var environment variable.
The following example checks for possible memory errors during the Apache Web
server restart, while following children processes and writing detailed Valgrind's
messages to separate files distinguished by the current process PID:
tux@mercury:~> valgrind -v --tool=memcheck --trace-children=yes \
--log-file=valgrind_pid_%p.log rcapache2 restart
This process created 52 log files in the testing system, and took 75 seconds instead
of the usual 7 seconds needed to run rcapache2 restart without Valgrind,
which is approximately 10 times more.
tux@mercury:~> ls -1 valgrind_pid_*log
valgrind_pid_11780.log
valgrind_pid_11782.log
valgrind_pid_11783.log
[...]
valgrind_pid_11860.log
valgrind_pid_11862.log
valgrind_pid_11863.log
3. You may also prefer to send the Valgrind's messages over the network. You need
to specify the aa.bb.cc.dd IP address and port_num port number of the net-
work socket with the --log-socket=aa.bb.cc.dd:port_num option. If
you omit the port number, 1500 will be used.
It is useless to send Valgrind's messages to a network socket if no application is ca-
pable of receiving them on the remote machine. That is why valgrind-lis-
tener, a simple listener, is shipped together with Valgrind. It accepts connections
on the specified port and copies everything it receives to the standard output.
17.3.7 Error Messages
Valgrind remembers all error messages, and if it detects a new error, the error is com-
pared against old error messages. This way Valgrind checks for duplicate error mes-