mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 1346486 - Add a memory reporter for PSM DataStorage caches; r=keeler
This commit is contained in:
parent
352feff91a
commit
99f016e209
@ -17,9 +17,11 @@
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsDirectoryServiceUtils.h"
|
||||
#include "nsIMemoryReporter.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nsStreamUtils.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
@ -36,8 +38,36 @@ static const int64_t sOneDayInMicroseconds = int64_t(24 * 60 * 60) *
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
NS_IMPL_ISUPPORTS(DataStorage,
|
||||
nsIObserver)
|
||||
class DataStorageMemoryReporter final : public nsIMemoryReporter
|
||||
{
|
||||
MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf)
|
||||
~DataStorageMemoryReporter() = default;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
|
||||
nsISupports* aData, bool aAnonymize) final
|
||||
{
|
||||
nsTArray<nsString> fileNames;
|
||||
DataStorage::GetAllFileNames(fileNames);
|
||||
for (const auto& file: fileNames) {
|
||||
RefPtr<DataStorage> ds = DataStorage::Get(file);
|
||||
size_t amount = ds->SizeOfIncludingThis(MallocSizeOf);
|
||||
nsPrintfCString path("explicit/data-storage/%s",
|
||||
NS_ConvertUTF16toUTF8(file).get());
|
||||
Unused << aHandleReport->Callback(EmptyCString(), path, KIND_HEAP,
|
||||
UNITS_BYTES, amount,
|
||||
NS_LITERAL_CSTRING("Memory used by PSM data storage cache."),
|
||||
aData);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(DataStorageMemoryReporter, nsIMemoryReporter)
|
||||
|
||||
NS_IMPL_ISUPPORTS(DataStorage, nsIObserver)
|
||||
|
||||
StaticAutoPtr<DataStorage::DataStorages> DataStorage::sDataStorages;
|
||||
|
||||
@ -113,6 +143,17 @@ DataStorage::SetCachedStorageEntries(
|
||||
}
|
||||
}
|
||||
|
||||
size_t
|
||||
DataStorage::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
||||
{
|
||||
size_t sizeOfExcludingThis =
|
||||
mPersistentDataTable.ShallowSizeOfExcludingThis(aMallocSizeOf) +
|
||||
mTemporaryDataTable.ShallowSizeOfExcludingThis(aMallocSizeOf) +
|
||||
mPrivateDataTable.ShallowSizeOfExcludingThis(aMallocSizeOf) +
|
||||
mFilename.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
||||
return aMallocSizeOf(this) + sizeOfExcludingThis;
|
||||
}
|
||||
|
||||
nsresult
|
||||
DataStorage::Init(bool& aDataWillPersist,
|
||||
const InfallibleTArray<mozilla::dom::DataStorageItem>* aItems)
|
||||
@ -132,6 +173,16 @@ DataStorage::Init(bool& aDataWillPersist,
|
||||
|
||||
mInitCalled = true;
|
||||
|
||||
static bool memoryReporterRegistered = false;
|
||||
if (!memoryReporterRegistered) {
|
||||
nsresult rv =
|
||||
RegisterStrongMemoryReporter(new DataStorageMemoryReporter());
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
memoryReporterRegistered = true;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
if (XRE_IsParentProcess()) {
|
||||
MOZ_ASSERT(!aItems);
|
||||
|
@ -8,6 +8,7 @@
|
||||
#define mozilla_DataStorage_h
|
||||
|
||||
#include "mozilla/Atomics.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/Monitor.h"
|
||||
#include "mozilla/Mutex.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
@ -132,6 +133,8 @@ public:
|
||||
// Set the cached copy of our DataStorage entries in the content process.
|
||||
static void SetCachedStorageEntries(const InfallibleTArray<mozilla::dom::DataStorageEntry>& aEntries);
|
||||
|
||||
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
||||
|
||||
private:
|
||||
explicit DataStorage(const nsString& aFilename);
|
||||
virtual ~DataStorage();
|
||||
|
Loading…
Reference in New Issue
Block a user