Author: rfm
Date: Mon Jul 13 12:02:31 2015
New Revision: 38788

URL: http://svn.gna.org/viewcvs/gnustep?rev=38788&view=rev
Log:
More teaking memory alerting

Modified:
    libs/ec/trunk/ChangeLog
    libs/ec/trunk/EcProcess.h
    libs/ec/trunk/EcProcess.m

Modified: libs/ec/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/ec/trunk/ChangeLog?rev=38788&r1=38787&r2=38788&view=diff
==============================================================================
--- libs/ec/trunk/ChangeLog     (original)
+++ libs/ec/trunk/ChangeLog     Mon Jul 13 12:02:31 2015
@@ -1,3 +1,10 @@
+2015-07-13  Richard Frith-Macdonald <[email protected]>
+
+       * 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 <[email protected]>
 
        * EcProcess.h:

Modified: libs/ec/trunk/EcProcess.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/ec/trunk/EcProcess.h?rev=38788&r1=38787&r2=38788&view=diff
==============================================================================
--- libs/ec/trunk/EcProcess.h   (original)
+++ libs/ec/trunk/EcProcess.h   Mon Jul 13 12:02:31 2015
@@ -278,7 +278,8 @@
  *     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 @@
  *   <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 @@
  *   <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 @@
 - (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;
 

Modified: libs/ec/trunk/EcProcess.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/ec/trunk/EcProcess.m?rev=38788&r1=38787&r2=38788&view=diff
==============================================================================
--- libs/ec/trunk/EcProcess.m   (original)
+++ libs/ec/trunk/EcProcess.m   Mon Jul 13 12:02:31 2015
@@ -520,13 +520,19 @@
 
 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 @@
         @" %"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 @@
         }
       fclose(fptr);
     }
+  excLast = (uint64_t)[self ecNotLeaked];
 
   /* Do initial population so we can work immediately.
    */
@@ -4319,21 +4326,27 @@
     {
       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,12 +4355,20 @@
     {
       memAvge = ((memAvge / 1024) + 1) * 1024;
     }
+  if (excAvge % 1024)
+    {
+      excAvge = ((excAvge / 1024) + 1) * 1024;
+    }
 
   /* Update peak memory usage if necessary.
    */
   if (memLast > memPeak)
     {
       memPeak = memLast;
+    }
+  if (excLast > excPeak)
+    {
+      excPeak = excLast;
     }
 
   /* If we have a defined maximum memory usage for the process,
@@ -4363,12 +4384,12 @@
       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 @@
        */
       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 @@
     {
       [self cmdDbg: cmdDetailDbg
               msg: @"Memory usage %"PRIu64"KB (reserved: %"PRIu64"KB)",
-        memLast/1024, ((uint64_t)[self ecNotLeaked])/1024];
+        memLast/1024, excLast/1024];
     }
 }
 


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to