mirror of
https://github.com/gnustep/libs-ec.git
synced 2025-02-20 18:32:09 +00:00
More teaking memory alerting
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@38788 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0b4401c2d9
commit
783d4cfb6c
3 changed files with 61 additions and 23 deletions
|
@ -1,3 +1,10 @@
|
|||
2015-07-13 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* EcProcess.h:
|
||||
* EcProcess.m:
|
||||
Restore lost effect of -ecNotLeaked to moderate changes in our idea
|
||||
of when we should generate a warening about potential leaks
|
||||
|
||||
2015-07-08 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* EcProcess.h:
|
||||
|
|
15
EcProcess.h
15
EcProcess.h
|
@ -278,7 +278,8 @@ extern NSString* cmdVersion(NSString *ver);
|
|||
* This may be used to specify the total process memory usage
|
||||
* (in megabytes) before memory usage alerting may begin.<br />
|
||||
* Memory usage 'error' reports are then generated every time
|
||||
* the average (over ten minutes) memory usage exceeds a warning
|
||||
* the average (over ten minutes) memory usage (adjusted by the
|
||||
* average memory known not leaked) exceeds a warning
|
||||
* threshold (the threshold is then increased).<br />
|
||||
* If this setting is not specified (or a negative or excessive value
|
||||
* is specified) then memory is monitored for ten minutes and
|
||||
|
@ -293,7 +294,8 @@ extern NSString* cmdVersion(NSString *ver);
|
|||
* <term>EcMemoryIncrement</term>
|
||||
* <desc>
|
||||
* This integer value controls the (KBytes) increment (from
|
||||
* current peak value) in process memory usage after which
|
||||
* current peak value) in process memory usage (adjusted by the
|
||||
* average memory known not leaked) after which
|
||||
* an alert is generated.<br />
|
||||
* If this is not set (or is set to a value less than 10KB or
|
||||
* greater than 1GB) then a value of 5MB is used.<br />
|
||||
|
@ -321,7 +323,8 @@ extern NSString* cmdVersion(NSString *ver);
|
|||
* <term>EcMemoryPercentage</term>
|
||||
* <desc>
|
||||
* This integer value controls the increase in the alerting
|
||||
* threshold after which a memory usage alert is generated.<br />
|
||||
* threshold (adjusted by the average memory known not leaked)
|
||||
* after which a memory usage alert is generated.<br />
|
||||
* The increase is calculated as a percentage of the current
|
||||
* peak memory usage value when an alert is generated.<br />
|
||||
* If this is not set (or is set to a value less than 1 or
|
||||
|
@ -970,8 +973,10 @@ extern NSString* cmdVersion(NSString *ver);
|
|||
- (void) ecNewMinute: (NSCalendarDate*)when;
|
||||
|
||||
/** Return heap memory known not to be leaked ... for use in internal
|
||||
* monitoring of memory usage. You should override this ti add in any
|
||||
* heap store you have used and know is not leaked.
|
||||
* monitoring of memory usage. You should override this to add in any
|
||||
* heap store you have used and know is not leaked.<br />
|
||||
* When generating error messages alerting about possible memory leaks,
|
||||
* this value is taken into consideration.
|
||||
*/
|
||||
- (NSUInteger) ecNotLeaked;
|
||||
|
||||
|
|
62
EcProcess.m
62
EcProcess.m
|
@ -520,13 +520,19 @@ ecHostName()
|
|||
|
||||
static uint64_t memMaximum = 0;
|
||||
static uint64_t memAllowed = 0;
|
||||
static uint64_t excAvge = 0; // current period average
|
||||
static uint64_t memAvge = 0; // current period average
|
||||
static uint64_t memStrt = 0; // usage at first check
|
||||
static uint64_t memLast = 0; // usage at last check
|
||||
static uint64_t memPrev = 0; // usage at previous warning
|
||||
static uint64_t memPeak = 0; // peak usage
|
||||
static uint64_t memWarn = 0; // next warning point
|
||||
static uint64_t excStrt = 0; // excluded usage at first check
|
||||
static uint64_t memStrt = 0; // total usage at first check
|
||||
static uint64_t excLast = 0; // excluded usage at last check
|
||||
static uint64_t memLast = 0; // total usage at last check
|
||||
static uint64_t excPrev = 0; // excluded usage at previous warning
|
||||
static uint64_t memPrev = 0; // total usage at previous warning
|
||||
static uint64_t excPeak = 0; // excluded peak usage
|
||||
static uint64_t memPeak = 0; // total peak usage
|
||||
static uint64_t memWarn = 0; // next warning interval
|
||||
static uint64_t memSlot = 0; // minute counter
|
||||
static uint64_t excRoll[10]; // last N values
|
||||
static uint64_t memRoll[10]; // last N values
|
||||
#define MEMCOUNT (sizeof(memRoll)/sizeof(*memRoll))
|
||||
static NSDate *memTime = nil; // Time of last alert
|
||||
|
@ -3395,7 +3401,7 @@ With two parameters ('maximum' and a number),\n\
|
|||
@" %"PRIu64"KB (start)\n",
|
||||
memAvge/1024, memStrt/1024];
|
||||
[self cmdPrintf: @" %"PRIu64"KB (reserved)\n",
|
||||
((uint64_t)[self ecNotLeaked])/1024];
|
||||
excLast/1024];
|
||||
if (memSlot < MEMCOUNT)
|
||||
{
|
||||
[self cmdPrintf: @"Memory error reporting disabled (for %d min"
|
||||
|
@ -4312,6 +4318,7 @@ With two parameters ('maximum' and a number),\n\
|
|||
}
|
||||
fclose(fptr);
|
||||
}
|
||||
excLast = (uint64_t)[self ecNotLeaked];
|
||||
|
||||
/* Do initial population so we can work immediately.
|
||||
*/
|
||||
|
@ -4319,21 +4326,27 @@ With two parameters ('maximum' and a number),\n\
|
|||
{
|
||||
for (i = 1; i < MEMCOUNT; i++)
|
||||
{
|
||||
excRoll[i] = excLast;
|
||||
memRoll[i] = memLast;
|
||||
}
|
||||
memPrev = memStrt = memLast;
|
||||
excPrev = excStrt = excLast;
|
||||
}
|
||||
excRoll[memSlot % MEMCOUNT] = excLast;
|
||||
memRoll[memSlot % MEMCOUNT] = memLast;
|
||||
memSlot++;
|
||||
|
||||
/* Find the average usage over the last set of samples.
|
||||
* Round up to a block size.
|
||||
*/
|
||||
excAvge = 0;
|
||||
memAvge = 0;
|
||||
for (i = 0; i < MEMCOUNT; i++)
|
||||
{
|
||||
excAvge += excRoll[i];
|
||||
memAvge += memRoll[i];
|
||||
}
|
||||
excAvge /= MEMCOUNT;
|
||||
memAvge /= MEMCOUNT;
|
||||
|
||||
/* Convert to 1KB blocks.
|
||||
|
@ -4342,6 +4355,10 @@ With two parameters ('maximum' and a number),\n\
|
|||
{
|
||||
memAvge = ((memAvge / 1024) + 1) * 1024;
|
||||
}
|
||||
if (excAvge % 1024)
|
||||
{
|
||||
excAvge = ((excAvge / 1024) + 1) * 1024;
|
||||
}
|
||||
|
||||
/* Update peak memory usage if necessary.
|
||||
*/
|
||||
|
@ -4349,6 +4366,10 @@ With two parameters ('maximum' and a number),\n\
|
|||
{
|
||||
memPeak = memLast;
|
||||
}
|
||||
if (excLast > excPeak)
|
||||
{
|
||||
excPeak = excLast;
|
||||
}
|
||||
|
||||
/* If we have a defined maximum memory usage for the process,
|
||||
* we should shut down with a non-zero status to get a restart.
|
||||
|
@ -4363,12 +4384,12 @@ With two parameters ('maximum' and a number),\n\
|
|||
return;
|
||||
}
|
||||
|
||||
/* If the average memory usage is above the threshold, we alert and reset
|
||||
* the threshold.
|
||||
/* If the average memory usage is above the threshold (adjusted by any
|
||||
* change in known unleaked memory), we alert and reset the threshold.
|
||||
* During the first ten minutes though, we always adjust the threshold and
|
||||
* we suppress any warnings. This gives us a more stable starting point.
|
||||
*/
|
||||
if (memAvge > memWarn || memSlot < MEMCOUNT)
|
||||
if (memAvge + excPrev - excAvge > memWarn || memSlot < MEMCOUNT)
|
||||
{
|
||||
NSInteger inc;
|
||||
NSInteger pct;
|
||||
|
@ -4420,24 +4441,29 @@ With two parameters ('maximum' and a number),\n\
|
|||
*/
|
||||
if (memSlot >= MEMCOUNT)
|
||||
{
|
||||
uint64_t prev;
|
||||
uint64_t ePrev;
|
||||
uint64_t mPrev;
|
||||
NSDate *when;
|
||||
|
||||
prev = memPrev;
|
||||
ePrev = excPrev;
|
||||
mPrev = memPrev;
|
||||
when = AUTORELEASE(memTime);
|
||||
excPrev = excAvge;
|
||||
memPrev = memAvge;
|
||||
memTime = [NSDate new];
|
||||
if (nil == when)
|
||||
{
|
||||
[self cmdError: @"Average memory usage grown from %"
|
||||
PRIu64"KB to %"PRIu64"KB (reserved: %"PRIu64"KB)",
|
||||
prev/1024, memAvge/1024, ((uint64_t)[self ecNotLeaked])/1024];
|
||||
[self cmdError: @"Average memory usage grown by %ldKB"
|
||||
@" with %ldKB accounted for; possible leak of %ldKB",
|
||||
(long)(memAvge - mPrev)/1024, (long)(excAvge - ePrev)/1024,
|
||||
(long)(memAvge - mPrev + ePrev - excAvge)/1024];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self cmdError: @"Average memory usage grown from %"
|
||||
PRIu64"KB to %"PRIu64"KB (reserved: %"PRIu64"KB) since %@",
|
||||
prev/1024, memAvge/1024, ((uint64_t)[self ecNotLeaked])/1024,
|
||||
[self cmdError: @"Average memory usage grown by %ldKB"
|
||||
@" with %ldKB accounted for; possible leak of %ldKB since %@",
|
||||
(long)(memAvge - mPrev)/1024, (long)(excAvge - ePrev)/1024,
|
||||
(long)(memAvge - mPrev + ePrev - excAvge)/1024,
|
||||
when];
|
||||
}
|
||||
}
|
||||
|
@ -4447,7 +4473,7 @@ With two parameters ('maximum' and a number),\n\
|
|||
{
|
||||
[self cmdDbg: cmdDetailDbg
|
||||
msg: @"Memory usage %"PRIu64"KB (reserved: %"PRIu64"KB)",
|
||||
memLast/1024, ((uint64_t)[self ecNotLeaked])/1024];
|
||||
memLast/1024, excLast/1024];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue