5aa1628e82232fab9951a2895094a216661271f4 - chromium/src

0 views
Skip to first unread message

xida...@chromium.org

unread,
May 25, 2016, 11:43:50 PM5/25/16
to chromium...@chromium.org
commit 5aa1628e82232fab9951a2895094a216661271f4
Author: xidachen <xida...@chromium.org>
AuthorDate: Thu May 26 03:40:36 2016
Commit: Commit bot <commi...@chromium.org>
CommitDate: Thu May 26 03:42:47 2016

Adding performance tracking for canvas API calls

In this CL, we add timer to some of the expensive API calls in 2d canvas.
These API calls includes:
1. drawImage
2. createImageData
3. getImageData
4. putImageData
5. toDataURL

Measuring toBlob will be in another CL, it is more complicated than this
because of its idle scheduling scheme.

BUG=612585

Review-Url: https://codereview.chromium.org/1992253002
Cr-Commit-Position: refs/heads/master@{#396105}

diff --git a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
index 72bf336..ceebfd5 100644
--- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
@@ -612,6 +612,36 @@
exceptionState.throwSecurityError("Tainted canvases may not be exported.");
return String();
}
+ Optional<ScopedUsHistogramTimer> timer;
+ String lowercaseMimeType = mimeType.lower();
+ if (mimeType.isNull())
+ lowercaseMimeType = DefaultMimeType;
+ if (lowercaseMimeType == "image/png") {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterPNG, new CustomCountHistogram("Blink.Canvas.ToDataURL.PNG", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterPNG);
+ } else if (lowercaseMimeType == "image/jpeg") {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterJPEG, new CustomCountHistogram("Blink.Canvas.ToDataURL.JPEG", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterJPEG);
+ } else if (lowercaseMimeType == "image/webp") {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterWEBP, new CustomCountHistogram("Blink.Canvas.ToDataURL.WEBP", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterWEBP);
+ } else if (lowercaseMimeType == "image/gif") {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterGIF, new CustomCountHistogram("Blink.Canvas.ToDataURL.GIF", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterGIF);
+ } else if (lowercaseMimeType == "image/bmp" || lowercaseMimeType == "image/x-windows-bmp") {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterBMP, new CustomCountHistogram("Blink.Canvas.ToDataURL.BMP", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterBMP);
+ } else if (lowercaseMimeType == "image/x-icon") {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterICON, new CustomCountHistogram("Blink.Canvas.ToDataURL.ICON", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterICON);
+ } else if (lowercaseMimeType == "image/tiff" || lowercaseMimeType == "image/x-tiff") {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterTIFF, new CustomCountHistogram("Blink.Canvas.ToDataURL.TIFF", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterTIFF);
+ } else {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterUnknown, new CustomCountHistogram("Blink.Canvas.ToDataURL.Unknown", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterUnknown);
+ }
+
double quality = UndefinedQualityValue;
if (!qualityArgument.isEmpty()) {
v8::Local<v8::Value> v8Value = qualityArgument.v8Value();
diff --git a/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp b/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
index 29c48be..d54204e 100644
--- a/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
+++ b/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
@@ -17,6 +17,7 @@
#include "modules/canvas2d/CanvasPattern.h"
#include "modules/canvas2d/CanvasStyle.h"
#include "modules/canvas2d/Path2D.h"
+#include "platform/Histogram.h"
#include "platform/geometry/FloatQuad.h"
#include "platform/graphics/Color.h"
#include "platform/graphics/ExpensiveCanvasHeuristicParameters.h"
@@ -988,6 +989,62 @@
if (!drawingCanvas())
return;

+ // TODO(xidachen): After collecting some data, come back and prune off
+ // the ones that is not needed.
+ Optional<ScopedUsHistogramTimer> timer;
+ if (imageBuffer() && imageBuffer()->isAccelerated()) {
+ if (imageSource->isVideoElement()) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterVideoGPU, new CustomCountHistogram("Blink.Canvas.DrawImage.Video.GPU", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterVideoGPU);
+ } else if (imageSource->isCanvasElement()) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterCanvasGPU, new CustomCountHistogram("Blink.Canvas.DrawImage.Canvas.GPU", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterCanvasGPU);
+ } else if (imageSource->isSVGSource()) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterSVGGPU, new CustomCountHistogram("Blink.Canvas.DrawImage.SVG.GPU", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterSVGGPU);
+ } else if (imageSource->isImageBitmap()) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterImageBitmapGPU, new CustomCountHistogram("Blink.Canvas.DrawImage.ImageBitmap.GPU", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterImageBitmapGPU);
+ } else {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterOthersGPU, new CustomCountHistogram("Blink.Canvas.DrawImage.Others.GPU", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterOthersGPU);
+ }
+ } else if (imageBuffer() && imageBuffer()->isRecording()) {
+ if (imageSource->isVideoElement()) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterVideoDisplayList, new CustomCountHistogram("Blink.Canvas.DrawImage.Video.DisplayList", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterVideoDisplayList);
+ } else if (imageSource->isCanvasElement()) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterCanvasDisplayList, new CustomCountHistogram("Blink.Canvas.DrawImage.Canvas.DisplayList", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterCanvasDisplayList);
+ } else if (imageSource->isSVGSource()) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterSVGDisplayList, new CustomCountHistogram("Blink.Canvas.DrawImage.SVG.DisplayList", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterSVGDisplayList);
+ } else if (imageSource->isImageBitmap()) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterImageBitmapDisplayList, new CustomCountHistogram("Blink.Canvas.DrawImage.ImageBitmap.DisplayList", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterImageBitmapDisplayList);
+ } else {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterOthersDisplayList, new CustomCountHistogram("Blink.Canvas.DrawImage.Others.DisplayList", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterOthersDisplayList);
+ }
+ } else {
+ if (imageSource->isVideoElement()) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterVideoCPU, new CustomCountHistogram("Blink.Canvas.DrawImage.Video.CPU", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterVideoCPU);
+ } else if (imageSource->isCanvasElement()) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterCanvasCPU, new CustomCountHistogram("Blink.Canvas.DrawImage.Canvas.CPU", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterCanvasCPU);
+ } else if (imageSource->isSVGSource()) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterSVGCPU, new CustomCountHistogram("Blink.Canvas.DrawImage.SVG.CPU", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterSVGCPU);
+ } else if (imageSource->isImageBitmap()) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterImageBitmapCPU, new CustomCountHistogram("Blink.Canvas.DrawImage.ImageBitmap.CPU", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterImageBitmapCPU);
+ } else {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterOthersCPU, new CustomCountHistogram("Blink.Canvas.DrawImage.Others.CPU", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterOthersCPU);
+ }
+ }
+
RefPtr<Image> image;
FloatSize defaultObjectSize(width(), height());
SourceImageStatus sourceImageStatus = InvalidSourceImageStatus;
@@ -1190,6 +1247,18 @@

ImageData* BaseRenderingContext2D::getImageData(double sx, double sy, double sw, double sh, ExceptionState& exceptionState) const
{
+ Optional<ScopedUsHistogramTimer> timer;
+ if (imageBuffer() && imageBuffer()->isAccelerated()) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterGPU, new CustomCountHistogram("Blink.Canvas.GetImageData.GPU", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterGPU);
+ } else if (imageBuffer() && imageBuffer()->isRecording()) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterDisplayList, new CustomCountHistogram("Blink.Canvas.GetImageData.DisplayList", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterDisplayList);
+ } else {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterCPU, new CustomCountHistogram("Blink.Canvas.GetImageData.CPU", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterCPU);
+ }
+
if (!originClean())
exceptionState.throwSecurityError("The canvas has been tainted by cross-origin data.");
else if (!sw || !sh)
@@ -1243,6 +1312,18 @@

void BaseRenderingContext2D::putImageData(ImageData* data, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight, ExceptionState& exceptionState)
{
+ Optional<ScopedUsHistogramTimer> timer;
+ if (imageBuffer() && imageBuffer()->isAccelerated()) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterGPU, new CustomCountHistogram("Blink.Canvas.PutImageData.GPU", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterGPU);
+ } else if (imageBuffer() && imageBuffer()->isRecording()) {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterDisplayList, new CustomCountHistogram("Blink.Canvas.PutImageData.DisplayList", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterDisplayList);
+ } else {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterCPU, new CustomCountHistogram("Blink.Canvas.PutImageData.CPU", 0, 10000000, 50));
+ timer.emplace(scopedUsCounterCPU);
+ }
+
if (data->data()->bufferBase()->isNeutered()) {
exceptionState.throwDOMException(InvalidStateError, "The source data has been neutered.");
return;
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index 96df540..190f2f2 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -3445,6 +3445,26 @@
<summary>Time spent initializing WindowProxy during a page loading.</summary>
</histogram>

+<histogram name="Blink.Canvas.DrawImage" units="microseconds">
+ <owner>ju...@chromium.org</owner>
+ <summary>Time spent on 2D canvas drawImage API call.</summary>
+</histogram>
+
+<histogram name="Blink.Canvas.GetImageData" units="microseconds">
+ <owner>ju...@chromium.org</owner>
+ <summary>Time spent on 2D canvas getImageData API call.</summary>
+</histogram>
+
+<histogram name="Blink.Canvas.PutImageData" units="microseconds">
+ <owner>ju...@chromium.org</owner>
+ <summary>Time spent on 2D canvas putImageData API call.</summary>
+</histogram>
+
+<histogram name="Blink.Canvas.ToDataURL" units="microseconds">
+ <owner>ju...@chromium.org</owner>
+ <summary>Time spent on 2D canvas toDataURL API call.</summary>
+</histogram>
+
<histogram name="Blink.Compositing.UpdateTime" units="microseconds">
<owner>pain...@chromium.org</owner>
<summary>
@@ -91255,6 +91275,40 @@
<affected-histogram name="WebRTC.Stun.BatchSuccessPercent.UnknownNAT"/>
</histogram_suffixes>

+<histogram_suffixes name="BlinkCanvasDrawImageType" separator=".">
+ <suffix name="Canvas"/>
+ <suffix name="ImageBitmap"/>
+ <suffix name="Others"/>
+ <suffix name="SVG"/>
+ <suffix name="Video"/>
+ <affected-histogram name="Blink.Canvas.DrawImage"/>
+</histogram_suffixes>
+
+<histogram_suffixes name="BlinkCanvasDurationBySource" separator=".">
+ <suffix name="CPU"/>
+ <suffix name="DisplayList"/>
+ <suffix name="GPU"/>
+ <affected-histogram name="Blink.Canvas.DrawImage.Canvas"/>
+ <affected-histogram name="Blink.Canvas.DrawImage.ImageBitmap"/>
+ <affected-histogram name="Blink.Canvas.DrawImage.Others"/>
+ <affected-histogram name="Blink.Canvas.DrawImage.SVG"/>
+ <affected-histogram name="Blink.Canvas.DrawImage.Video"/>
+ <affected-histogram name="Blink.Canvas.GetImageData"/>
+ <affected-histogram name="Blink.Canvas.PutImageData"/>
+</histogram_suffixes>
+
+<histogram_suffixes name="BlinkCanvasToDataURLTime" separator=".">
+ <suffix name="BMP"/>
+ <suffix name="GIF"/>
+ <suffix name="ICON"/>
+ <suffix name="JPEG"/>
+ <suffix name="PNG"/>
+ <suffix name="TIFF"/>
+ <suffix name="Unknown"/>
+ <suffix name="WEBP"/>
+ <affected-histogram name="Blink.Canvas.ToDataURL"/>
+</histogram_suffixes>
+
<histogram_suffixes name="BlinkGCReason">
<suffix name="IdleGC" label="Idle GC"/>
<suffix name="PreciseGC" label="Precise GC"/>
Reply all
Reply to author
Forward
0 new messages