Keep track of maximum number of events in-flight in the SDL queue at once.
authorRyan C. Gordon
Wed, 25 Mar 2015 10:19:10 -0400
changeset 9437569cfb86df95
parent 9436 0af69dab9bb6
child 9438 fff5af5de6dd
Keep track of maximum number of events in-flight in the SDL queue at once.
src/events/SDL_events.c
     1.1 --- a/src/events/SDL_events.c	Tue Mar 24 14:40:31 2015 -0400
     1.2 +++ b/src/events/SDL_events.c	Wed Mar 25 10:19:10 2015 -0400
     1.3 @@ -75,12 +75,13 @@
     1.4      SDL_mutex *lock;
     1.5      volatile SDL_bool active;
     1.6      volatile int count;
     1.7 +    volatile int max_events_seen;
     1.8      SDL_EventEntry *head;
     1.9      SDL_EventEntry *tail;
    1.10      SDL_EventEntry *free;
    1.11      SDL_SysWMEntry *wmmsg_used;
    1.12      SDL_SysWMEntry *wmmsg_free;
    1.13 -} SDL_EventQ = { NULL, SDL_TRUE };
    1.14 +} SDL_EventQ = { NULL, SDL_TRUE, 0, 0, NULL, NULL, NULL, NULL, NULL };
    1.15  
    1.16  
    1.17  /* Public functions */
    1.18 @@ -88,6 +89,7 @@
    1.19  void
    1.20  SDL_StopEventLoop(void)
    1.21  {
    1.22 +    const char *report = SDL_GetHint("SDL_EVENT_QUEUE_STATISTICS");
    1.23      int i;
    1.24      SDL_EventEntry *entry;
    1.25      SDL_SysWMEntry *wmmsg;
    1.26 @@ -98,6 +100,11 @@
    1.27  
    1.28      SDL_EventQ.active = SDL_FALSE;
    1.29  
    1.30 +    if (report && SDL_atoi(report)) {
    1.31 +        SDL_Log("SDL EVENT QUEUE: Maximum events in-flight: %d\n",
    1.32 +                SDL_EventQ.max_events_seen);
    1.33 +    }
    1.34 +
    1.35      /* Clean out EventQ */
    1.36      for (entry = SDL_EventQ.head; entry; ) {
    1.37          SDL_EventEntry *next = entry->next;
    1.38 @@ -119,7 +126,9 @@
    1.39          SDL_free(wmmsg);
    1.40          wmmsg = next;
    1.41      }
    1.42 +
    1.43      SDL_EventQ.count = 0;
    1.44 +    SDL_EventQ.max_events_seen = 0;
    1.45      SDL_EventQ.head = NULL;
    1.46      SDL_EventQ.tail = NULL;
    1.47      SDL_EventQ.free = NULL;
    1.48 @@ -218,6 +227,10 @@
    1.49      }
    1.50      ++SDL_EventQ.count;
    1.51  
    1.52 +    if (SDL_EventQ.count > SDL_EventQ.max_events_seen) {
    1.53 +        SDL_EventQ.max_events_seen = SDL_EventQ.count;
    1.54 +    }
    1.55 +
    1.56      return 1;
    1.57  }
    1.58