From f4a03626ab6d3b9b78efa2df0fb41244114d7fdf Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 15 Mar 2017 00:12:07 -0400 Subject: [PATCH] Bug 1347400 - Add telemetry for imgLoader::LoadImage(); r=mystor,francois --- image/imgLoader.cpp | 12 +++++++++++- toolkit/components/telemetry/Histograms.json | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/image/imgLoader.cpp b/image/imgLoader.cpp index d6b4ec5b7711..9a7f2a7e9a40 100644 --- a/image/imgLoader.cpp +++ b/image/imgLoader.cpp @@ -12,6 +12,7 @@ #include "mozilla/Move.h" #include "mozilla/Preferences.h" #include "mozilla/ChaosMode.h" +#include "mozilla/Telemetry.h" #include "nsImageModule.h" #include "imgRequestProxy.h" @@ -2063,6 +2064,12 @@ imgLoader::LoadImage(nsIURI* aURI, const nsAString& initiatorType, imgRequestProxy** _retval) { + // Note: We round the time to the nearest milliseconds. Due to this rounding, + // the actual minimum value is 500 microseconds. + static const uint32_t kMinTelemetryLatencyMs = 1; + + mozilla::TimeStamp start = TimeStamp::Now(); + VerifyCacheSizes(); NS_ASSERTION(aURI, "imgLoader::LoadImage -- NULL URI pointer"); @@ -2298,8 +2305,11 @@ imgLoader::LoadImage(nsIURI* aURI, if (!newChannel) { proxy->NotifyListener(); } + } - return rv; + uint32_t latencyMs = round((TimeStamp::Now() - start).ToMilliseconds()); + if (XRE_IsContentProcess() && latencyMs >= kMinTelemetryLatencyMs) { + Telemetry::Accumulate(Telemetry::IMAGE_LOAD_TRIGGER_LATENCY_MS, latencyMs); } NS_ASSERTION(*_retval, "imgLoader::LoadImage -- no return value"); diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index 5fa0132a4e38..d76c44cfef3f 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -1482,6 +1482,16 @@ "n_buckets": 50, "description": "GIF image decode speed (Kbytes/sec)" }, + "IMAGE_LOAD_TRIGGER_LATENCY_MS": { + "alert_emails": ["ehsan@mozilla.com"], + "expires_in_version": "60", + "bug_numbers": [1347376], + "kind": "exponential", + "low": 1, + "high": 1000, + "n_buckets": 50, + "description": "Measures the number of milliseconds we spend inside imgLoader::LoadImage(). Note: only calls that take more than 500 microseconds and happen in the content process are included in this probe." + }, "IMAGE_DECODE_SPEED_PNG": { "expires_in_version": "never", "kind": "exponential",