speed up logging a bit

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38793 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2015-07-14 18:51:30 +00:00
parent 78fd39fcd1
commit 136b8c8f49
2 changed files with 32 additions and 22 deletions

View file

@ -6,6 +6,7 @@
Stefan Bidigaray pointed out that the heading we currently write is Stefan Bidigaray pointed out that the heading we currently write is
very out of date. very out of date.
* Source/NSThread.m: On premature thread exist, log native thread ID. * Source/NSThread.m: On premature thread exist, log native thread ID.
* Source/NSLog.m: Optimisations to make logging a little quicker.
2015-07-09 Richard Frith-Macdonald <rfm@gnu.org> 2015-07-09 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -87,6 +87,8 @@ extern NSThread *GSCurrentThread();
int _NSLogDescriptor = 2; int _NSLogDescriptor = 2;
static NSRecursiveLock *myLock = nil; static NSRecursiveLock *myLock = nil;
static IMP lockImp = 0;
static IMP unlockImp = 0;
/** /**
* Returns the lock used to protect the GNUstep NSLogv() implementation. * Returns the lock used to protect the GNUstep NSLogv() implementation.
@ -103,6 +105,8 @@ GSLogLock()
if (myLock == nil) if (myLock == nil)
{ {
myLock = [NSRecursiveLock new]; myLock = [NSRecursiveLock new];
lockImp = [myLock methodForSelector: @selector(lock)];
unlockImp = [myLock methodForSelector: @selector(unlock)];
} }
[gnustep_global_lock unlock]; [gnustep_global_lock unlock];
} }
@ -330,8 +334,8 @@ NSLogv(NSString* format, va_list args)
NSMutableString *prefix; NSMutableString *prefix;
NSString *message; NSString *message;
NSString *threadName = nil; NSString *threadName = nil;
NSThread *t = nil;
static int pid = 0; static int pid = 0;
NSAutoreleasePool *arp = [NSAutoreleasePool new];
if (_NSLog_printf_handler == NULL) if (_NSLog_printf_handler == NULL)
{ {
@ -349,33 +353,33 @@ NSLogv(NSString* format, va_list args)
if (GSPrivateDefaultsFlag(GSLogThread) == YES) if (GSPrivateDefaultsFlag(GSLogThread) == YES)
{ {
NSThread *t = GSCurrentThread(); /* If no name has been set for the current thread,
* we log the address of the NSThread object instead.
threadName = [t name];
/* If no name has been set for the current thread, we log the address
* of the NSThread object instead.
*/ */
if ([threadName length] == 0) t = GSCurrentThread();
{ threadName = [t name];
threadName = [NSString stringWithFormat: @"%p", t];
}
} }
prefix = [NSMutableString stringWithCapacity: 1000]; prefix = [[NSMutableString alloc] initWithCapacity: 1000];
#ifdef HAVE_SYSLOG #ifdef HAVE_SYSLOG
if (GSPrivateDefaultsFlag(GSLogSyslog) == YES) if (GSPrivateDefaultsFlag(GSLogSyslog) == YES)
{ {
if (nil != threadName) if (nil == t)
{
[prefix appendFormat: @"[thread:%"PRIuPTR",%@] ",
GSPrivateThreadID(), threadName];
}
else
{ {
[prefix appendFormat: @"[thread:%"PRIuPTR"] ", [prefix appendFormat: @"[thread:%"PRIuPTR"] ",
GSPrivateThreadID()]; GSPrivateThreadID()];
} }
else if (nil == threadName)
{
[prefix appendFormat: @"[thread:%"PRIuPTR",%p] ",
GSPrivateThreadID(), t];
}
else
{
[prefix appendFormat: @"[thread:%"PRIuPTR",%@] ",
GSPrivateThreadID(), threadName];
}
} }
else else
#endif #endif
@ -396,11 +400,16 @@ NSLogv(NSString* format, va_list args)
[prefix appendString: cal]; [prefix appendString: cal];
[prefix appendString: @" "]; [prefix appendString: @" "];
[prefix appendString: [[NSProcessInfo processInfo] processName]]; [prefix appendString: [[NSProcessInfo processInfo] processName]];
if (nil == threadName) if (nil == t)
{ {
[prefix appendFormat: @"[%d:%"PRIuPTR"] ", [prefix appendFormat: @"[%d:%"PRIuPTR"] ",
pid, GSPrivateThreadID()]; pid, GSPrivateThreadID()];
} }
else if (nil == threadName)
{
[prefix appendFormat: @"[%d:%"PRIuPTR",%p] ",
pid, GSPrivateThreadID(), t];
}
else else
{ {
[prefix appendFormat: @"[%d:%"PRIuPTR",%@] ", [prefix appendFormat: @"[%d:%"PRIuPTR",%@] ",
@ -416,17 +425,17 @@ NSLogv(NSString* format, va_list args)
[prefix appendString: @"\n"]; [prefix appendString: @"\n"];
} }
if (myLock == nil) if (nil == myLock)
{ {
GSLogLock(); GSLogLock();
} }
[myLock lock]; (*lockImp)(myLock, @selector(lock));
_NSLog_printf_handler(prefix); _NSLog_printf_handler(prefix);
[myLock unlock]; (*lockImp)(myLock, @selector(unlock));
[arp drain]; [prefix release];
} }