From ef186fb5e9b0bb134656cef5723c94cdb15b2a72 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Sun, 22 May 2011 08:24:32 +0200 Subject: [PATCH] Bug 657297 part 2 - Add telemetry samples for initial I/O counters. r=tglek --- browser/app/nsBrowserApp.cpp | 43 +++++++++++++++++-- .../telemetry/TelemetryHistograms.h | 9 ++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/browser/app/nsBrowserApp.cpp b/browser/app/nsBrowserApp.cpp index 78cca4760eb..19da11f9848 100644 --- a/browser/app/nsBrowserApp.cpp +++ b/browser/app/nsBrowserApp.cpp @@ -38,9 +38,12 @@ #include "nsXPCOMGlue.h" #include "nsXULAppAPI.h" -#ifdef XP_WIN +#if defined(XP_WIN) #include #include +#elif defined(XP_UNIX) +#include +#include #endif #include @@ -65,6 +68,8 @@ #include "nsXPCOMPrivate.h" // for MAXPATHLEN and XPCOM_DLL +#include "mozilla/Telemetry.h" + static void Output(const char *fmt, ... ) { va_list ap; @@ -117,6 +122,7 @@ XRE_FreeAppDataType XRE_FreeAppData; #ifdef XRE_HAS_DLL_BLOCKLIST XRE_SetupDllBlocklistType XRE_SetupDllBlocklist; #endif +XRE_TelemetryAccumulateType XRE_TelemetryAccumulate; XRE_mainType XRE_main; static const nsDynamicFunctionLoad kXULFuncs[] = { @@ -126,6 +132,7 @@ static const nsDynamicFunctionLoad kXULFuncs[] = { #ifdef XRE_HAS_DLL_BLOCKLIST { "XRE_SetupDllBlocklist", (NSFuncPtr*) &XRE_SetupDllBlocklist }, #endif + { "XRE_TelemetryAccumulate", (NSFuncPtr*) &XRE_TelemetryAccumulate }, { "XRE_main", (NSFuncPtr*) &XRE_main }, { nsnull, nsnull } }; @@ -209,15 +216,19 @@ int main(int argc, char* argv[]) strcpy(++lastSlash, XPCOM_DLL); -#ifdef XP_WIN + int gotCounters; +#if defined(XP_UNIX) + struct rusage initialRUsage; + gotCounters = !getrusage(RUSAGE_SELF, &initialRUsage); +#elif defined(XP_WIN) // GetProcessIoCounters().ReadOperationCount seems to have little to // do with actual read operations. It reports 0 or 1 at this stage // in the program. Luckily 1 coincides with when prefetch is // enabled. If Windows prefetch didn't happen we can do our own // faster dll preloading. IO_COUNTERS ioCounters; - if (GetProcessIoCounters(GetCurrentProcess(), &ioCounters) - && !ioCounters.ReadOperationCount) + gotCounters = GetProcessIoCounters(GetCurrentProcess(), &ioCounters); + if (gotCounters && !ioCounters.ReadOperationCount) #endif { XPCOMGlueEnablePreload(); @@ -240,6 +251,30 @@ int main(int argc, char* argv[]) XRE_SetupDllBlocklist(); #endif + if (gotCounters) { +#if defined(XP_WIN) + XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_READ_OPS, + int(ioCounters.ReadOperationCount)); + XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_READ_TRANSFER, + int(ioCounters.ReadTransferCount / 1024)); + IO_COUNTERS newIoCounters; + if (GetProcessIoCounters(GetCurrentProcess(), &newIoCounters)) { + XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_READ_OPS, + int(newIoCounters.ReadOperationCount - ioCounters.ReadOperationCount)); + XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_READ_TRANSFER, + int((newIoCounters.ReadTransferCount - ioCounters.ReadTransferCount) / 1024)); + } +#elif defined(XP_UNIX) + XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_HARD_FAULTS, + int(initialRUsage.ru_majflt)); + struct rusage newRUsage; + if (!getrusage(RUSAGE_SELF, &newRUsage)) { + XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_HARD_FAULTS, + int(newRUsage.ru_majflt - initialRUsage.ru_majflt)); + } +#endif + } + int result; { ScopedLogging log; diff --git a/toolkit/components/telemetry/TelemetryHistograms.h b/toolkit/components/telemetry/TelemetryHistograms.h index 739e8a28f0a..7238abf0884 100644 --- a/toolkit/components/telemetry/TelemetryHistograms.h +++ b/toolkit/components/telemetry/TelemetryHistograms.h @@ -48,3 +48,12 @@ HISTOGRAM(TELEMETRY_SUCCESS, 0, 1, 2, BOOLEAN, "Success(No, Yes) rate of teleme HISTOGRAM(MEMORY_JS_GC_HEAP, 1024, 512 * 1024, 10, EXPONENTIAL, "Memory(MB) used by the JavaScript GC") HISTOGRAM(MEMORY_RESIDENT, 32 * 1024, 1024 * 1024, 10, EXPONENTIAL, "Resident memory(MB) reported by OS") HISTOGRAM(MEMORY_LAYOUT_ALL, 1024, 64 * 1024, 10, EXPONENTIAL, "Memory(MB) reported used by layout") +#if defined(XP_WIN) +HISTOGRAM(EARLY_GLUESTARTUP_READ_OPS, 1, 100, 12, LINEAR, "ProcessIoCounters.ReadOperationCount before glue startup") +HISTOGRAM(EARLY_GLUESTARTUP_READ_TRANSFER, 1, 50 * 1024, 12, EXPONENTIAL, "ProcessIoCounters.ReadTransferCount before glue startup (KB)") +HISTOGRAM(GLUESTARTUP_READ_OPS, 1, 100, 12, LINEAR, "ProcessIoCounters.ReadOperationCount after glue startup") +HISTOGRAM(GLUESTARTUP_READ_TRANSFER, 1, 50 * 1024, 12, EXPONENTIAL, "ProcessIoCounters.ReadTransferCount after glue startup (KB)") +#elif defined(XP_UNIX) +HISTOGRAM(EARLY_GLUESTARTUP_HARD_FAULTS, 1, 100, 12, LINEAR, "Hard faults count before glue startup") +HISTOGRAM(GLUESTARTUP_HARD_FAULTS, 1, 500, 12, EXPONENTIAL, "Hard faults count after glue startup") +#endif