Bug 669117 - Add a memory reporter for the Necko memory cache. r=khuey,jduell.

This commit is contained in:
Nicholas Nethercote 2011-07-18 18:22:36 -07:00
parent d8af27d8bc
commit 44f3c270fd
5 changed files with 44 additions and 2 deletions

View File

@ -57,6 +57,7 @@
#include "nsDiskCacheDeviceSQL.h"
#endif
#include "nsIMemoryReporter.h"
#include "nsIObserverService.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
@ -1002,6 +1003,15 @@ private:
*****************************************************************************/
nsCacheService * nsCacheService::gService = nsnull;
static nsCOMPtr<nsIMemoryReporter> MemoryCacheReporter = nsnull;
NS_THREADSAFE_MEMORY_REPORTER_IMPLEMENT(NetworkMemoryCache,
"explicit/network-memory-cache",
KIND_HEAP,
UNITS_BYTES,
nsCacheService::MemoryDeviceSize,
"Memory used by the network memory cache.")
NS_IMPL_THREADSAFE_ISUPPORTS1(nsCacheService, nsICacheService)
nsCacheService::nsCacheService()
@ -1102,6 +1112,11 @@ nsCacheService::Shutdown()
// proceeding with destructive actions (bug #620660)
(void) SyncWithCacheIOThread();
// unregister memory reporter, before deleting the memory device, just
// to be safe
NS_UnregisterMemoryReporter(MemoryCacheReporter);
MemoryCacheReporter = nsnull;
// deallocate memory and disk caches
delete mMemoryDevice;
mMemoryDevice = nsnull;
@ -1443,6 +1458,11 @@ nsCacheService::CreateMemoryDevice()
delete mMemoryDevice;
mMemoryDevice = nsnull;
}
MemoryCacheReporter =
new NS_MEMORY_REPORTER_NAME(NetworkMemoryCache);
NS_RegisterMemoryReporter(MemoryCacheReporter);
return rv;
}
@ -1913,6 +1933,12 @@ nsCacheService::EnsureEntryHasDevice(nsCacheEntry * entry)
return device;
}
PRInt64
nsCacheService::MemoryDeviceSize()
{
nsMemoryCacheDevice *memoryDevice = GlobalInstance()->mMemoryDevice;
return memoryDevice ? memoryDevice->TotalSize() : 0;
}
nsresult
nsCacheService::DoomEntry(nsCacheEntry * entry)

View File

@ -131,6 +131,9 @@ public:
static
nsCacheService * GlobalInstance() { return gService; }
static
PRInt64 MemoryDeviceSize();
static nsresult DoomEntry(nsCacheEntry * entry);

View File

@ -307,6 +307,11 @@ nsMemoryCacheDevice::EntryIsTooBig(PRInt64 entrySize)
return (entrySize > mSoftLimit || entrySize > mMaxEntrySize);
}
size_t
nsMemoryCacheDevice::TotalSize()
{
return mTotalSize;
}
nsresult
nsMemoryCacheDevice::OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize)

View File

@ -91,6 +91,9 @@ public:
void SetMaxEntrySize(PRInt32 maxSizeInKilobytes);
bool EntryIsTooBig(PRInt64 entrySize);
size_t TotalSize();
private:
friend class nsMemoryCacheDeviceInfo;
enum { DELETE_ENTRY = PR_TRUE,

View File

@ -247,7 +247,7 @@ interface nsIMemoryReporterManager : nsISupports
/*
* Note that this defaults 'process' to "", which is usually what's desired.
*/
#define NS_MEMORY_REPORTER_IMPLEMENT(_classname, _path, _kind, _units, _amountFunction, _desc) \
#define NS_MEMORY_REPORTER_IMPLEMENT_HELPER(_classname, _path, _kind, _units, _amountFunction, _desc, _ts) \
class MemoryReporter_##_classname : public nsIMemoryReporter { \
public: \
NS_DECL_ISUPPORTS \
@ -258,7 +258,12 @@ interface nsIMemoryReporterManager : nsISupports
NS_IMETHOD GetAmount(PRInt64 *amount) { *amount = _amountFunction(); return NS_OK; } \
NS_IMETHOD GetDescription(nsACString &desc) { desc.Assign(_desc); return NS_OK; } \
}; \
NS_IMPL_ISUPPORTS1(MemoryReporter_##_classname, nsIMemoryReporter)
NS_IMPL##_ts##ISUPPORTS1(MemoryReporter_##_classname, nsIMemoryReporter)
#define NS_MEMORY_REPORTER_IMPLEMENT(_c, _p, _k, _u, _a, _d) \
NS_MEMORY_REPORTER_IMPLEMENT_HELPER(_c, _p, _k, _u, _a, _d, _)
#define NS_THREADSAFE_MEMORY_REPORTER_IMPLEMENT(_c, _p, _k, _u, _a, _d) \
NS_MEMORY_REPORTER_IMPLEMENT_HELPER(_c, _p, _k, _u, _a, _d, _THREADSAFE_)
#define NS_MEMORY_REPORTER_NAME(_classname) MemoryReporter_##_classname