From 74e3527fb2bdaca176c7b81df59d922e21ce7607 Mon Sep 17 00:00:00 2001 From: Aaron Klotz Date: Fri, 31 Jan 2014 20:14:51 -0700 Subject: [PATCH] Bug 902587 - Part 4: Changes to telemetry memory reporting; r=njn,froydnj --- toolkit/components/telemetry/Telemetry.cpp | 79 +++++++++++++++------- 1 file changed, 54 insertions(+), 25 deletions(-) diff --git a/toolkit/components/telemetry/Telemetry.cpp b/toolkit/components/telemetry/Telemetry.cpp index 7a3a1cea7791..8f5284590e1e 100644 --- a/toolkit/components/telemetry/Telemetry.cpp +++ b/toolkit/components/telemetry/Telemetry.cpp @@ -304,6 +304,25 @@ public: void AddPath(const nsAString& aPath); + /** + * Get size of hash table with file stats + */ + size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { + return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); + } + + size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { + size_t size; + size = mFileStats.SizeOfExcludingThis(SizeOfFileIOEntryTypeExcludingThis, + aMallocSizeOf) + + mSafeDirs.SizeOfExcludingThis(aMallocSizeOf); + uint32_t safeDirsLen = mSafeDirs.Length(); + for (uint32_t i = 0; i < safeDirsLen; ++i) { + size += mSafeDirs[i].SizeOfExcludingThisIfUnshared(aMallocSizeOf); + } + return size; + } + private: // Statistics for each filename AutoHashtable mFileStats; @@ -317,6 +336,13 @@ private: */ static bool ReflectFileStats(FileIOEntryType* entry, JSContext *cx, JS::Handle obj); + + static size_t SizeOfFileIOEntryTypeExcludingThis(FileIOEntryType* aEntry, + mozilla::MallocSizeOf mallocSizeOf, + void*) + { + return aEntry->GetKey().SizeOfExcludingThisIfUnshared(mallocSizeOf); + } }; TelemetryIOInterposeObserver::TelemetryIOInterposeObserver(nsIFile* aXreDir) @@ -585,31 +611,6 @@ TelemetryImpl::CollectReports(nsIHandleReportCallback* aHandleReport, "Memory used by the telemetry system."); } -size_t -TelemetryImpl::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) -{ - size_t n = aMallocSizeOf(this); - // Ignore the hashtables in mAddonMap; they are not significant. - n += mAddonMap.SizeOfExcludingThis(nullptr, aMallocSizeOf); - n += mHistogramMap.SizeOfExcludingThis(nullptr, aMallocSizeOf); - n += mPrivateSQL.SizeOfExcludingThis(nullptr, aMallocSizeOf); - n += mSanitizedSQL.SizeOfExcludingThis(nullptr, aMallocSizeOf); - n += mTrackedDBs.SizeOfExcludingThis(nullptr, aMallocSizeOf); - n += mHangReports.SizeOfExcludingThis(); - n += mThreadHangStats.sizeOfExcludingThis(aMallocSizeOf); - - // It's a bit gross that we measure this other stuff that lives outside of - // TelemetryImpl... oh well. - StatisticsRecorder::Histograms hs; - StatisticsRecorder::GetHistograms(&hs); - for (HistogramIterator it = hs.begin(); it != hs.end(); ++it) { - Histogram *h = *it; - n += h->SizeOfIncludingThis(aMallocSizeOf); - } - - return n; -} - // A initializer to initialize histogram collection StatisticsRecorder gStatisticsRecorder; @@ -2544,6 +2545,34 @@ TelemetryImpl::GetFileIOReports(JSContext *cx, JS::MutableHandleValue ret) return NS_OK; } +size_t +TelemetryImpl::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) +{ + size_t n = aMallocSizeOf(this); + // Ignore the hashtables in mAddonMap; they are not significant. + n += mAddonMap.SizeOfExcludingThis(nullptr, aMallocSizeOf); + n += mHistogramMap.SizeOfExcludingThis(nullptr, aMallocSizeOf); + n += mPrivateSQL.SizeOfExcludingThis(nullptr, aMallocSizeOf); + n += mSanitizedSQL.SizeOfExcludingThis(nullptr, aMallocSizeOf); + n += mTrackedDBs.SizeOfExcludingThis(nullptr, aMallocSizeOf); + n += mHangReports.SizeOfExcludingThis(); + n += mThreadHangStats.sizeOfExcludingThis(aMallocSizeOf); + + // It's a bit gross that we measure this other stuff that lives outside of + // TelemetryImpl... oh well. + if (sTelemetryIOObserver) { + n += sTelemetryIOObserver->SizeOfIncludingThis(aMallocSizeOf); + } + StatisticsRecorder::Histograms hs; + StatisticsRecorder::GetHistograms(&hs); + for (HistogramIterator it = hs.begin(); it != hs.end(); ++it) { + Histogram *h = *it; + n += h->SizeOfIncludingThis(aMallocSizeOf); + } + + return n; +} + } // anonymous namespace namespace mozilla {