diff --git a/ChangeLog b/ChangeLog index 500a7435c..927332d6f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-09-07 Richard Frith-Macdonald + + * Source/NSRunLoop.m: + * Source/GSRunLoopCtxt.h: + Add some logging to help debug problems where code is adding too + many events into a run loop. + 2009-09-06 Richard Frith-Macdonald * Source/NSLock.m: Fix the ([-tryLock]) and [(-lockBeforeDate:]) diff --git a/Source/GSRunLoopCtxt.h b/Source/GSRunLoopCtxt.h index 76ffe362f..091c9859e 100644 --- a/Source/GSRunLoopCtxt.h +++ b/Source/GSRunLoopCtxt.h @@ -62,8 +62,11 @@ typedef struct{ void *extra; /** Copy of the RunLoop ivar. */ NSString *mode; /** The mode for this context. */ GSIArray performers; /** The actions to perform regularly. */ + unsigned maxPerformers; GSIArray timers; /** The timers set for the runloop mode */ + unsigned maxTimers; GSIArray watchers; /** The inputs set for the runloop mode */ + unsigned maxWatchers; NSTimer *housekeeper; /** Housekeeping timer for loop. */ @private #if defined(__MINGW32__) diff --git a/Source/NSRunLoop.m b/Source/NSRunLoop.m index f7255b8e1..5e461e692 100644 --- a/Source/NSRunLoop.m +++ b/Source/NSRunLoop.m @@ -405,6 +405,7 @@ static inline BOOL timerInvalidated(NSTimer *t) { GSRunLoopCtxt *context; GSIArray watchers; + unsigned i; context = NSMapGet(_contextMap, mode); if (context == nil) @@ -415,6 +416,13 @@ static inline BOOL timerInvalidated(NSTimer *t) } watchers = context->watchers; GSIArrayAddItem(watchers, (GSIArrayItem)((id)item)); + i = GSIArrayCount(watchers); + if (i % 1000 == 0 && i > context->maxWatchers) + { + context->maxWatchers = i; + NSLog(@"WARNING ... there are %u watchers scheduled in mode %@ of %@", + i, mode, self); + } } - (void) _checkPerformers: (GSRunLoopCtxt*)context @@ -840,6 +848,13 @@ static inline BOOL timerInvalidated(NSTimer *t) * all each time -limitDateForMode: is called. */ GSIArrayAddItem(timers, (GSIArrayItem)((id)timer)); + i = GSIArrayCount(timers); + if (i % 1000 == 0 && i > context->maxTimers) + { + context->maxTimers = i; + NSLog(@"WARNING ... there are %u timers scheduled in mode %@ of %@", + i, mode, self); + } } @@ -1484,6 +1499,13 @@ static inline BOOL timerInvalidated(NSTimer *t) { GSIArrayInsertItem(performers, (GSIArrayItem)((id)item), i); } + i = GSIArrayCount(performers); + if (i % 1000 == 0 && i > context->maxPerformers) + { + context->maxPerformers = i; + NSLog(@"WARNING ... there are %u performers scheduled" + @" in mode %@ of %@", i, mode, self); + } } RELEASE(item); }