Bug 1472145 - Part 2. Add telemetry to track how frequently WebP images are used. r=tnikkel data-r=chutten

This patch adds three telemetry scalars to track how WebP is used. All
of these scalars are updated when we do the MIME type confirmation for
an imgRequest when the first data comes in. We know at this point we
decided to load the given content, so there should be minimal false
positives for data the browser loaded but never displayed.

The first two scalars are merely whether or not WebP was observed. One
is for probes, which are tiny WebP images suggested by the Google WebP
FAQ to probe for different aspects of WebP support (lossy, animated,
etc). We want to count this separately as actual WebP content that the
website wishes us to display. Probes will give a measure of how many
users visit websites that probe for WebP support, and content will give
a measure of how many websites don't care and just give us WebP images
regardless.

The third scalar is intended to give a relative measure of how many WebP
images we are being served relative to all other image types. We expect
the ratio to be small, but it would be good to confirm this from the
data.
This commit is contained in:
Andrew Osmond 2018-06-29 20:30:08 -04:00
Родитель c7ece5c2e5
Коммит b13b2abe4f
2 изменённых файлов: 88 добавлений и 0 удалений

Просмотреть файл

@ -39,6 +39,7 @@
#include "imgIRequest.h"
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/Telemetry.h"
using namespace mozilla;
using namespace mozilla::image;
@ -940,6 +941,7 @@ imgRequest::OnStopRequest(nsIRequest* aRequest,
struct mimetype_closure
{
nsACString* newType;
uint32_t segmentSize;
};
/* prototype for these defined below */
@ -986,11 +988,49 @@ PrepareForNewPart(nsIRequest* aRequest, nsIInputStream* aInStr, uint32_t aCount,
if (aInStr) {
mimetype_closure closure;
closure.newType = &result.mContentType;
closure.segmentSize = 0;
// Look at the first few bytes and see if we can tell what the data is from
// that since servers tend to lie. :(
uint32_t out;
aInStr->ReadSegments(sniff_mimetype_callback, &closure, aCount, &out);
// We don't support WebP but we are getting reports of Firefox being served
// WebP content in the wild. In particular this appears to be a problem on
// Fennec where content authors assume Android implies WebP support. The
// telemetry below is intended to get a sense of how prevalent this is.
//
// From the Google WebP FAQ example and the Modernizr library, websites may
// supply a tiny WebP image to probe for feature support using scripts. The
// probes are implemented as data URIs thus we should have all the content
// upfront. We don't want to consider a probe as having observed WebP since
// in theory the client should do the right thing when we fail to decode it.
// See https://developers.google.com/speed/webp/faq for details.
bool webp = result.mContentType.EqualsLiteral(IMAGE_WEBP);
bool webpProbe = false;
if (webp) {
// The probes from the example/library are all < 90 bytes. Round it up
// just in case.
const uint32_t kMaxProbeSize = 100;
if (closure.segmentSize < kMaxProbeSize &&
NS_FAILED(aURI->SchemeIs("data", &webpProbe))) {
webpProbe = false;
}
if (webpProbe) {
Telemetry::ScalarSet(Telemetry::ScalarID::IMAGES_WEBP_PROBE_OBSERVED,
true);
} else {
Telemetry::ScalarSet(Telemetry::ScalarID::IMAGES_WEBP_CONTENT_OBSERVED,
true);
}
}
if (!webpProbe) {
Telemetry::ScalarAdd(Telemetry::ScalarID::IMAGES_WEBP_CONTENT_FREQUENCY,
webp ? NS_LITERAL_STRING("webp") :
NS_LITERAL_STRING("other"), 1);
}
}
nsCOMPtr<nsIChannel> chan(do_QueryInterface(aRequest));
@ -1241,6 +1281,7 @@ sniff_mimetype_callback(nsIInputStream* in,
NS_ASSERTION(closure, "closure is null!");
closure->segmentSize = count;
if (count > 0) {
imgLoader::GetMimeTypeFromContent(fromRawSegment, count, *closure->newType);
}

Просмотреть файл

@ -1441,6 +1441,53 @@ gfx.omtp:
record_in_processes:
- 'content'
images.webp:
probe_observed:
bug_numbers:
- 1472145
description: >
Whether we received a probe detecting our WebP image support.
kind: boolean
expires: "65"
notification_emails:
- gfx-telemetry-alerts@mozilla.com
- aosmond@mozilla.com
release_channel_collection: opt-out
record_in_processes:
- 'main'
- 'content'
content_observed:
bug_numbers:
- 1472145
description: >
Whether we received a request to decode a WebP image, excluding probes.
kind: boolean
expires: "65"
notification_emails:
- gfx-telemetry-alerts@mozilla.com
- aosmond@mozilla.com
release_channel_collection: opt-out
record_in_processes:
- 'main'
- 'content'
content_frequency:
bug_numbers:
- 1472145
description: >
How many image requests are WebP images, excluding probes.
kind: uint
keyed: true
expires: "65"
notification_emails:
- gfx-telemetry-alerts@mozilla.com
- aosmond@mozilla.com
release_channel_collection: opt-out
record_in_processes:
- 'main'
- 'content'
# The following section contains the form autofill related scalars.
formautofill:
availability: