summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Sweeney <asweeney86@gmail.com>2013-12-30 14:06:20 -0500
committerAndrew Sweeney <asweeney86@gmail.com>2013-12-30 14:06:20 -0500
commit5173bef50ff8ff389598c8d9301a7b77ffae8315 (patch)
tree51efafc2bce63fffb0843275a70c48dd26a9bf6c
parentccf432b91201afb61b1b015724bcb50245a36eec (diff)
downloadlibevent-5173bef50ff8ff389598c8d9301a7b77ffae8315.tar.gz
Add access to max event count stats
This commit provides an interface for accessing and resetting the maximum number of events in a given period. This information provides better insight into event queue pressure.
-rw-r--r--event-internal.h6
-rw-r--r--event.c46
-rw-r--r--include/event2/event.h12
3 files changed, 62 insertions, 2 deletions
diff --git a/event-internal.h b/event-internal.h
index bce96df5..5208fbe0 100644
--- a/event-internal.h
+++ b/event-internal.h
@@ -224,10 +224,16 @@ struct event_base {
/** Number of virtual events */
int virtual_event_count;
+ /** Maximum number of virtual events active */
+ int virtual_event_count_max;
/** Number of total events added to this event_base */
int event_count;
+ /** Maximum number of total events added to this event_base */
+ int event_count_max;
/** Number of total events active in this event_base */
int event_count_active;
+ /** Maximum number of total events active in this event_base */
+ int event_count_active_max;
/** Set if we should terminate the loop once we're done processing
* events. */
diff --git a/event.c b/event.c
index e50616c4..3f6dd585 100644
--- a/event.c
+++ b/event.c
@@ -1204,6 +1204,36 @@ event_base_get_num_events(struct event_base *base, unsigned int type)
return r;
}
+int
+event_base_get_max_events(struct event_base *base, unsigned int type, int clear)
+{
+ int r = 0;
+
+ EVBASE_ACQUIRE_LOCK(base, th_base_lock);
+
+ if (type & EVENT_BASE_COUNT_ACTIVE) {
+ r += base->event_count_active_max;
+ if (clear)
+ base->event_count_active_max = 0;
+ }
+
+ if (type & EVENT_BASE_COUNT_VIRTUAL) {
+ r += base->virtual_event_count_max;
+ if (clear)
+ base->virtual_event_count_max = 0;
+ }
+
+ if (type & EVENT_BASE_COUNT_ADDED) {
+ r += base->event_count_max;
+ if (clear)
+ base->event_count_max = 0;
+ }
+
+ EVBASE_RELEASE_LOCK(base, th_base_lock);
+
+ return r;
+}
+
/* Returns true iff we're currently watching any events. */
static int
event_haveevents(struct event_base *base)
@@ -3026,14 +3056,23 @@ timeout_process(struct event_base *base)
#if (EVLIST_INTERNAL >> 4) != 1
#error "Mismatch for value of EVLIST_INTERNAL"
#endif
+
+#ifndef MAX
+#define MAX(a,b) (((a)>(b))?(a):(b))
+#endif
+
+#define MAX_EVENT_COUNT(var, v) var = MAX(var, v)
+
/* These are a fancy way to spell
if (flags & EVLIST_INTERNAL)
base->event_count--/++;
*/
#define DECR_EVENT_COUNT(base,flags) \
((base)->event_count -= (~((flags) >> 4) & 1))
-#define INCR_EVENT_COUNT(base,flags) \
- ((base)->event_count += (~((flags) >> 4) & 1))
+#define INCR_EVENT_COUNT(base,flags) do { \
+ ((base)->event_count += (~((flags) >> 4) & 1)); \
+ MAX_EVENT_COUNT((base)->event_count_max, (base)->event_count_max); \
+} while (0)
static void
event_queue_remove_inserted(struct event_base *base, struct event *ev)
@@ -3203,6 +3242,7 @@ event_queue_insert_active(struct event_base *base, struct event_callback *evcb)
evcb->evcb_flags |= EVLIST_ACTIVE;
base->event_count_active++;
+ MAX_EVENT_COUNT(base->event_count_active_max, base->event_count_active);
EVUTIL_ASSERT(evcb->evcb_pri < base->nactivequeues);
TAILQ_INSERT_TAIL(&base->activequeues[evcb->evcb_pri],
evcb, evcb_active_next);
@@ -3220,6 +3260,7 @@ event_queue_insert_active_later(struct event_base *base, struct event_callback *
INCR_EVENT_COUNT(base, evcb->evcb_flags);
evcb->evcb_flags |= EVLIST_ACTIVE_LATER;
base->event_count_active++;
+ MAX_EVENT_COUNT(base->event_count_active_max, base->event_count_active);
EVUTIL_ASSERT(evcb->evcb_pri < base->nactivequeues);
TAILQ_INSERT_TAIL(&base->active_later_queue, evcb, evcb_active_next);
}
@@ -3637,6 +3678,7 @@ event_base_add_virtual_(struct event_base *base)
{
EVBASE_ACQUIRE_LOCK(base, th_base_lock);
base->virtual_event_count++;
+ MAX_EVENT_COUNT(base->virtual_event_count_max, base->virtual_event_count);
EVBASE_RELEASE_LOCK(base, th_base_lock);
}
diff --git a/include/event2/event.h b/include/event2/event.h
index 986c009c..5e7044ad 100644
--- a/include/event2/event.h
+++ b/include/event2/event.h
@@ -425,6 +425,18 @@ const char **event_get_supported_methods(void);
int event_base_get_num_events(struct event_base *, unsigned int);
/**
+ Get the maximum number of events in a given event_base as specified in the
+ flags.
+
+ @param eb the event_base structure returned by event_base_new()
+ @param flags a bitwise combination of the kinds of events to aggregate
+ counts for
+ @param clear option used to reset the maximum count.
+ @return the number of events specified in the flags
+ */
+int event_base_get_max_events(struct event_base *, unsigned int, int);
+
+/**
Allocates a new event configuration object.
The event configuration object can be used to change the behavior of