Discussion:
[Linuxptp-devel] [PATCHv2 2/3] print: add rate limited versions of pr_* macros.
Miroslav Lichvar
2015-09-10 09:49:27 UTC
Permalink
Signed-off-by: Miroslav Lichvar <***@redhat.com>
---
print.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/print.h b/print.h
index f5ed248..6d7aa94 100644
--- a/print.h
+++ b/print.h
@@ -44,4 +44,21 @@ void print_set_verbose(int value);
#define pr_info(x...) print(LOG_INFO, x)
#define pr_debug(x...) print(LOG_DEBUG, x)

+#define PRINT_RL(l, i, x...) \
+ do { \
+ static time_t last = -i; \
+ if (!rate_limited(i, &last)) \
+ print(l, x); \
+ } while (0);
+
+/* Rate limited versions */
+#define pl_emerg(i, x...) PRINT_RL(LOG_EMERG, i, x)
+#define pl_alert(i, x...) PRINT_RL(LOG_ALERT, i, x)
+#define pl_crit(i, x...) PRINT_RL(LOG_CRIT, i, x)
+#define pl_err(i, x...) PRINT_RL(LOG_ERR, i, x)
+#define pl_warning(i, x...) PRINT_RL(LOG_WARNING, i, x)
+#define pl_notice(i, x...) PRINT_RL(LOG_NOTICE, i, x)
+#define pl_info(i, x...) PRINT_RL(LOG_INFO, i, x)
+#define pl_debug(i, x...) PRINT_RL(LOG_DEBUG, i, x)
+
#endif
--
2.1.0
Miroslav Lichvar
2015-09-10 09:49:28 UTC
Permalink
Upgrade the message level to info so the user can see it, but print it
at most once per 5 minutes to not spam the syslog too much.

Signed-off-by: Miroslav Lichvar <***@redhat.com>
---
port.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/port.c b/port.c
index 9c804cf..3f32433 100644
--- a/port.c
+++ b/port.c
@@ -1688,8 +1688,8 @@ static void process_delay_resp(struct port *p, struct ptp_message *m)
}
if (rsp->hdr.logMessageInterval < -10 ||
rsp->hdr.logMessageInterval > 22) {
- pr_debug("port %hu: ignore bogus delay request interval 2^%d",
- portnum(p), rsp->hdr.logMessageInterval);
+ pl_info(300, "port %hu: ignore bogus delay request interval 2^%d",
+ portnum(p), rsp->hdr.logMessageInterval);
return;
}
p->logMinDelayReqInterval = rsp->hdr.logMessageInterval;
--
2.1.0
Richard Cochran
2015-09-11 19:47:40 UTC
Permalink
Post by Miroslav Lichvar
Upgrade the message level to info so the user can see it, but print it
at most once per 5 minutes to not spam the syslog too much.
Series applied.

Thanks,
Richard

------------------------------------------------------------------------------
Loading...