Commit 13370095 authored by Alex Deymo's avatar Alex Deymo Committed by Commit Bot

Unify Blink.DecodedImage.JpegDensity.* metrics.

The Blink.DecodedImage.JpegDensity.100px, 400px and 1000px metrics count
the number of images per image bpp (bits per pixel) in the three
different categories of image size (decodec image >= 1000px, >= 400px and
>= 100px), requiring three different metrics to cover the spectrum.

A more direct approach introduced by this commit is to track the number
of KiB per image density, since this will allow us to focus on the image
compression density ranges (measured in bpp) that matter the most for
the user since they are the compression density ranges that take the
most network bandwidth. This also eliminates the need to have three
metrics and simplifies the analysis.

The old Blink.DecodedImage.JpegDensity.100px, 400px and 1000px are
marked as deprecated after the next release by this commit, allowing to
have both old and new metrics overlap for one full release (M78).

Bug: None
Test: Added unittests.
Change-Id: I6ead60fa9da3bc1b6080b12a6044c3ff9c8ce50e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1742160
Commit-Queue: Philip Rogers <pdr@chromium.org>
Reviewed-by: default avatarPrimiano Tucci <primiano@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690390}
parent b2dd2518
......@@ -223,7 +223,8 @@ Image::SizeAvailability BitmapImage::DataChanged(bool all_data_received) {
decoder_->FilenameExtension() == "jpg") {
BitmapImageMetrics::CountImageJpegDensity(
std::min(Size().Width(), Size().Height()),
ImageDensityInCentiBpp(Size(), decoder_->ByteSize()));
ImageDensityInCentiBpp(Size(), decoder_->ByteSize()),
decoder_->ByteSize());
}
// Feed all the data we've seen so far to the image decoder.
......
......@@ -45,9 +45,17 @@ void BitmapImageMetrics::CountImageOrientation(
}
void BitmapImageMetrics::CountImageJpegDensity(int image_min_side,
uint64_t density_centi_bpp) {
// Values are reported in the range 0.01 to 10 bpp, in different metrics
// depending on the image category (small, medium, large).
uint64_t density_centi_bpp,
size_t image_size_bytes) {
// All bpp samples are reported in the range 0.01 to 10 bpp as integer number
// of 0.01 bpp. We don't report for any sample for small images (0 to 99px on
// the smallest dimension).
//
// The histograms JpegDensity.1000px, JpegDensity.400px and JpegDensity.100px
// report the number of images decoded for a given bpp value.
//
// The histogram JpegDensity.KiBWeighted reports the number of KiB decoded for
// a given bpp value.
if (image_min_side >= 1000) {
DEFINE_THREAD_SAFE_STATIC_LOCAL(
CustomCountHistogram, density_histogram,
......@@ -69,6 +77,18 @@ void BitmapImageMetrics::CountImageJpegDensity(int image_min_side,
} else {
// We don't report for images with 0 to 99px on the smallest dimension.
}
if (image_min_side >= 100) {
DEFINE_THREAD_SAFE_STATIC_LOCAL(
CustomCountHistogram, density_histogram,
("Blink.DecodedImage.JpegDensity.KiBWeighted", 1, 1000, 100));
int image_size_kib = (image_size_bytes + 512) / 1024;
if (image_size_kib > 0) {
density_histogram.CountMany(
base::saturated_cast<base::Histogram::Sample>(density_centi_bpp),
image_size_kib);
}
}
}
void BitmapImageMetrics::CountJpegArea(const IntSize& size) {
......
......@@ -73,9 +73,11 @@ class PLATFORM_EXPORT BitmapImageMetrics {
static void CountDecodedImageType(const String& type);
static void CountImageOrientation(const ImageOrientationEnum);
// Report the JPEG compression density in 0.01 bits per pixel for an image
// with a smallest side (width or length) of |image_min_side|.
// with a smallest side (width or length) of |image_min_side| and total size
// in bytes |image_size_bytes|.
static void CountImageJpegDensity(int image_min_side,
uint64_t density_centi_bpp);
uint64_t density_centi_bpp,
size_t image_size_bytes);
static void CountJpegArea(const IntSize& size);
static void CountJpegColorSpace(JpegColorSpace color_space);
};
......
......@@ -788,8 +788,17 @@ TEST_F(BitmapImageTestWithMockDecoder, PaintImageForStaticBitmapImage) {
template <typename HistogramEnumType>
struct HistogramTestParams {
HistogramTestParams(const char* filename, HistogramEnumType type, int count)
: filename(filename), type(type), count(count) {}
HistogramTestParams(const char* filename, HistogramEnumType type)
: HistogramTestParams(filename, type, 1) {}
const char* filename;
HistogramEnumType type;
// The number of events reported in the histogram when |type| is not
// kNoSamplesReported, otherwise is ignored.
int count;
};
template <typename HistogramEnumType>
......@@ -810,7 +819,7 @@ class BitmapHistogramTest : public BitmapImageTest,
histogram_tester.ExpectTotalCount(histogram_name, 0);
} else {
histogram_tester.ExpectUniqueSample(histogram_name, this->GetParam().type,
1);
this->GetParam().count);
}
}
};
......@@ -905,4 +914,25 @@ INSTANTIATE_TEST_SUITE_P(
DecodedImageDensityHistogramTest400px,
testing::ValuesIn(kDecodedImageDensityHistogramTest400pxParams));
using DecodedImageDensityHistogramTestKiBWeighted = BitmapHistogramTest<int>;
TEST_P(DecodedImageDensityHistogramTestKiBWeighted, JpegDensity) {
RunTest("Blink.DecodedImage.JpegDensity.KiBWeighted");
}
const DecodedImageDensityHistogramTestKiBWeighted::ParamType
kDecodedImageDensityHistogramTestKiBWeightedParams[] = {
// 64x64 too small to report any metric
{"rgb-jpeg-red.jpg",
DecodedImageDensityHistogramTest100px::kNoSamplesReported},
// 439x154, 23220 bytes --> 2.74 bpp, 23 KiB (rounded up)
{"cropped_mandrill.jpg", 274, 23},
// 320x320, 74017 bytes --> 5.78, 72 KiB (rounded down)
{"blue-wheel-srgb-color-profile.jpg", 578, 72}};
INSTANTIATE_TEST_SUITE_P(
DecodedImageDensityHistogramTestKiBWeighted,
DecodedImageDensityHistogramTestKiBWeighted,
testing::ValuesIn(kDecodedImageDensityHistogramTestKiBWeightedParams));
} // namespace blink
......@@ -26,6 +26,11 @@ void CustomCountHistogram::Count(base::HistogramBase::Sample sample) {
histogram_->Add(sample);
}
void CustomCountHistogram::CountMany(base::HistogramBase::Sample sample,
int count) {
histogram_->AddCount(sample, count);
}
void CustomCountHistogram::CountMicroseconds(base::TimeDelta delta) {
Count(base::saturated_cast<base::HistogramBase::Sample>(
delta.InMicroseconds()));
......
......@@ -29,6 +29,7 @@ class PLATFORM_EXPORT CustomCountHistogram {
base::HistogramBase::Sample max,
int32_t bucket_count);
void Count(base::HistogramBase::Sample);
void CountMany(base::HistogramBase::Sample, int count);
void CountMicroseconds(base::TimeDelta);
void CountMilliseconds(base::TimeDelta);
......
......@@ -13814,7 +13814,10 @@ uploading your change for review.
</histogram>
<histogram name="Blink.DecodedImage.JpegDensity.1000px"
units="0.01 bits per pixel" expires_after="2020-02-16">
units="0.01 bits per pixel" expires_after="M78">
<obsolete>
Deprecated in M79. Replaced by Blink.DecodedImage.JpegDensity.KiBWeighted.
</obsolete>
<owner>deymo@google.com</owner>
<owner>compression-dev@google.com</owner>
<summary>
......@@ -13825,7 +13828,10 @@ uploading your change for review.
</histogram>
<histogram name="Blink.DecodedImage.JpegDensity.100px"
units="0.01 bits per pixel" expires_after="2020-02-02">
units="0.01 bits per pixel" expires_after="M78">
<obsolete>
Deprecated in M79. Replaced by Blink.DecodedImage.JpegDensity.KiBWeighted.
</obsolete>
<owner>deymo@google.com</owner>
<owner>compression-dev@google.com</owner>
<summary>
......@@ -13837,7 +13843,10 @@ uploading your change for review.
</histogram>
<histogram name="Blink.DecodedImage.JpegDensity.400px"
units="0.01 bits per pixel" expires_after="2020-01-26">
units="0.01 bits per pixel" expires_after="M78">
<obsolete>
Deprecated in M79. Replaced by Blink.DecodedImage.JpegDensity.KiBWeighted.
</obsolete>
<owner>deymo@google.com</owner>
<owner>compression-dev@google.com</owner>
<summary>
......@@ -13848,6 +13857,19 @@ uploading your change for review.
</summary>
</histogram>
<histogram name="Blink.DecodedImage.JpegDensity.KiBWeighted"
units="0.01 bits per pixel" expires_after="2020-08-08">
<owner>deymo@google.com</owner>
<owner>compression-dev@google.com</owner>
<summary>
The compressed image size in KiB per image density measured in 0.01 bits per
pixel. This is logged once per image load after the whole image is loaded
and only for JPEGs with at least 100 pixels on the smallest dimension (width
or height). The reported count for a sample represents the image size
rounded to the nearest KiB.
</summary>
</histogram>
<histogram name="Blink.DecodedImage.Orientation" enum="DecodedImageOrientation">
<owner>andrescj@chromium.org</owner>
<owner>rob.buis@samsung.org</owner>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment