[PATCH libinput] Add log_*_ratelimit wrappers
Peter Hutterer
peter.hutterer at who-t.net
Tue Aug 18 22:26:10 PDT 2015
Don't open-code the rate-limited log messages, use a simple wrapper instead.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
src/evdev.c | 37 ++++++++-----------------------------
src/libinput-private.h | 14 ++++++++++++++
src/libinput.c | 25 +++++++++++++++++++++++++
3 files changed, 47 insertions(+), 29 deletions(-)
diff --git a/src/evdev.c b/src/evdev.c
index 97c007c..303e447 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -647,21 +647,10 @@ evdev_reject_relative(struct evdev_device *device,
if ((e->code == REL_X || e->code == REL_Y) &&
(device->seat_caps & EVDEV_DEVICE_POINTER) == 0) {
- switch (ratelimit_test(&device->nonpointer_rel_limit)) {
- case RATELIMIT_PASS:
- log_bug_libinput(libinput,
- "REL_X/Y from device '%s', but this device is not a pointer\n",
- device->devname);
- break;
- case RATELIMIT_THRESHOLD:
- log_bug_libinput(libinput,
- "REL_X/Y event flood from '%s'\n",
- device->devname);
- break;
- case RATELIMIT_EXCEEDED:
- break;
- }
-
+ log_bug_libinput_ratelimit(libinput,
+ &device->nonpointer_rel_limit,
+ "REL_X/Y from device '%s', but this device is not a pointer\n",
+ device->devname);
return true;
}
@@ -1371,20 +1360,10 @@ evdev_device_dispatch(void *data)
rc = libevdev_next_event(device->evdev,
LIBEVDEV_READ_FLAG_NORMAL, &ev);
if (rc == LIBEVDEV_READ_STATUS_SYNC) {
- switch (ratelimit_test(&device->syn_drop_limit)) {
- case RATELIMIT_PASS:
- log_info(libinput, "SYN_DROPPED event from "
- "\"%s\" - some input events have "
- "been lost.\n", device->devname);
- break;
- case RATELIMIT_THRESHOLD:
- log_info(libinput, "SYN_DROPPED flood "
- "from \"%s\"\n",
- device->devname);
- break;
- case RATELIMIT_EXCEEDED:
- break;
- }
+ log_info_ratelimit(libinput,
+ &device->syn_drop_limit,
+ "SYN_DROPPED event from \"%s\" - some input events have been lost.\n",
+ device->devname);
/* send one more sync event so we handle all
currently pending events before we sync up
diff --git a/src/libinput-private.h b/src/libinput-private.h
index 5d0826d..8b161cc 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -256,6 +256,20 @@ typedef void (*libinput_source_dispatch_t)(void *data);
#define log_bug_libinput(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__)
#define log_bug_client(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__)
+#define log_debug_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__)
+#define log_info_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__)
+#define log_error_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__)
+#define log_bug_kernel_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__)
+#define log_bug_libinput_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__)
+#define log_bug_client_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__)
+
+void
+log_msg_ratelimit(struct libinput *libinput,
+ struct ratelimit *ratelimit,
+ enum libinput_log_priority priority,
+ const char *format, ...)
+ LIBINPUT_ATTRIBUTE_PRINTF(4, 5);
+
void
log_msg(struct libinput *libinput,
enum libinput_log_priority priority,
diff --git a/src/libinput.c b/src/libinput.c
index 4673073..e564571 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -166,6 +166,31 @@ log_msg(struct libinput *libinput,
va_end(args);
}
+void
+log_msg_ratelimit(struct libinput *libinput,
+ struct ratelimit *ratelimit,
+ enum libinput_log_priority priority,
+ const char *format, ...)
+{
+ va_list args;
+ enum ratelimit_state state;
+
+ state = ratelimit_test(ratelimit);
+ if (state == RATELIMIT_EXCEEDED)
+ return;
+
+ va_start(args, format);
+ log_msg_va(libinput, priority, format, args);
+ va_end(args);
+
+ if (state == RATELIMIT_THRESHOLD)
+ log_msg(libinput,
+ priority,
+ "WARNING: log rate limit exceeded (%d msgs per %dms). Discarding future messages.\n",
+ ratelimit->burst,
+ us2ms(ratelimit->interval));
+}
+
LIBINPUT_EXPORT void
libinput_log_set_priority(struct libinput *libinput,
enum libinput_log_priority priority)
--
2.4.3
More information about the wayland-devel
mailing list