mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-24 17:28:59 +00:00
Performance improvements when debug enabled
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3888 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e51cc0780e
commit
d50d93ac9a
5 changed files with 145 additions and 77 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
Wed Mar 10 09:54:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/FastMap.x: FastMapNodeForKey() - special case for empty map
|
||||
return 0 immediately. Fast for empty maps, marginally slower othrwise.
|
||||
* Source/NSProcessInfo.m: Removed [-debugArray], Added [-debugSet],
|
||||
Added GSDebugSet() function for rapid debug level testing.
|
||||
* Source/include/NSProcessInfo.h: Remove [-debugArray], Add [-debugSet]
|
||||
* Source/include/NSDebug.h: Rewrite NSDebugLog() and NSDebugLLog() to
|
||||
be much more efficient - now minimal performance impact.
|
||||
|
||||
1999-03-09 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Source/include/NSObjCRuntime.h: Define some OpenStep cpp vars.
|
||||
|
|
|
@ -67,23 +67,38 @@ extern const char* GSDebugAllocationList(BOOL changeFlag);
|
|||
/* Debug logging which can be enabled/disabled by defining DEBUG
|
||||
when compiling and also setting values in the mutable array
|
||||
that is set up by NSProcessInfo.
|
||||
This array is initialised by NSProcess info using the
|
||||
'--GNU-Debug=...' command line argument. Each command-line argument
|
||||
of that form is removed from NSProcessInfos list of arguments and the
|
||||
variable part (...) is added to the array.
|
||||
|
||||
NB. The 'debug=yes' option is understood by the GNUstep make package
|
||||
to mean that DEBUG should be defined, so you don't need to go editing
|
||||
your makefiles to do it.
|
||||
|
||||
NSProcess initialises a set of strings that are the names of active
|
||||
debug levels using the '--GNU-Debug=...' command line argument.
|
||||
Each command-line argument of that form is removed from NSProcessInfos
|
||||
list of arguments and the variable part (...) is added to the set.
|
||||
|
||||
For instance, to debug the NSBundle class, run your program with
|
||||
'--GNU-Debug=NSBundle'
|
||||
You can of course supply multiple '--GNU-Debug=...' arguments to
|
||||
output debug information on more than one thing.
|
||||
|
||||
To embed debug logging in your code you use the NSDebugLLog() or
|
||||
NSDebugLog() macro. NSDebugLog() is just NSDebugLLog() with the debug
|
||||
level set to 'dflt'. So, to activate debug statements that use
|
||||
NSDebugLog(), you supply the '--GNU-Debug=dflt' argument to your program.
|
||||
|
||||
You can also change the active debug levels under your programs control -
|
||||
NSProcessInfo has a [-debugSet] method that returns the mutable set that
|
||||
contains the active debug levels - your program can modify this set.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSObjCRuntime.h>
|
||||
#include <Foundation/NSProcessInfo.h>
|
||||
#define NSDebugLLog(level, format, args...) \
|
||||
do { if ([[[NSProcessInfo processInfo] debugArray] containsObject: level]) \
|
||||
do { if (GSDebugSet(level) == YES) \
|
||||
NSLog(format, ## args); } while (0)
|
||||
#define NSDebugLog(format, args...) \
|
||||
do { if ([[[NSProcessInfo processInfo] debugArray] containsObject: @"dflt"]) \
|
||||
do { if (GSDebugSet(@"dflt") == YES) \
|
||||
NSLog(format, ## args); } while (0)
|
||||
#else
|
||||
#define NSDebugLLog(level, format, args...)
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
@class NSMutableArray;
|
||||
@class NSDictionary;
|
||||
@class NSData;
|
||||
@class NSMutableSet;
|
||||
|
||||
@interface NSProcessInfo: NSObject
|
||||
|
||||
|
@ -48,10 +49,22 @@
|
|||
/* Specifying a Process Name */
|
||||
- (void)setProcessName:(NSString *)newName;
|
||||
|
||||
/* GNUstep extension this is a list of debug levels set using the
|
||||
* --GNU-Debug=... command line option. */
|
||||
- (NSMutableArray*) debugArray;
|
||||
|
||||
@end
|
||||
|
||||
#ifndef NO_GNUSTEP
|
||||
|
||||
@interface NSProcessInfo (GNUstep)
|
||||
/* This method returns a set of debug levels set using the
|
||||
* --GNU-Debug=... command line option. */
|
||||
- (NSMutableSet*) debugSet;
|
||||
@end
|
||||
|
||||
/*
|
||||
* This function determines if the specified debug level is present in the
|
||||
* set of active debug levels.
|
||||
*/
|
||||
extern BOOL GSDebugSet(NSString *level);
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* __NSProcessInfo_h_GNUSTEP_BASE_INCLUDE */
|
||||
|
|
|
@ -392,6 +392,8 @@ FastMapNodeForKey(FastMapTable map, FastMapItem key)
|
|||
FastMapBucket bucket;
|
||||
FastMapNode node;
|
||||
|
||||
if (map->nodeCount == 0)
|
||||
return 0;
|
||||
bucket = FastMapBucketForKey(map, key);
|
||||
node = FastMapNodeForKeyInBucket(bucket, key);
|
||||
return node;
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
#include <string.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSSet.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
#include <Foundation/NSException.h>
|
||||
|
@ -129,7 +130,7 @@ static NSArray* _gnu_arguments = nil;
|
|||
static NSMutableDictionary* _gnu_environment = nil;
|
||||
|
||||
// Array of debug levels set.
|
||||
static NSMutableArray* _debug_array = nil;
|
||||
static NSMutableSet* _debug_set = nil;
|
||||
|
||||
/*************************************************************************
|
||||
*** Implementing the Libobjects main function
|
||||
|
@ -146,19 +147,21 @@ _gnu_process_args(int argc, char *argv[], char *env[])
|
|||
|
||||
/* Copy the argument list */
|
||||
{
|
||||
NSMutableSet *mySet;
|
||||
id obj_argv[argc];
|
||||
int added = 0;
|
||||
|
||||
_debug_array = [[NSMutableArray alloc] init];
|
||||
mySet = [[NSMutableSet alloc] init];
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
NSString *str = [NSString stringWithCString:argv[i]];
|
||||
if ([str hasPrefix: @"--GNU-Debug="])
|
||||
[_debug_array addObject: [str substringFromIndex: 12]];
|
||||
[mySet addObject: [str substringFromIndex: 12]];
|
||||
else
|
||||
obj_argv[added++] = str;
|
||||
}
|
||||
_gnu_arguments = [[NSArray alloc] initWithObjects:obj_argv count:added];
|
||||
_debug_set = mySet;
|
||||
}
|
||||
|
||||
/* Copy the evironment list */
|
||||
|
@ -209,83 +212,89 @@ static char **_gnu_noobjc_env;
|
|||
static void
|
||||
_gnu_process_noobjc_args(int argc, char *argv[], char *env[])
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
/* We have to copy these in case the main() modifies their values
|
||||
* somehow before we get a change to use them
|
||||
*/
|
||||
/* We have to copy these in case the main() modifies their values
|
||||
* somehow before we get a change to use them
|
||||
*/
|
||||
|
||||
_gnu_noobjc_argc = argc;
|
||||
i=0;
|
||||
while(argv[i])
|
||||
i++;
|
||||
_gnu_noobjc_argv = malloc(sizeof(char *)*(i+1));
|
||||
if (_gnu_noobjc_argv == NULL)
|
||||
goto error;
|
||||
i=0;
|
||||
while(*argv) {
|
||||
_gnu_noobjc_argv[i] = malloc(strlen(*argv)+1);
|
||||
if (_gnu_noobjc_argv[i] == NULL)
|
||||
goto error;
|
||||
strcpy(_gnu_noobjc_argv[i],*argv);
|
||||
argv++;
|
||||
i++;
|
||||
}
|
||||
_gnu_noobjc_argv[i] = 0;
|
||||
i=0;
|
||||
while(env[i])
|
||||
i++;
|
||||
_gnu_noobjc_env = malloc(sizeof(char *)*(i+1));
|
||||
if (_gnu_noobjc_env == NULL)
|
||||
goto error;
|
||||
i=0;
|
||||
while(*env) {
|
||||
_gnu_noobjc_env[i] = malloc(strlen(*env)+1);
|
||||
if (_gnu_noobjc_env[i] == NULL)
|
||||
goto error;
|
||||
strcpy(_gnu_noobjc_env[i],*env);
|
||||
env++;
|
||||
i++;
|
||||
}
|
||||
_gnu_noobjc_env[i] = 0;
|
||||
return;
|
||||
_gnu_noobjc_argc = argc;
|
||||
i = 0;
|
||||
while (argv[i])
|
||||
i++;
|
||||
_gnu_noobjc_argv = malloc(sizeof(char *)*(i+1));
|
||||
if (_gnu_noobjc_argv == NULL)
|
||||
goto error;
|
||||
i = 0;
|
||||
while (*argv)
|
||||
{
|
||||
_gnu_noobjc_argv[i] = malloc(strlen(*argv)+1);
|
||||
if (_gnu_noobjc_argv[i] == NULL)
|
||||
goto error;
|
||||
strcpy(_gnu_noobjc_argv[i],*argv);
|
||||
argv++;
|
||||
i++;
|
||||
}
|
||||
_gnu_noobjc_argv[i] = 0;
|
||||
i = 0;
|
||||
while (env[i])
|
||||
i++;
|
||||
_gnu_noobjc_env = malloc(sizeof(char *)*(i+1));
|
||||
if (_gnu_noobjc_env == NULL)
|
||||
goto error;
|
||||
i = 0;
|
||||
while(*env)
|
||||
{
|
||||
_gnu_noobjc_env[i] = malloc(strlen(*env)+1);
|
||||
if (_gnu_noobjc_env[i] == NULL)
|
||||
goto error;
|
||||
strcpy(_gnu_noobjc_env[i],*env);
|
||||
env++;
|
||||
i++;
|
||||
}
|
||||
_gnu_noobjc_env[i] = 0;
|
||||
return;
|
||||
|
||||
error:
|
||||
fputs("malloc() error when starting gstep-base\n", stderr);
|
||||
abort();
|
||||
fputs("malloc() error when starting gstep-base\n", stderr);
|
||||
abort();
|
||||
}
|
||||
|
||||
static void _gnu_noobjc_free_vars(void)
|
||||
{
|
||||
char **p;
|
||||
char **p;
|
||||
|
||||
p = _gnu_noobjc_argv;
|
||||
while (*p) {
|
||||
free(*p);
|
||||
p++;
|
||||
}
|
||||
free(_gnu_noobjc_argv);
|
||||
_gnu_noobjc_argv = 0;
|
||||
p = _gnu_noobjc_argv;
|
||||
while (*p)
|
||||
{
|
||||
free(*p);
|
||||
p++;
|
||||
}
|
||||
free(_gnu_noobjc_argv);
|
||||
_gnu_noobjc_argv = 0;
|
||||
|
||||
p = _gnu_noobjc_env;
|
||||
while (*p) {
|
||||
free(*p);
|
||||
p++;
|
||||
}
|
||||
free(_gnu_noobjc_env);
|
||||
_gnu_noobjc_env = 0;
|
||||
p = _gnu_noobjc_env;
|
||||
while (*p)
|
||||
{
|
||||
free(*p);
|
||||
p++;
|
||||
}
|
||||
free(_gnu_noobjc_env);
|
||||
_gnu_noobjc_env = 0;
|
||||
}
|
||||
|
||||
void * __gnustep_base_subinit_args__
|
||||
__attribute__ ((section ("__libc_subinit"))) = &(_gnu_process_noobjc_args);
|
||||
|
||||
+ (void)initialize {
|
||||
if (!_gnu_processName && !_gnu_arguments && !_gnu_environment) {
|
||||
NSAssert(_gnu_noobjc_argv && _gnu_noobjc_env,
|
||||
+ (void) initialize
|
||||
{
|
||||
if (!_gnu_processName && !_gnu_arguments && !_gnu_environment)
|
||||
{
|
||||
NSAssert(_gnu_noobjc_argv && _gnu_noobjc_env,
|
||||
_GNU_MISSING_MAIN_FUNCTION_CALL);
|
||||
_gnu_process_args(_gnu_noobjc_argc,_gnu_noobjc_argv,_gnu_noobjc_env);
|
||||
_gnu_noobjc_free_vars();
|
||||
}
|
||||
_gnu_process_args(_gnu_noobjc_argc,_gnu_noobjc_argv,_gnu_noobjc_env);
|
||||
_gnu_noobjc_free_vars();
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -361,9 +370,9 @@ int main(int argc, char *argv[], char *env[])
|
|||
return _gnu_arguments;
|
||||
}
|
||||
|
||||
- (NSMutableArray*) debugArray
|
||||
- (NSMutableSet*) debugSet
|
||||
{
|
||||
return _debug_array;
|
||||
return _debug_set;
|
||||
}
|
||||
|
||||
- (NSDictionary *)environment
|
||||
|
@ -413,3 +422,22 @@ int main(int argc, char *argv[], char *env[])
|
|||
|
||||
@end
|
||||
|
||||
/*
|
||||
* Function for rapid testing to see if a debug level is set.
|
||||
*/
|
||||
BOOL GSDebugSet(NSString *val)
|
||||
{
|
||||
static SEL debugSel = @selector(member:);
|
||||
static IMP debugImp = 0;
|
||||
|
||||
if (debugImp == 0)
|
||||
{
|
||||
if (_debug_set == nil)
|
||||
{
|
||||
[[NSProcessInfo processInfo] debugSet];
|
||||
}
|
||||
debugImp = [_debug_set methodForSelector: debugSel];
|
||||
}
|
||||
return ((*debugImp)(_debug_set, debugSel, val) == val) ? YES : NO;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue