From owner-freebsd-current@FreeBSD.ORG Mon Aug 13 20:37:29 2012 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 2177E106566C for ; Mon, 13 Aug 2012 20:37:29 +0000 (UTC) (envelope-from luigi@onelab2.iet.unipi.it) Received: from onelab2.iet.unipi.it (onelab2.iet.unipi.it [131.114.59.238]) by mx1.freebsd.org (Postfix) with ESMTP id D9D308FC0A for ; Mon, 13 Aug 2012 20:37:28 +0000 (UTC) Received: by onelab2.iet.unipi.it (Postfix, from userid 275) id 744877300A; Mon, 13 Aug 2012 22:56:22 +0200 (CEST) Date: Mon, 13 Aug 2012 22:56:22 +0200 From: Luigi Rizzo To: current@freebsd.org Message-ID: <20120813205622.GA85732@onelab2.iet.unipi.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.3i Cc: Subject: rate-limited [kernel] debugging messages ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Aug 2012 20:37:29 -0000 In my kernel stuff i tend to define debugging macros of the form #define ND(format, ...) do {} while (0) #define D(format, ...) do { } 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. cheers luigi