config and alerting improvements

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@36355 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2013-03-13 10:08:13 +00:00
parent 0cce314dd3
commit b6a1742a05
3 changed files with 123 additions and 32 deletions

View file

@ -1,3 +1,12 @@
2013-03-13 Richard Frith-Macdonald <rfm@gnu.org>
* EcProcess.h:
* EcProcess.m:
Improve documentation of sequence of calls of configuration update
methods and add convenience functionality to support alarming for
fatal configuration errors.
Add Ecmemoryincrement config to adjust alerting about potential leaks.
2013-01-26 Richard Frith-Macdonald <rfm@gnu.org>
* EcAlarmDestination.m:

View file

@ -63,6 +63,17 @@
may be overridden by using the 'release' command in the
Console program.
</desc>
<term>EcMemoryIncrement</term>
<desc>
This integer value controls the (KBytes) increment in process
memory usage after which an alert is generated.<br />
If this is not set (or is set to a value less than 1) then
a value of 500 is used unless EcMemory is set (in which case
the lower value of 20 is used).<br />
Setting a higher value make memory leak detection less
sensitive (but reduces unnecessary alerts).<br />
This may be set on the command line or in Control.plist
</desc>
<term>EcRelease</term>
<desc>
This boolean value determines whether checks for memory problems
@ -448,15 +459,19 @@ extern NSString* cmdVersion(NSString *ver);
*/
- (void) cmdDebug: (NSString*)fmt, ...;
/** Called whenever the user defaults are updated due to a central
* configuration change (or another defaults system change).<br />
* This is also called by -cmdUpdate: even if no configuration
* actually changed ... in which case the notification argument
* is nil.<br />
/** Called whenever the user defaults are updated (which may be due to a
* central configuration in additions to other defaults system changes).<br />
* This is automatically called by -cmdUpdate: (even if the user defaults
* database has not actually changed), in this case the notification
* argument is nil.<br />
* If you override this to handle configuration changes, don't forget
* to call the superclass implementation.<br />
* This method is provided to allow subclasses to control the order
* in which defaults changes are handled by them and their superclasses.
* in which defaults changes are handled by them and their superclasses.<br />
* Generally, this method is for use handling changes in the local
* NSUserDefaults database; to handle explict configuration changes from
* the central configuration in the Control server, you should usually
* override the -cmdUpdated method instead.
*/
- (void) cmdDefaultsChanged: (NSNotification*)n;
@ -562,9 +577,30 @@ extern NSString* cmdVersion(NSString *ver);
* defaults system ... so be sure that your implementation calls the
* superclass implementation (unless you wish to suppress the configuration
* update).<br />
* You may alter the info dictionary prior to passign it to the superclass
* You may alter the info dictionary prior to passing it to the superclass
* implementation if you wish to adjust the new configuration before it
* takes effect.
* takes effect.<br />
* The order of execution of a configuration update is therefore as follows:
* <list>
* <item>Any subclass implementation of -cmdUpdate: is entered.
* </item>
* <item>The base implementation of -cmdUpdate: is entered, the stored
* configuration is changed as necessary, the user defaults database is
* updated.
* </item>
* <item>The -cmdDefaultsChanged: method is called (either as a result of
* a user defaults update, or directly by the base -cmdUpdate: method.
* </item>
* <item>The base implementation of the -cmdDefaults: method ends.
* </item>
* <item>Any subclass implementation of the -cmdDefaults: method ends.
* </item>
* <item>The -cmdUpdated method is called.
* </item>
* </list>
* You should usually override the -cmdUpdated method to handle configuration
* changes, using this method only when you want to check/override changes
* before they take effect.
*/
- (void) cmdUpdate: (NSMutableDictionary*)info;
@ -576,10 +612,16 @@ extern NSString* cmdVersion(NSString *ver);
* NB. This method will be called even if your implementation of
* -cmdUpdate: suppresses the actual update. In this situation this
* method will find the configuration unchanged since the previous
* time that it was called.
* time that it was called.<br />
* The base implementation of this method does nothing and return nil.<br />
* The return value of this method is used to control automatic generation
* of alarms for fatal configuration errors. If the return value is nil
* (the default), then any configuration error alarm is cleared.
* Otherwise, a configuration error alarm will be raised (using the
* returned string as the 'additional text' of the alarm), and the
* process will be terminated by a call to -cmdQuit: with an argument of 1.
*/
- (void) cmdUpdated;
- (NSString*) cmdUpdated;
- (void) log: (NSString*)message type: (EcLogType)t;

View file

@ -1891,6 +1891,8 @@ NSLog(@"Ignored attempt to set timer interval to %g ... using 10.0", interval);
average = ((average / 1024) + 1) * 1024;
if (average > memPeak)
{
int inc;
/* Alert if the we have peaked above the allowed size.
*/
if (average > (memAllowed * 1024 * 1024))
@ -1912,24 +1914,29 @@ NSLog(@"Ignored attempt to set timer interval to %g ... using 10.0", interval);
memPeak = size;
}
}
if (YES == [cmdDefs boolForKey: @"Memory"])
{
/* We want detailed memory information, so we set the next
* alerting threshold from 20 to 40 KB above the current
* peak usage.
*/
memPeak = ((memPeak / (20 * 1024)) + 2) * (20 * 1024);
}
else
{
/* We do not want detailed memory information,
* so we set the next alerting threshold from
* 500 to 1000 KB above the current peak usage,
* ensuring that only serious increases
* in usage will generate an alert.
*/
memPeak = ((memPeak / (500 * 1024)) + 2) * (500 * 1024);
}
inc = (int)[cmdDefs integerForKey: @"MemoryIncrement"];
if (inc < 1)
{
if (YES == [cmdDefs boolForKey: @"Memory"])
{
/* We want detailed memory information, so we set the next
* alerting threshold from 20 to 40 KB above the current
* peak usage.
*/
inc = 20;
}
else
{
/* We do not want detailed memory information,
* so we set the next alerting threshold from
* 500 to 1000 KB above the current peak usage,
* ensuring that only serious increases
* in usage will generate an alert.
*/
inc = 500;
}
}
memPeak = ((memPeak / (inc * 1024)) + 2) * (inc * 1024);
}
}
/* Record the latest memory usage.
@ -2904,9 +2911,9 @@ NSLog(@"Ignored attempt to set timer interval to %g ... using 10.0", interval);
}
}
- (void) cmdUpdated
- (NSString*) cmdUpdated
{
return;
return nil;
}
@ -3892,16 +3899,49 @@ NSLog(@"Ignored attempt to set timer interval to %g ... using 10.0", interval);
if (nil == cmdConf || [cmdConf isEqual: newConfig] == NO)
{
NSString *err;
NS_DURING
[self cmdUpdate: newConfig];
NS_HANDLER
[self cmdError: @"Problem before updating config: %@", localException];
NS_ENDHANDLER
NS_DURING
[self cmdUpdated];
err = [self cmdUpdated];
NS_HANDLER
err = nil;
[self cmdError: @"Problem after updating config: %@", localException];
NS_ENDHANDLER
if (nil != err)
{
EcAlarm *a;
a = [EcAlarm alarmForManagedObject: nil
at: nil
withEventType: EcAlarmEventTypeProcessingError
probableCause: EcAlarmConfigurationOrCustomizationError
specificProblem: @"fatal configuration error"
perceivedSeverity: EcAlarmSeverityMajor
proposedRepairAction: _(@"Correct config (check log for details).")
additionalText: err];
[self alarm: a];
[alarmDestination shutdown];
[self cmdQuit: 1];
}
else
{
EcAlarm *a;
a = [EcAlarm alarmForManagedObject: nil
at: nil
withEventType: EcAlarmEventTypeProcessingError
probableCause: EcAlarmConfigurationOrCustomizationError
specificProblem: @"fatal configuration error"
perceivedSeverity: EcAlarmSeverityCleared
proposedRepairAction: nil
additionalText: nil];
[self alarm: a];
}
}
}