User: Password:
Subscribe / Log in / New account

Keeping printk() under control

Keeping printk() under control

Posted Jan 15, 2004 17:55 UTC (Thu) by rwmj (subscriber, #5474)
Parent article: Keeping printk() under control

A long long time ago (13 years?) I used to write testing software for scientific X-ray detectors and we used to have a similar problem with the log messages. We devised a technique to reduce the number of messages printed and make them relevant, which might be of interest.

Our testing code usually started off with an outer loop which ran all the tests over M * 1000 passes, and inside that a loop which did tests 1 - N, and inside each of those tests, several layers of inner loops.

We maintained a *stack* of messages, such that the outer loop messages were at level 1, then the next inner messages at level 2 and the next ones at level 3 and so on. The key here is that you *don't* print out any messages at all until you get a failure - at which point you print out the stack of messages.

Thus a typical failure message would look like:

1: In pass 2345
2: .. In test 3
3: .. .. Testing memory line 4567
4: .. .. .. Write test failed

The verbosity is reduced to nothing, except in the case where you actually have some sort of error, in which case you know exactly where it happened.

Also, you could set the verbosity. For example, you could ask it to print all messages at level 1.

It seems to me the Linux kernel could implement something similar by using:

push_printk ();
for (i = 0; i < 10; ++i) {
printk ("very verbose message about where we are now - don't worry \
it won't get printed unless there's a failure");
pop_printk ();


(Log in to post comments)

Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds