Keep track of maximum number of events in-flight in the SDL queue at once.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index 963b9bd..cfbdcf8 100644
--- a/src/events/SDL_events.c
+++ b/src/events/SDL_events.c
@@ -75,12 +75,13 @@ static struct
SDL_mutex *lock;
volatile SDL_bool active;
volatile int count;
+ volatile int max_events_seen;
SDL_EventEntry *head;
SDL_EventEntry *tail;
SDL_EventEntry *free;
SDL_SysWMEntry *wmmsg_used;
SDL_SysWMEntry *wmmsg_free;
-} SDL_EventQ = { NULL, SDL_TRUE };
+} SDL_EventQ = { NULL, SDL_TRUE, 0, 0, NULL, NULL, NULL, NULL, NULL };
/* Public functions */
@@ -88,6 +89,7 @@ static struct
void
SDL_StopEventLoop(void)
{
+ const char *report = SDL_GetHint("SDL_EVENT_QUEUE_STATISTICS");
int i;
SDL_EventEntry *entry;
SDL_SysWMEntry *wmmsg;
@@ -98,6 +100,11 @@ SDL_StopEventLoop(void)
SDL_EventQ.active = SDL_FALSE;
+ if (report && SDL_atoi(report)) {
+ SDL_Log("SDL EVENT QUEUE: Maximum events in-flight: %d\n",
+ SDL_EventQ.max_events_seen);
+ }
+
/* Clean out EventQ */
for (entry = SDL_EventQ.head; entry; ) {
SDL_EventEntry *next = entry->next;
@@ -119,7 +126,9 @@ SDL_StopEventLoop(void)
SDL_free(wmmsg);
wmmsg = next;
}
+
SDL_EventQ.count = 0;
+ SDL_EventQ.max_events_seen = 0;
SDL_EventQ.head = NULL;
SDL_EventQ.tail = NULL;
SDL_EventQ.free = NULL;
@@ -218,6 +227,10 @@ SDL_AddEvent(SDL_Event * event)
}
++SDL_EventQ.count;
+ if (SDL_EventQ.count > SDL_EventQ.max_events_seen) {
+ SDL_EventQ.max_events_seen = SDL_EventQ.count;
+ }
+
return 1;
}