improve status reporting

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@39140 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2015-11-04 07:56:16 +00:00
parent 50a8a2ca59
commit 3fefb489fe

View file

@ -70,6 +70,16 @@
@implementation SQLClientPool @implementation SQLClientPool
static Class cls = Nil;
+ (void) initialize
{
if (Nil == cls)
{
cls = [NSAutoreleasePool class];
}
}
- (int) availableConnections - (int) availableConnections
{ {
int available; int available;
@ -665,12 +675,33 @@
{ {
SQLClient *client = _items[index].c; SQLClient *client = _items[index].c;
NSUInteger rc = [client retainCount]; NSUInteger rc = [client retainCount];
NSUInteger uc = _items[index].u;
/* Check to see if this client is free to be taken from the pool. /* Check to see if this client is free to be taken from the pool.
* Also, if a client is connected but not in use, we call it idle. * Also, if a client is connected but not in use, we call it idle.
*/ */
if (_items[index].u > 0) if (uc > 0)
{ {
NSUInteger ac;
NSString *s;
ac = [cls autoreleaseCountForObject: client];
if (NSNotFound == uc)
{
s = [NSString stringWithFormat: @" Client '%@'"
@" provided exclusively (retained:%llu - autoreleased:%llu)",
[client name],
(unsigned long long)rc, (unsigned long long)ac];
}
else
{
s = [NSString stringWithFormat: @" Client '%@'"
@" provided %lld time%s (retained:%llu - autoreleased:%llu)",
[client name],
(unsigned long long)uc, (1 == uc) ? "" : "s",
(unsigned long long)rc, (unsigned long long)ac];
}
/* This is a client which has been provided by the pool, /* This is a client which has been provided by the pool,
* so it is in use by some code. * so it is in use by some code.
*/ */
@ -683,10 +714,8 @@
{ {
liveInfo = [NSMutableArray array]; liveInfo = [NSMutableArray array];
} }
[liveInfo addObject: [NSString stringWithFormat: [liveInfo addObject: [s stringByAppendingFormat:
@" Client '%@' (retain count %"PRIuPTR @" active in transaction since %@\n", d]];
@") active in transaction since %@\n",
[client name], rc, d]];
rc = 0; rc = 0;
} }
else else
@ -709,15 +738,14 @@
{ {
idleInfo = [NSMutableArray array]; idleInfo = [NSMutableArray array];
} }
[idleInfo addObject: [NSString stringWithFormat: [idleInfo addObject: [s stringByAppendingFormat:
@" Client '%@' (retain count %"PRIuPTR @" taken from pool but idle since %@\n", d]];
@") taken from pool but idle since %@\n",
[client name], rc, d]];
rc = 0;
} }
else else
{ {
idle++; idle++;
[idleInfo addObject: [s stringByAppendingFormat:
@" taken from pool and recently used\n"]];
} }
} }
} }
@ -739,18 +767,18 @@
*/ */
dead++; dead++;
} }
} if (rc > 1)
if (rc > 1)
{
if (nil == retainInfo)
{ {
retainInfo = [NSMutableString stringWithCapacity: 100]; if (nil == retainInfo)
{
retainInfo = [NSMutableString stringWithCapacity: 100];
}
[retainInfo appendFormat:
@" Client '%@' (retain count %"PRIuPTR
@") %s pool\n",
[client name], rc,
(_items[index].u > 0) ? "taken from" : "available in"];
} }
[retainInfo appendFormat:
@" Client '%@' (retain count %"PRIuPTR
@") %s pool\n",
[client name], rc,
(_items[index].u > 0) ? "taken from" : "available in"];
} }
} }
@ -909,17 +937,11 @@
#if defined(GNUSTEP) #if defined(GNUSTEP)
if (_debugging > 3) if (_debugging > 3)
{ {
static Class cls = Nil;
NSUInteger rc; NSUInteger rc;
NSUInteger ac; NSUInteger ac;
NSUInteger uc; NSUInteger uc;
int index; int index;
if (Nil == cls)
{
cls = [NSAutoreleasePool class];
}
rc = (unsigned long)[o retainCount]; rc = (unsigned long)[o retainCount];
ac = (unsigned long)[cls autoreleaseCountForObject: o]; ac = (unsigned long)[cls autoreleaseCountForObject: o];
[_lock lock]; [_lock lock];
@ -942,8 +964,8 @@
else else
{ {
return [NSString stringWithFormat: return [NSString stringWithFormat:
@" provided %lld times (retained:%llu - autoreleased:%llu)", @" provided %lld time%s (retained:%llu - autoreleased:%llu)",
(unsigned long long)uc, (unsigned long long)uc, (1 == uc) ? "" : "s",
(unsigned long long)rc, (unsigned long long)ac]; (unsigned long long)rc, (unsigned long long)ac];
} }
} }