Add Histogram Macros to Skia

Adds a set of histogram macros to Skia, modeled after Chrome's
UMA_HISTOGRAM_* macros. These allow logging of high frequency events,
and are useful to analyze real world usage of certain features.

By default, these macros are no-ops. Users can provide a custom
header file which defines these macros if they wish to collect
histogram data. Chrome will provide such a header.

I've currently only added two macros:
- SK_HISTOGRAM_BOOLEAN - logs a true/false type relationship (whether
we are tiling a texture or not on each draw).
- SK_HISTOGRAM_ENUMERATION - logs a set of potential values (which of
a number of choices were selected for the texture upload path).

We could add more unused macros at the moment, but it seems easier to
add these as needed, WDYT?

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1652053004

Review URL: https://codereview.chromium.org/1652053004
This commit is contained in:
ericrk 2016-02-05 15:32:36 -08:00 committed by Commit bot
parent 60dcd3cb85
commit 369e9375a3
5 changed files with 50 additions and 0 deletions

View File

@ -146,4 +146,12 @@
*/ */
//#define SK_PDF_USE_PATHOPS_CLIPPING //#define SK_PDF_USE_PATHOPS_CLIPPING
/* Skia makes use of histogram logging macros to trace the frequency of
* events. By default, Skia provides no-op versions of these macros.
* Skia consumers can provide their own definitions of these macros to
* integrate with their histogram collection backend.
*/
//#define SK_HISTOGRAM_BOOLEAN(name, value)
//#define SK_HISTOGRAM_ENUMERATION(name, value, boundary_value)
#endif #endif

View File

@ -344,4 +344,14 @@
# define GR_TEST_UTILS 1 # define GR_TEST_UTILS 1
#endif #endif
//////////////////////////////////////////////////////////////////////
#ifndef SK_HISTOGRAM_BOOLEAN
# define SK_HISTOGRAM_BOOLEAN(name, value)
#endif
#ifndef SK_HISTOGRAM_ENUMERATION
# define SK_HISTOGRAM_ENUMERATION(name, value, boundary_value)
#endif
#endif // SkPostConfig_DEFINED #endif // SkPostConfig_DEFINED

View File

@ -240,9 +240,24 @@ static GrTexture* set_key_and_return(GrTexture* tex, const GrUniqueKey& key) {
*/ */
GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& key, GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& key,
const SkImage* client, SkImage::CachingHint chint) { const SkImage* client, SkImage::CachingHint chint) {
// Values representing the various texture lock paths we can take. Used for logging the path
// taken to a histogram.
enum LockTexturePath {
kFailure_LockTexturePath,
kPreExisting_LockTexturePath,
kNative_LockTexturePath,
kCompressed_LockTexturePath,
kYUV_LockTexturePath,
kRGBA_LockTexturePath,
};
enum { kLockTexturePathCount = kRGBA_LockTexturePath + 1 };
// 1. Check the cache for a pre-existing one // 1. Check the cache for a pre-existing one
if (key.isValid()) { if (key.isValid()) {
if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(key)) { if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(key)) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kPreExisting_LockTexturePath,
kLockTexturePathCount);
return tex; return tex;
} }
} }
@ -252,6 +267,8 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& key
ScopedGenerator generator(this); ScopedGenerator generator(this);
SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width(), fInfo.height()); SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width(), fInfo.height());
if (GrTexture* tex = generator->generateTexture(ctx, &subset)) { if (GrTexture* tex = generator->generateTexture(ctx, &subset)) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kNative_LockTexturePath,
kLockTexturePathCount);
return set_key_and_return(tex, key); return set_key_and_return(tex, key);
} }
} }
@ -263,6 +280,8 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& key
if (data) { if (data) {
GrTexture* tex = load_compressed_into_texture(ctx, data, desc); GrTexture* tex = load_compressed_into_texture(ctx, data, desc);
if (tex) { if (tex) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kCompressed_LockTexturePath,
kLockTexturePathCount);
return set_key_and_return(tex, key); return set_key_and_return(tex, key);
} }
} }
@ -273,6 +292,8 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& key
Generator_GrYUVProvider provider(generator); Generator_GrYUVProvider provider(generator);
GrTexture* tex = provider.refAsTexture(ctx, desc, true); GrTexture* tex = provider.refAsTexture(ctx, desc, true);
if (tex) { if (tex) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kYUV_LockTexturePath,
kLockTexturePathCount);
return set_key_and_return(tex, key); return set_key_and_return(tex, key);
} }
} }
@ -282,9 +303,13 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& key
if (this->tryLockAsBitmap(&bitmap, client, chint)) { if (this->tryLockAsBitmap(&bitmap, client, chint)) {
GrTexture* tex = GrUploadBitmapToTexture(ctx, bitmap); GrTexture* tex = GrUploadBitmapToTexture(ctx, bitmap);
if (tex) { if (tex) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kRGBA_LockTexturePath,
kLockTexturePathCount);
return set_key_and_return(tex, key); return set_key_and_return(tex, key);
} }
} }
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kFailure_LockTexturePath,
kLockTexturePathCount);
return nullptr; return nullptr;
} }

View File

@ -925,6 +925,10 @@ void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap,
int tileSize, int tileSize,
bool bicubic) { bool bicubic) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
// This is the funnel for all paths that draw tiled bitmaps/images. Log histogram entry.
SK_HISTOGRAM_BOOLEAN("DrawTiled", true);
// The following pixel lock is technically redundant, but it is desirable // The following pixel lock is technically redundant, but it is desirable
// to lock outside of the tile loop to prevent redecoding the whole image // to lock outside of the tile loop to prevent redecoding the whole image
// at each tile in cases where 'bitmap' holds an SkDiscardablePixelRef that // at each tile in cases where 'bitmap' holds an SkDiscardablePixelRef that

View File

@ -94,6 +94,9 @@ void SkGpuDevice::drawTextureProducer(GrTextureProducer* producer,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const GrClip& clip, const GrClip& clip,
const SkPaint& paint) { const SkPaint& paint) {
// This is the funnel for all non-tiled bitmap/image draw calls. Log a histogram entry.
SK_HISTOGRAM_BOOLEAN("DrawTiled", false);
// Figure out the actual dst and src rect by clipping the src rect to the bounds of the // Figure out the actual dst and src rect by clipping the src rect to the bounds of the
// adjuster. If the src rect is clipped then the dst rect must be recomputed. Also determine // adjuster. If the src rect is clipped then the dst rect must be recomputed. Also determine
// the matrix that maps the src rect to the dst rect. // the matrix that maps the src rect to the dst rect.