Date: Tue, 14 Aug 2012 08:49:56 +1200 From: Andrew Thompson <thompsa@FreeBSD.org> To: Luigi Rizzo <rizzo@iet.unipi.it> Cc: current@freebsd.org Subject: Re: rate-limited [kernel] debugging messages ? Message-ID: <CAFAOGNQAnvWsyi-jsBYm6PCfeQ1Bu4-mWqoi1k1vY5wYxHgtGA@mail.gmail.com> In-Reply-To: <20120813205622.GA85732@onelab2.iet.unipi.it> References: <20120813205622.GA85732@onelab2.iet.unipi.it>
next in thread | previous in thread | raw e-mail | index | archive | help
On 14 August 2012 08:56, Luigi Rizzo <rizzo@iet.unipi.it> wrote: > In my kernel stuff i tend to define debugging macros of the form > > #define ND(format, ...) do {} while (0) > #define D(format, ...) do { <some useful stuff> } while (0) > > so it is convenient to comment them out when not needed anymore. > > I have recently tried the following rate-limited version, where the > first parameter indicates how many lines per second are output at most > > /* rate limited, lps indicates how many per second */ > #define RD(lps, format, ...) \ > do { \ > static int t0, cnt; \ > if (t0 != time_second) { \ > t0 = time_second; \ > cnt = 0; \ > } \ > if (cnt++ < lps) \ > D(format, ##__VA_ARGS__); \ > } while (0) > > I was wondering if people have better suggestions or perhaps there > are already similar macros used by other parts of the kernel. > See ppsratecheck(), it does most of that already. Andrew
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFAOGNQAnvWsyi-jsBYm6PCfeQ1Bu4-mWqoi1k1vY5wYxHgtGA>