From 1250b5d735129c3e04c45484f80f99cdb12f39a1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 22 Jan 2011 01:08:36 +0100 Subject: ratelimit: fix log levels of log suppression messages When logging a suppression message do so on the same log level as the suppressed messages. Cherry picked by Colin Guthrie from ec5a7857127a1b3b9c5517c4a70a9b2c8aab35ca with a couple of additional changes due to extra limiting in master that was not present in stable-queue. --- src/pulsecore/asyncq.c | 2 +- src/pulsecore/flist.c | 2 +- src/pulsecore/log.c | 4 ++-- src/pulsecore/log.h | 2 +- src/pulsecore/memblock.c | 2 +- src/pulsecore/protocol-native.c | 2 +- src/pulsecore/pstream.c | 2 +- src/pulsecore/ratelimit.c | 4 ++-- src/pulsecore/ratelimit.h | 3 ++- src/pulsecore/sink.c | 2 +- 10 files changed, 13 insertions(+), 12 deletions(-) (limited to 'src/pulsecore') diff --git a/src/pulsecore/asyncq.c b/src/pulsecore/asyncq.c index 072ef02c..e62d0c16 100644 --- a/src/pulsecore/asyncq.c +++ b/src/pulsecore/asyncq.c @@ -206,7 +206,7 @@ void pa_asyncq_post(pa_asyncq*l, void *p) { /* OK, we couldn't push anything in the queue. So let's queue it * locally and push it later */ - if (pa_log_ratelimit()) + if (pa_log_ratelimit(PA_LOG_WARN)) pa_log_warn("q overrun, queuing locally"); if (!(q = pa_flist_pop(PA_STATIC_FLIST_GET(localq)))) diff --git a/src/pulsecore/flist.c b/src/pulsecore/flist.c index 23af5dd4..e342a579 100644 --- a/src/pulsecore/flist.c +++ b/src/pulsecore/flist.c @@ -124,7 +124,7 @@ int pa_flist_push(pa_flist *l, void *p) { elem = stack_pop(&l->empty); if (elem == NULL) { - if (pa_log_ratelimit()) + if (pa_log_ratelimit(PA_LOG_DEBUG)) pa_log_debug("%s flist is full (don't worry)", l->name); return -1; } diff --git a/src/pulsecore/log.c b/src/pulsecore/log.c index 0c5a317c..7ba41ee9 100644 --- a/src/pulsecore/log.c +++ b/src/pulsecore/log.c @@ -431,7 +431,7 @@ void pa_log_level(pa_log_level_t level, const char *format, ...) { va_end(ap); } -pa_bool_t pa_log_ratelimit(void) { +pa_bool_t pa_log_ratelimit(pa_log_level_t level) { /* Not more than 10 messages every 5s */ static PA_DEFINE_RATELIMIT(ratelimit, 5 * PA_USEC_PER_SEC, 10); @@ -440,5 +440,5 @@ pa_bool_t pa_log_ratelimit(void) { if (no_rate_limit) return TRUE; - return pa_ratelimit_test(&ratelimit); + return pa_ratelimit_test(&ratelimit, level); } diff --git a/src/pulsecore/log.h b/src/pulsecore/log.h index 2f379f68..1fd38d44 100644 --- a/src/pulsecore/log.h +++ b/src/pulsecore/log.h @@ -135,6 +135,6 @@ LOG_FUNC(error, PA_LOG_ERROR) #define pa_log pa_log_error -pa_bool_t pa_log_ratelimit(void); +pa_bool_t pa_log_ratelimit(pa_log_level_t level); #endif diff --git a/src/pulsecore/memblock.c b/src/pulsecore/memblock.c index f38b17c6..454900d1 100644 --- a/src/pulsecore/memblock.c +++ b/src/pulsecore/memblock.c @@ -258,7 +258,7 @@ static struct mempool_slot* mempool_allocate_slot(pa_mempool *p) { slot = (struct mempool_slot*) ((uint8_t*) p->memory.ptr + (p->block_size * (size_t) idx)); if (!slot) { - if (pa_log_ratelimit()) + if (pa_log_ratelimit(PA_LOG_DEBUG)) pa_log_debug("Pool full"); pa_atomic_inc(&p->stat.n_pool_full); return NULL; diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c index 85245a93..3943e83e 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -1385,7 +1385,7 @@ static int sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int if (pa_memblockq_push_align(s->memblockq, chunk) < 0) { - if (pa_log_ratelimit()) + if (pa_log_ratelimit(PA_LOG_WARN)) pa_log_warn("Failed to push data into queue"); pa_asyncmsgq_post(pa_thread_mq_get()->outq, PA_MSGOBJECT(s), PLAYBACK_STREAM_MESSAGE_OVERFLOW, NULL, 0, NULL, NULL); pa_memblockq_seek(s->memblockq, (int64_t) chunk->length, PA_SEEK_RELATIVE, TRUE); diff --git a/src/pulsecore/pstream.c b/src/pulsecore/pstream.c index 1d4ac177..3e0bfa3b 100644 --- a/src/pulsecore/pstream.c +++ b/src/pulsecore/pstream.c @@ -832,7 +832,7 @@ static int do_read(pa_pstream *p) { ntohl(p->read.shm_info[PA_PSTREAM_SHM_INDEX]), ntohl(p->read.shm_info[PA_PSTREAM_SHM_LENGTH])))) { - if (pa_log_ratelimit()) + if (pa_log_ratelimit(PA_LOG_DEBUG)) pa_log_debug("Failed to import memory block."); } diff --git a/src/pulsecore/ratelimit.c b/src/pulsecore/ratelimit.c index 844dd77d..a274d2cc 100644 --- a/src/pulsecore/ratelimit.c +++ b/src/pulsecore/ratelimit.c @@ -35,7 +35,7 @@ static pa_static_mutex mutex = PA_STATIC_MUTEX_INIT; /* Modelled after Linux' lib/ratelimit.c by Dave Young * , which is licensed GPLv2. */ -pa_bool_t pa_ratelimit_test(pa_ratelimit *r) { +pa_bool_t pa_ratelimit_test(pa_ratelimit *r, pa_log_level_t t) { pa_usec_t now; pa_mutex *m; @@ -52,7 +52,7 @@ pa_bool_t pa_ratelimit_test(pa_ratelimit *r) { r->begin + r->interval < now) { if (r->n_missed > 0) - pa_log_warn("%u events suppressed", r->n_missed); + pa_logl(t, "%u events suppressed", r->n_missed); r->begin = now; diff --git a/src/pulsecore/ratelimit.h b/src/pulsecore/ratelimit.h index 9857a291..9a36195d 100644 --- a/src/pulsecore/ratelimit.h +++ b/src/pulsecore/ratelimit.h @@ -23,6 +23,7 @@ ***/ #include +#include #include typedef struct pa_ratelimit { @@ -51,6 +52,6 @@ typedef struct pa_ratelimit { r->begin = 0; \ } while (FALSE); -pa_bool_t pa_ratelimit_test(pa_ratelimit *r); +pa_bool_t pa_ratelimit_test(pa_ratelimit *r, pa_log_level_t t); #endif diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index 3cadbff6..62000e0d 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -2989,7 +2989,7 @@ pa_bool_t pa_sink_volume_change_apply(pa_sink *s, pa_usec_t *usec_to_next) { if (s->thread_info.volume_changes) { if (usec_to_next) *usec_to_next = s->thread_info.volume_changes->at - now; - if (pa_log_ratelimit()) + if (pa_log_ratelimit(PA_LOG_DEBUG)) pa_log_debug("Next volume change in %lld usec", s->thread_info.volume_changes->at - now); } else { -- cgit