Commit 01cd7593 authored by Daniel Cheng's avatar Daniel Cheng Committed by Commit Bot

Clarify guidance for when to use histogram functions vs macros.

Given that the overhead of dynamic histogram lookup is insignificant in
most cases, encourage the use of functions over macros and remove the
very specific reference to "ten calls per hour".

Bug: 1047547
Change-Id: I334e1d3cca240c4d5bbae0865cfda8403e507c14
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2040006
Auto-Submit: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Alexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738978}
parent 028b4d69
......@@ -15,16 +15,15 @@ etc., where each group organizes related histograms.
## Coding (Emitting to Histograms)
Generally you should be using the
Prefer the helper functions defined in
[histogram_functions.h](https://cs.chromium.org/chromium/src/base/metrics/histogram_functions.h).
You can also use the macros in
[histogram_macros.h](https://cs.chromium.org/chromium/src/base/metrics/histogram_macros.h).
The macros are best used in code where efficiency matters--when the histogram is
emitted frequently (i.e., on any regular basis resulting in more than about ten
calls per hour) or on a critical path. The macros cache a pointer to the
histogram object for efficiency, though this comes at the cost of increased
binary size. (130 bytes/macro sounds small but could and does easily add up.)
If efficiency isn't a concern, prefer the histogram_functions.h methods.
These functions take a lock and perform a map lookup, but the overhead is
generally insignificant. However, when recording metrics on the critical path
(e.g. called in a loop or logged multiple times per second), use the macros in
[histogram_macros.h](https://cs.chromium.org/chromium/src/base/metrics/histogram_macros.h)
instead. These macros cache a pointer to the histogram object for efficiency,
though this comes at the cost of increased binary size: 130 bytes/macro usage
sounds small but quickly adds up.
### Don't Use the Same Histogram Logging Call in Multiple Places
......
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