mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-02-04 14:00:29 +01:00
Add log_*_ratelimit wrappers
Don't open-code the rate-limited log messages, use a simple wrapper instead. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
parent
2e7a585faa
commit
b88fd37593
3 changed files with 47 additions and 29 deletions
37
src/evdev.c
37
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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue