Trun on DO encryption if available. Improve memory usage setting/reporting

This commit is contained in:
Richard Frith-Macdonald 2021-06-03 15:40:14 +01:00
parent de5edec9ef
commit 9b87fbcdc4
3 changed files with 66 additions and 87 deletions

View file

@ -452,7 +452,7 @@ extern NSString* cmdVersion(NSString *ver);
* <term>EcMemoryAllowed</term>
* <desc>
* This may be used to specify the process memory usage
* (in megabytes) before memory usage alarms may begin.<br />
* (in megabytes by default) before memory usage alarms may begin.<br />
* If this setting is not specified (or a negative or excessive value
* is specified) then memory is monitored for ten minutes and the
* base/allowed threshold is set at either the peak during that period
@ -478,8 +478,8 @@ extern NSString* cmdVersion(NSString *ver);
* <term>EcMemoryMaximum</term>
* <desc>
* This may be used to specify the maximum process memory allowed
* (in megabytes) before the process is forced to restart due to
* excessive memory usage.<br />
* (in megabytes by default) before the process is forced to restart due
* to excessive memory usage.<br />
* If the total memory usage of the process reaches this threshold,
* the -ecRestart: method will be called<br />
* The process will also generate alarms depending on the memory usage
@ -504,6 +504,13 @@ extern NSString* cmdVersion(NSString *ver);
* between multiple processes (used for the program code and for shared
* libraries).
* </desc>
* <term>EcMemoryUnit</term>
* <desc>
* This controls the units in which memory information is displayed,
* the default being K/KB/KiB (1024 bytes). Other possible settings are
* M/MB/MiB (1048576 bytes) and P/Pg/Page (system memory pages, typically
* 4096 bytes).
* </desc>
* <term>EcRelease</term>
* <desc>
* This boolean value determines whether checks for memory problems

View file

@ -26,29 +26,10 @@
*/
#import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSConnection.h>
#import <Foundation/NSData.h>
#import <Foundation/NSDate.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSDistantObject.h>
#import <Foundation/NSException.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSNotification.h>
#import <Foundation/NSObjCRuntime.h>
#import <Foundation/NSPort.h>
#import <Foundation/NSProcessInfo.h>
#import <Foundation/NSRunLoop.h>
#import <Foundation/NSScanner.h>
#import <Foundation/NSSerialization.h>
#import <Foundation/NSString.h>
#import <Foundation/NSTimer.h>
#import <Foundation/NSUserDefaults.h>
#import <Foundation/NSValue.h>
#import <Foundation/Foundation.h>
#import <GNUstepBase/GSObjCRuntime.h>
#import <GNUstepBase/GSTLS.h>
#import <GNUstepBase/NSObject+GNUstepBase.h>
#import "EcProcess.h"
@ -767,9 +748,6 @@ ecHostName()
static EcAlarmSeverity memAlarm = EcAlarmSeverityMajor;
static NSString *memType = nil;
static NSString *memUnit = @"KB";
static int memSize = 1024; // Report KB
static NSTimeInterval memTime = 0.0; // Time of last check
static uint64_t memMaximum = 0;
static uint64_t memAllowed = 0;
static uint64_t excAvge = 0; // current period average
@ -3072,6 +3050,12 @@ NSLog(@"Ignored attempt to set timer interval to %g ... using 10.0", interval);
{
if (nil == ecLock)
{
/* Enable encrypted DO if supported bu the base library.
*/
if ([NSSocketPort respondsToSelector: @selector(setOptionsForTLS:)])
{
[NSSocketPort setOptionsForTLS: [NSDictionary dictionary]];
}
ecLock = [NSRecursiveLock new];
dateClass = [NSDate class];
cDateClass = [NSCalendarDate class];
@ -5201,7 +5185,6 @@ With two parameters ('maximum' and a number),\n\
else
{
NSTimeInterval ti = [self ecQuitDuration];
NSString *s;
[self cmdPrintf: @"\n%@ on %@ running since %@\n",
cmdLogName(), ecHostName(), [self ecStarted]];
@ -5215,7 +5198,9 @@ With two parameters ('maximum' and a number),\n\
}
if (ti > 0)
{
if (nil == (s = [self ecQuitReason]))
NSString *s = [self ecQuitReason];
if (nil == s)
{
[self cmdPrintf: @"Quitting for %g seconds\n", ti];
}
@ -5236,21 +5221,12 @@ With two parameters ('maximum' and a number),\n\
}
}
if (memTime <= 0.0)
{
s = @"";
}
else
{
s = [NSString stringWithFormat: @" (last checked at %@)",
[NSDate dateWithTimeIntervalSinceReferenceDate: memTime]];
}
[self cmdPrintf: @"%@ memory usage%@:\n"
@" %"PRIu64"%@ (current), %"PRIu64"%@ (peak)\n",
memType, s, memLast/memSize, memUnit, memPeak/memSize, memUnit];
[self cmdPrintf: @" %"PRIu64"%@ (average),"
@" %"PRIu64"%@ (start)\n",
memAvge/memSize, memUnit, memStrt/memSize, memUnit];
[self cmdPrintf: @"%@ memory usage:\n %"PRIu64"KB (current),"
@" %"PRIu64"KB (peak)\n",
memType, memLast/1024, memPeak/1024];
[self cmdPrintf: @" %"PRIu64"KB (average),"
@" %"PRIu64"KB (start)\n",
memAvge/1024, memStrt/1024];
setMemBase();
if (memSlot < MEMCOUNT)
@ -5263,8 +5239,8 @@ With two parameters ('maximum' and a number),\n\
if (memAllowed > 0)
{
[self cmdPrintf: @"MemoryAllowed: %"PRIu64
@"%@\n the process is expected to use up to this much memory.\n",
memAllowed * 1024 * 1024 / memSize, memUnit];
@"KB\n the process is expected to use up to this much memory.\n",
memAllowed * 1024];
}
if (memMaximum > 0)
{
@ -5275,20 +5251,19 @@ With two parameters ('maximum' and a number),\n\
if (0 == memAllowed)
{
[self cmdPrintf: @"Estimated base: %"PRIu64
@"%@\n the process is expected to use up to"
@"KB\n the process is expected to use up to"
@" this much memory.\n",
memAllowed * 1024 * 1024 / memSize, memUnit];
memAllowed * 1024];
}
[self cmdPrintf: @"MemoryMaximum: %"PRIu64
@"%@\n the process is restarted when peak memory usage"
@" is above this limit.\n",
memMaximum * 1024 * 1024 / memSize, memUnit];
@"KB\n the process is restarted when peak memory usage"
@" is above this limit.\n", memMaximum * 1024];
idle = [cmdDefs stringForKey: @"MemoryIdle"];
if ([idle length] > 0 && (hour = [idle intValue]) >= 0 && hour < 24)
{
[self cmdPrintf: @" The process is also restarted if memory"
@" is above %"PRIu64"%@\n during the hour from %02d:00.\n",
memCrit/memSize, memUnit, hour];
@" is above %"PRIu64"KB\n during the hour from %02d:00.\n",
memCrit/1024, hour];
}
limit = memWarn;
switch (memAlarm)
@ -5299,7 +5274,7 @@ With two parameters ('maximum' and a number),\n\
default: limit = memWarn; break;
}
[self cmdPrintf: @"Alarms are raised when memory usage"
@" is above: %"PRIu64"%@.\n", limit / memSize, memUnit];
@" is above: %"PRIu64"KB.\n", limit / 1024];
}
}
}
@ -5521,12 +5496,9 @@ With two parameters ('maximum' and a number),\n\
@"-%@MemoryMaximum [MB] Maximum memory usage (before restart)\n"
@"-%@MemoryType [aName] Type of memory to measure. One of\n"
@" Total, Resident or Data.\n"
@"-%@MemoryUnit [aName] Unit to display memory in. One of\n"
@" KB, MB or Page (KB by default).\n"
@"-%@ProgramName [aName] Name to use for this program\n"
@"\n--version to get version information and quit\n\n",
prf, prf, prf, prf, prf, prf, prf, prf, prf, prf,
prf, prf, prf, prf);
prf, prf, prf, prf, prf, prf, prf, prf, prf, prf, prf, prf, prf);
[EcDefaultRegistration showHelp];
@ -5972,27 +5944,6 @@ With two parameters ('maximum' and a number),\n\
NSString *str;
int i;
memTime = [NSDate timeIntervalSinceReferenceDate];
if (nil == (str = [cmdDefs stringForKey: @"MemoryUnit"]))
{
memSize = 1024;
memUnit = @"KB";
}
else if ([str caseInsensitiveCompare: @"MB"] == NSOrderedSame)
{
memSize = 1024 * 1024;
memUnit = @"MB";
}
else if ([str caseInsensitiveCompare: @"Page"] == NSOrderedSame)
{
memSize = pageSize;
memUnit = @"Pg";
}
else
{
memSize = 1024;
memUnit = @"KB";
}
if (nil == (str = [cmdDefs stringForKey: @"MemoryType"]))
{
str = @"Total";
@ -6035,11 +5986,11 @@ With two parameters ('maximum' and a number),\n\
}
else
{
if ([memType isEqualToString: @"Resident"])
if ([memType isEqualToString: @"Resident"] == NSOrderedSame)
{
memLast = mResident;
}
else if ([memType isEqualToString: @"Data"])
else if ([memType isEqualToString: @"Data"] == NSOrderedSame)
{
memLast = mData;
}
@ -6187,11 +6138,11 @@ With two parameters ('maximum' and a number),\n\
NSString *additional;
additional = [NSString stringWithFormat:
@"Average %@ memory usage %lu%@ (base %lu%@, max %lu%@)",
@"Average %@ memory usage %luKB (base %luKB, max %luKB)",
memType,
(unsigned long)memAvge/memSize, memUnit,
(unsigned long)memBase/memSize, memUnit,
(unsigned long)memMaximum*1024*1024/memSize, memUnit];
(unsigned long)memAvge/1024,
(unsigned long)memBase/1024,
(unsigned long)memMaximum*1024];
NSLog(@"%@", additional);
@ -6243,8 +6194,8 @@ With two parameters ('maximum' and a number),\n\
if (YES == memDebug)
{
[self cmdDbg: cmdDetailDbg
msg: @"%@ memory usage %"PRIu64"%@ (reserved: %"PRIu64"%@)",
memType, memLast/memSize, memUnit, excLast/memSize, memUnit];
msg: @"%@ memory usage %"PRIu64"KB (reserved: %"PRIu64"KB)",
memType, memLast/1024, excLast/1024];
}
}

View file

@ -41,6 +41,23 @@
#import "EcHost.h"
#import "EcTest.h"
static void
setup()
{
static BOOL beenHere = NO;
if (NO == beenHere)
{
beenHere = YES;
/* Enable encrypted DO if supported bu the base library.
*/
if ([NSSocketPort respondsToSelector: @selector(setOptionsForTLS:)])
{
[NSSocketPort setOptionsForTLS: [NSDictionary dictionary]];
}
}
}
static NSUserDefaults*
defaults()
{
@ -71,6 +88,7 @@ defaults()
id<EcTest>
EcTestConnect(NSString *name, NSString *host, NSTimeInterval timeout)
{
setup();
CREATE_AUTORELEASE_POOL(pool);
BOOL triedLaunching = NO;
NSUserDefaults *defs = defaults();
@ -164,6 +182,7 @@ EcTestConnect(NSString *name, NSString *host, NSTimeInterval timeout)
id
EcTestGetConfig(id<EcTest> process, NSString *key)
{
setup();
id val;
NSCAssert([key isKindOfClass: [NSString class]], NSInvalidArgumentException);
@ -182,6 +201,7 @@ EcTestGetConfig(id<EcTest> process, NSString *key)
void
EcTestSetConfig(id<EcTest> process, NSString *key, id value)
{
setup();
NSCAssert([key isKindOfClass: [NSString class]], NSInvalidArgumentException);
if (nil != value)
{
@ -197,6 +217,7 @@ EcTestSetConfig(id<EcTest> process, NSString *key, id value)
BOOL
EcTestShutdown(id<EcTest> process, NSTimeInterval timeout)
{
setup();
int pid;
NSConnection *conn;
NSDate *when;