bug 699409 - telemetry for memory used by records in the disk cache map. r=jduell
authorNick Hurley <hurley@todesschaf.org>
Mon, 07 Nov 2011 23:41:52 -0500
changeset 79988 5c0861ec147f45cb4bee620c2381a2c26dcf227d
parent 79987 27b8e5fb9699fb0145486ebfbfbcacf0c510431e
child 79989 bcf9c9ec97a04c122d9156483f8f8300e1bf8364
push idunknown
push userunknown
push dateunknown
reviewersjduell
bugs699409
milestone10.0a1
bug 699409 - telemetry for memory used by records in the disk cache map. r=jduell
netwerk/cache/nsDiskCacheMap.cpp
toolkit/components/telemetry/TelemetryHistograms.h
--- a/netwerk/cache/nsDiskCacheMap.cpp
+++ b/netwerk/cache/nsDiskCacheMap.cpp
@@ -48,16 +48,18 @@
 #include "nsCache.h"
 
 #include <string.h>
 #include "nsPrintfCString.h"
 
 #include "nsISerializable.h"
 #include "nsSerializationHelper.h"
 
+#include "mozilla/Telemetry.h"
+
 /******************************************************************************
  *  nsDiskCacheMap
  *****************************************************************************/
 
 /**
  *  File operations
  */
 
@@ -159,16 +161,25 @@ nsDiskCacheMap::Open(nsILocalFile *  cac
     rv = OpenBlockFiles();
     if (NS_FAILED(rv))  goto error_exit;
 
     // set dirty bit and flush header
     mHeader.mIsDirty    = true;
     rv = FlushHeader();
     if (NS_FAILED(rv))  goto error_exit;
     
+    {
+        // extra scope so the compiler doesn't barf on the above gotos jumping
+        // past this declaration down here
+        PRUint32 overhead = moz_malloc_usable_size(mRecordArray);
+        overhead = overhead ? overhead : mHeader.mRecordCount * sizeof(nsDiskCacheRecord);
+        mozilla::Telemetry::Accumulate(mozilla::Telemetry::HTTP_DISK_CACHE_OVERHEAD,
+                overhead);
+    }
+
     return NS_OK;
     
 error_exit:
     (void) Close(false);
        
     return rv;
 }
 
--- a/toolkit/components/telemetry/TelemetryHistograms.h
+++ b/toolkit/components/telemetry/TelemetryHistograms.h
@@ -161,16 +161,17 @@ HTTP_HISTOGRAMS(SUB, "subitem: ")
 HISTOGRAM(HTTP_CACHE_DISPOSITION, 1, 5, 5, LINEAR, "HTTP Cache Hit, Reval, Failed-Reval, Miss")
 HISTOGRAM(HTTP_DISK_CACHE_DISPOSITION, 1, 5, 5, LINEAR, "HTTP Disk Cache Hit, Reval, Failed-Reval, Miss")
 HISTOGRAM(HTTP_MEMORY_CACHE_DISPOSITION, 1, 5, 5, LINEAR, "HTTP Memory Cache Hit, Reval, Failed-Reval, Miss")
 HISTOGRAM(HTTP_OFFLINE_CACHE_DISPOSITION, 1, 5, 5, LINEAR, "HTTP Offline Cache Hit, Reval, Failed-Reval, Miss")
 HISTOGRAM(CACHE_DEVICE_SEARCH, 1, 100, 100, LINEAR, "Time to search cache (ms)")
 HISTOGRAM(CACHE_MEMORY_SEARCH, 1, 100, 100, LINEAR, "Time to search memory cache (ms)")
 HISTOGRAM(CACHE_DISK_SEARCH, 1, 100, 100, LINEAR, "Time to search disk cache (ms)")
 HISTOGRAM(CACHE_OFFLINE_SEARCH, 1, 100, 100, LINEAR, "Time to search offline cache (ms)")
+HISTOGRAM(HTTP_DISK_CACHE_OVERHEAD, 1, 32000000, 100, EXPONENTIAL, "HTTP Disk cache memory overhead (bytes)")
 
 HISTOGRAM(FIND_PLUGINS, 1, 3000, 10, EXPONENTIAL, "Time spent scanning filesystem for plugins (ms)")
 HISTOGRAM(CHECK_JAVA_ENABLED, 1, 3000, 10, EXPONENTIAL, "Time spent checking if Java is enabled (ms)")
 
 /* Define 2 histograms: MOZ_SQLITE_(NAME)_MS and
  * MOZ_SQLITE_(NAME)_MAIN_THREAD_MS. These are meant to be used by
  * IOThreadAutoTimer which relies on _MAIN_THREAD_MS histogram being
  * "+ 1" away from MOZ_SQLITE_(NAME)_MS.