Debugging by Querying
The previous section described how printk works and how it can be used. What it didn’t talk about are its disadvantages.
A massive use of printk can slow down the system
noticeably, because syslogd keeps syncing
its output files; thus, every line that is printed causes a disk
operation. This is the right implementation from
syslogd’s perspective. It tries to
write everything to disk in case the system crashes right after
printing the message; however, you don’t want to slow down your system
just for the sake of debugging messages. This problem can be solved
by prefixing the name of your log file as it appears in
/etc/syslogd.conf with a
minus.[22] The problem with
changing the configuration file is that the modification will likely
remain there after you are done debugging, even though during normal
system operation you do want messages to be flushed to disk as soon as
possible. An alternative to such a permanent change is running a
program other than klogd (such as
cat /proc/kmsg, as suggested earlier), but this
may not provide a suitable environment for normal system operation.
More often than not, the best way to get relevant information is to query the system when you need the information, instead of continually producing data. In fact, every Unix system provides many tools for obtaining system information: ps, netstat, vmstat, and so on.
Two main techniques are available to driver developers for querying
the system: creating a file in the /proc ...