[systemd-devel] [PATCH] ratelimit: removed n_printed

harald at redhat.com harald at redhat.com
Mon Feb 21 06:32:18 PST 2011


From: Harald Hoyer <harald at redhat.com>

Removed n_printed and renamed n_printed to num.
This is not a logging rate limiter anymore.
---
 src/ratelimit.c |   14 ++++----------
 src/ratelimit.h |    8 +++-----
 2 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/src/ratelimit.c b/src/ratelimit.c
index 5adf1ae..1ddc831 100644
--- a/src/ratelimit.c
+++ b/src/ratelimit.c
@@ -38,25 +38,19 @@ bool ratelimit_test(RateLimit *r) {
 
         if (r->begin <= 0 ||
             r->begin + r->interval < ts) {
-
-                if (r->n_missed > 0)
-                        log_warning("%u events suppressed", r->n_missed);
-
                 r->begin = ts;
 
-                /* Reset counters */
-                r->n_printed = 0;
-                r->n_missed = 0;
+                /* Reset counter */
+                r->num = 0;
                 goto good;
         }
 
-        if (r->n_printed <= r->burst)
+        if (r->num <= r->burst)
                 goto good;
 
-        r->n_missed++;
         return false;
 
 good:
-        r->n_printed++;
+        r->num++;
         return true;
 }
diff --git a/src/ratelimit.h b/src/ratelimit.h
index 2c77787..a44ef70 100644
--- a/src/ratelimit.h
+++ b/src/ratelimit.h
@@ -28,15 +28,14 @@ typedef struct RateLimit {
         usec_t interval;
         usec_t begin;
         unsigned burst;
-        unsigned n_printed, n_missed;
+        unsigned num;
 } RateLimit;
 
 #define RATELIMIT_DEFINE(_name, _interval, _burst)       \
         RateLimit _name = {                              \
                 .interval = (_interval),                 \
                 .burst = (_burst),                       \
-                .n_printed = 0,                          \
-                .n_missed = 0,                           \
+                .num = 0,                                \
                 .begin = 0                               \
         }
 
@@ -45,8 +44,7 @@ typedef struct RateLimit {
                 RateLimit *_r = &(v);                    \
                 _r->interval = (_interval);              \
                 _r->burst = (_burst);                    \
-                _r->n_printed = 0;                       \
-                _r->n_missed = 0;                        \
+                _r->num = 0;                             \
                 _r->begin = 0;                           \
         } while (false);
 
-- 
1.7.3.4



More information about the systemd-devel mailing list