From 0c664e3100ac2df2cff65497c727899cbe6b31dd Mon Sep 17 00:00:00 2001 From: rfm Date: Thu, 23 Sep 2010 15:39:47 +0000 Subject: [PATCH] add some diagnostics git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/performance/trunk@31400 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++++ GSThreadPool.h | 7 ++++++- GSThreadPool.m | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index dd54514..28c59e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-09-23 Richard Frith-Macdonald + + * performance/GSThreadPool.h: + * performance/GSThreadPool.m: + Track count of active threads and count of number of methods + performed in the thread pool. Display via -description. + 2010-09-22 Richard Frith-Macdonald * GSLinkedList.h: diff --git a/GSThreadPool.h b/GSThreadPool.h index b3d7ef1..3ebd76f 100644 --- a/GSThreadPool.h +++ b/GSThreadPool.h @@ -42,6 +42,7 @@ BOOL suspended; NSUInteger maxThreads; NSUInteger threadCount; + NSUInteger activeCount; GSThreadLink *idle; GSThreadLink *live; NSUInteger maxOperations; @@ -50,6 +51,7 @@ GSOperation *lastOperation; NSUInteger unusedCount; GSOperation *unused; + NSUInteger processed; } /** Waits until the pool of operations is empty or until the specified @@ -91,7 +93,10 @@ * You may add an object more than once, but that may result in the operation * being performed simultaneously in more than one thread.
* If the pool is configured with zero threads or zero operations, - * this method will simply perform the operation immediately. + * this method will simply perform the operation immediately.
+ * The operation will be performed in a context where there is an exception + * handler set to trap exceptions, and an autorelease pool to deal with + * autoreleased objects. */ - (void) scheduleSelector: (SEL)aSelector onReceiver: (NSObject*)aReceiver diff --git a/GSThreadPool.m b/GSThreadPool.m index 5f8b93f..f49b7ac 100644 --- a/GSThreadPool.m +++ b/GSThreadPool.m @@ -93,6 +93,19 @@ [super dealloc]; } +- (NSString*) description +{ + NSString *result; + + [poolLock lock]; + result = [NSString stringWithFormat: + @"%@ queue: %u(%u) threads: %u(%u) active: %u processed: %u", + [super description], operationCount, maxOperations, + threadCount, maxThreads, activeCount, processed]; + [poolLock unlock]; + return result; +} + - (BOOL) drain: (NSDate*)before { BOOL result = [self isEmpty]; @@ -220,8 +233,26 @@ } else { + NSAutoreleasePool *arp; + [poolLock unlock]; - [aReceiver performSelector: aSelector withObject: anArgument]; + + NS_DURING + { + arp = [NSAutoreleasePool new]; + [aReceiver performSelector: aSelector withObject: anArgument]; + [arp release]; + } + NS_HANDLER + { + arp = [NSAutoreleasePool new]; + NSLog(@"[%@-%@] %@", + NSStringFromClass([aReceiver class]), + NSStringFromSelector(aSelector), + localException); + [arp release]; + } + NS_ENDHANDLER } } @@ -322,6 +353,7 @@ idle = [link remove]; [live insert: link]; live = link; + activeCount++; link->op = op; [link->lock lock]; [link->lock unlockWithCondition: 1]; @@ -379,6 +411,7 @@ { [link remove]; } + activeCount--; if (threadCount > maxThreads) { threadCount--; @@ -403,6 +436,7 @@ BOOL more = NO; [poolLock lock]; + processed++; if (unusedCount < maxOperations) { if (nil != op->arg)