diff options
author | ericrk <ericrk@chromium.org> | 2016-02-05 14:53:25 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-05 22:54:30 +0000 |
commit | 4e7c2b3384ce41324ec60f84cd36d063b6db6d76 (patch) | |
tree | 8c9c1ab1630073e228508b2ebb9e36ddb90c8568 /skia | |
parent | a66c86c302e0d0442dbf7ebbb48f79673005fb90 (diff) | |
download | chromium_src-4e7c2b3384ce41324ec60f84cd36d063b6db6d76.zip chromium_src-4e7c2b3384ce41324ec60f84cd36d063b6db6d76.tar.gz chromium_src-4e7c2b3384ce41324ec60f84cd36d063b6db6d76.tar.bz2 |
Add Skia support for UMA stats
This is the counterpart to crrev.com/1652053004
This adds a simple wrapper around the UMA_HISTOGRAM_* macros
for inclusion in SkUserConfig. Along with the corresponding
Skia change, this allows Skia to log stats which will be
picked up by the UMA system.
BUG=
Review URL: https://codereview.chromium.org/1659303002
Cr-Commit-Position: refs/heads/master@{#373933}
Diffstat (limited to 'skia')
-rw-r--r-- | skia/BUILD.gn | 1 | ||||
-rw-r--r-- | skia/config/SkUserConfig.h | 2 | ||||
-rw-r--r-- | skia/ext/skia_histogram.cc | 43 | ||||
-rw-r--r-- | skia/ext/skia_histogram.h | 40 | ||||
-rw-r--r-- | skia/skia_chrome.gypi | 1 |
5 files changed, 87 insertions, 0 deletions
diff --git a/skia/BUILD.gn b/skia/BUILD.gn index af09b70..2e64ee8 100644 --- a/skia/BUILD.gn +++ b/skia/BUILD.gn @@ -297,6 +297,7 @@ component("skia") { "ext/platform_device_mac.cc", "ext/platform_device_win.cc", "ext/recursive_gaussian_convolution.cc", + "ext/skia_histogram.cc", "ext/skia_memory_dump_provider.cc", "ext/skia_trace_memory_dump_impl.cc", "ext/skia_utils_base.cc", diff --git a/skia/config/SkUserConfig.h b/skia/config/SkUserConfig.h index 4b547a9..f6b4bea 100644 --- a/skia/config/SkUserConfig.h +++ b/skia/config/SkUserConfig.h @@ -17,6 +17,8 @@ #ifndef SkUserConfig_DEFINED #define SkUserConfig_DEFINED +#include "skia/ext/skia_histogram.h" + /* SkTypes.h, the root of the public header files, does the following trick: #include <SkPreConfig.h> diff --git a/skia/ext/skia_histogram.cc b/skia/ext/skia_histogram.cc new file mode 100644 index 0000000..430e66b --- /dev/null +++ b/skia/ext/skia_histogram.cc @@ -0,0 +1,43 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "skia/ext/skia_histogram.h" + +#include <type_traits> +#include "base/metrics/histogram.h" + +// In order to prevent Chrome headers from leaking into Skia, we use a raw +// intptr_t in the header, rather than the base::subtle::AtomicWord. Make sure +// this is a valid assumption. +static_assert(std::is_same<intptr_t, base::subtle::AtomicWord>::value, + "To allow for header decoupling, skia_histogram.h uses intptr_t " + "instead of a base::subtle::AtomicWord. These must be the same " + "type"); + +namespace skia { + +// Wrapper around HISTOGRAM_POINTER_USE - mimics UMA_HISTOGRAM_BOOLEAN but +// allows for an external atomic_histogram_pointer. +void HistogramBoolean(intptr_t* atomic_histogram_pointer, + const char* name, + bool sample) { + HISTOGRAM_POINTER_USE( + atomic_histogram_pointer, name, AddBoolean(sample), + base::BooleanHistogram::FactoryGet( + name, base::HistogramBase::kUmaTargetedHistogramFlag)); +} + +// Wrapper around HISTOGRAM_POINTER_USE - mimics UMA_HISTOGRAM_ENUMERATION but +// allows for an external atomic_histogram_pointer. +void HistogramEnumeration(intptr_t* atomic_histogram_pointer, + const char* name, + int sample, + int boundary_value) { + HISTOGRAM_POINTER_USE(atomic_histogram_pointer, name, Add(sample), + base::LinearHistogram::FactoryGet( + name, 1, boundary_value, boundary_value + 1, + base::HistogramBase::kUmaTargetedHistogramFlag)); +} + +} // namespace skia diff --git a/skia/ext/skia_histogram.h b/skia/ext/skia_histogram.h new file mode 100644 index 0000000..0a2c7f2 --- /dev/null +++ b/skia/ext/skia_histogram.h @@ -0,0 +1,40 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SKIA_EXT_SKIA_HISTOGRAM_H_ +#define SKIA_EXT_SKIA_HISTOGRAM_H_ + +#include <cstdint> + +// This file exposes Chrome's histogram functionality to Skia, without bringing +// in any Chrome specific headers. To achieve the same level of optimization as +// is present in Chrome, we need to use an inlined atomic pointer. This macro +// defines a placeholder atomic which will be inlined into the call-site. This +// placeholder is passed to the actual histogram logic in Chrome. +#define SK_HISTOGRAM_POINTER_HELPER(function, ...) \ + do { \ + static intptr_t atomic_histogram_pointer = 0; \ + function(&atomic_histogram_pointer, __VA_ARGS__); \ + } while (0) + +#define SK_HISTOGRAM_BOOLEAN(name, sample) \ + SK_HISTOGRAM_POINTER_HELPER(skia::HistogramBoolean, "Skia." name, sample) + +#define SK_HISTOGRAM_ENUMERATION(name, sample, boundary_value) \ + SK_HISTOGRAM_POINTER_HELPER(skia::HistogramEnumeration, "Skia." name, \ + sample, boundary_value) + +namespace skia { + +void HistogramBoolean(intptr_t* atomic_histogram_pointer, + const char* name, + bool sample); +void HistogramEnumeration(intptr_t* atomic_histogram_pointer, + const char* name, + int sample, + int boundary_value); + +} // namespace skia + +#endif // SKIA_EXT_SKIA_HISTOGRAM_H_ diff --git a/skia/skia_chrome.gypi b/skia/skia_chrome.gypi index 4927624..8d4f850 100644 --- a/skia/skia_chrome.gypi +++ b/skia/skia_chrome.gypi @@ -47,6 +47,7 @@ 'ext/recursive_gaussian_convolution.cc', 'ext/SkDiscardableMemory_chrome.cc', 'ext/SkMemory_new_handler.cpp', + 'ext/skia_histogram.cc', 'ext/skia_memory_dump_provider.cc', 'ext/skia_trace_memory_dump_impl.cc', 'ext/skia_utils_base.cc', |