blob: 86b848b5312f2e8f5694532b96248104f9dad3e8 [file] [log] [blame] [view]
mpearson2b5f7e02016-10-03 21:27:031# Histogram Guidelines
2
3This document gives the best practices on how to use histograms in code and how
Caitlin Fischerb5e94352020-10-27 17:34:504to document the histograms for the dashboards. There are three general types
Darwin Huang1ca97ac2020-06-17 18:09:205of histograms: [enumerated histograms](#Enum-Histograms),
6[count histograms](#Count-Histograms) (for arbitrary numbers), and
7[sparse histograms](#When-To-Use-Sparse-Histograms) (for anything when the
8precision is important over a wide range and/or the range is not possible to
9specify a priori).
mpearson2b5f7e02016-10-03 21:27:0310
11[TOC]
12
Ilya Shermanb9641892020-11-06 00:53:5513## Defining Useful Metrics
Mark Pearsonb1d608d2018-06-05 19:59:4414
Ilya Shermanb9641892020-11-06 00:53:5515### Directly Measure What You Want
16
17Measure exactly what you want, whether that's the time used for a function call,
18the number of bytes transmitted to fetch a page, the number of items in a list,
19etc. Do not assume you can calculate what you want from other histograms, as
20most ways of doing this are incorrect.
21
22For example, suppose you want to measure the runtime of a function that just
23calls two subfunctions, each of which is instrumented with histogram logging.
24You might assume that you can simply sum the histograms for those two functions
25to get the total time, but that results in misleading data. If we knew which
26emissions came from which calls, we could pair them up and derive the total time
27for the function. However, histograms are pre-aggregated client-side, which
28means that there's no way to recover which emissions should be paired up. If you
29simply add up the two histograms to get a total duration histogram, you're
30implicitly assuming the two histograms' values are independent, which may not be
31the case.
32
33Directly measure what you care about; don't try to derive it from other data.
34
35### Provide Context
36
37When defining a new metric, think ahead about how you will analyze the
38data. Often, this will require providing context in order for the data to be
39interpretable.
40
41For enumerated histograms in particular, that often means including a bucket
42that can be used as a baseline for understanding the data recorded to other
43buckets: see the [enumerated histogram section](#Enum-Histograms).
44
45### Naming Your Histogram
46
47Histograms are taxonomized into categories, using dot (`.`) characters as
48separators. Thus, histogram names should be in the form Category.Name or
49Category.Subcategory.Name, etc., where each category organizes related
50histograms.
51
52It should be quite rare to introduce new top-level categories into the existing
53taxonomy. If you're tempted to do so, please look through the existing
Robert Kaplowcbc6fd62021-03-19 15:11:4054categories to see whether any matches the metric(s) that you are adding. To
55create a new category, the CL must be reviewed by
56[email protected].
Mark Pearsonb1d608d2018-06-05 19:59:4457
Mark Pearson4c4bc972018-05-16 20:01:0658## Coding (Emitting to Histograms)
59
Daniel Cheng01cd75932020-02-06 16:43:4560Prefer the helper functions defined in
Mark Pearsoned73f1f2019-03-22 18:00:1261[histogram_functions.h](https://cs.chromium.org/chromium/src/base/metrics/histogram_functions.h).
Daniel Cheng01cd75932020-02-06 16:43:4562These functions take a lock and perform a map lookup, but the overhead is
63generally insignificant. However, when recording metrics on the critical path
64(e.g. called in a loop or logged multiple times per second), use the macros in
65[histogram_macros.h](https://cs.chromium.org/chromium/src/base/metrics/histogram_macros.h)
66instead. These macros cache a pointer to the histogram object for efficiency,
67though this comes at the cost of increased binary size: 130 bytes/macro usage
68sounds small but quickly adds up.
Mark Pearson159c38972018-06-05 19:44:0869
Mark Pearson4c4bc972018-05-16 20:01:0670### Don't Use the Same Histogram Logging Call in Multiple Places
71
72These logging macros and functions have long names and sometimes include extra
Caitlin Fischerb5e94352020-10-27 17:34:5073parameters (defining the number of buckets for example). Use a helper function
74if possible. This leads to shorter, more readable code that's also more
75resilient to problems that could be introduced when making changes. (One could,
Mark Pearson4c4bc972018-05-16 20:01:0676for example, erroneously change the bucketing of the histogram in one call but
77not the other.)
78
79### Use Fixed Strings When Using Histogram Macros
80
81When using histogram macros (calls such as `UMA_HISTOGRAM_ENUMERATION`), you're
Victor-Gabriel Savub2afb6f42019-10-23 07:28:2382not allowed to construct your string dynamically so that it can vary at a
Caitlin Fischerb5e94352020-10-27 17:34:5083callsite. At a given callsite (preferably you have only one), the string
84should be the same every time the macro is called. If you need to use dynamic
Mark Pearson74c53212019-03-08 00:34:0885names, use the functions in histogram_functions.h instead of the macros.
Mark Pearson4c4bc972018-05-16 20:01:0686
87### Don't Use Same String in Multiple Places
88
89If you must use the histogram name in multiple places, use a compile-time
90constant of appropriate scope that can be referenced everywhere. Using inline
91strings in multiple places can lead to errors if you ever need to revise the
92name and you update one one location and forget another.
93
94### Efficiency
95
Mark Pearsoned73f1f2019-03-22 18:00:1296Generally, don't be concerned about the processing cost of emitting to a
97histogram (unless you're using [sparse
98histograms](#When-To-Use-Sparse-Histograms)). The normal histogram code is
99highly optimized. If you are recording to a histogram in particularly
100performance-sensitive or "hot" code, make sure you're using the histogram
101macros; see [reasons above](#Coding-Emitting-to-Histograms).
Mark Pearson4c4bc972018-05-16 20:01:06102
103## Picking Your Histogram Type
mpearson2b5f7e02016-10-03 21:27:03104
mpearson2b5f7e02016-10-03 21:27:03105### Enum Histograms
106
107Enumerated histogram are most appropriate when you have a list of connected /
Caitlin Fischerb5e94352020-10-27 17:34:50108related states that should be analyzed jointly. For example, the set of actions
109that can be done on the New Tab Page (use the omnibox, click a most visited
110tile, click a bookmark, etc.) would make a good enumerated histogram.
mpearson2b5f7e02016-10-03 21:27:03111If the total count of your histogram (i.e. the sum across all buckets) is
Caitlin Fischerb5e94352020-10-27 17:34:50112something meaningful—as it is in this example—that is generally a good sign.
mpearson2b5f7e02016-10-03 21:27:03113However, the total count does not have to be meaningful for an enum histogram
114to still be the right choice.
115
Caitlin Fischerb5e94352020-10-27 17:34:50116Enumerated histograms are also appropriate for counting events. Use a simple
Ilya Shermanb9641892020-11-06 00:53:55117boolean histogram. It's usually best if you have a comparison point in the same
Caitlin Fischerb5e94352020-10-27 17:34:50118histogram. For example, if you want to count pages opened from the history page,
119it might be a useful comparison to have the same histogram record the number of
120times the history page was opened.
Mark Pearsona768d0222019-03-20 02:16:00121
Ilya Shermanb9641892020-11-06 00:53:55122In rarer cases, it's okay if you only log to one bucket (say, `true`). However,
123think about whether this will provide enough [context](#Provide-Context). For
124example, suppose we want to understand how often users interact with a button.
125Just knowning that users clicked this particular button 1 million times in a day
126is not very informative on its own: The size of Chrome's user base is constantly
127changing, only a subset of users have consented to metrics reporting, different
128platforms have different sampling rates for metrics reporting, and so on. The
129data would be much easier to make sense of if it included a baseline: how often
130is the button shown?
131
Caitlin Fischerb5e94352020-10-27 17:34:50132If only a few buckets are emitted to, consider using a [sparse
Mark Pearson4d0b4632017-10-04 21:58:48133histogram](#When-To-Use-Sparse-Histograms).
134
Daniel Cheng914170d22019-05-08 09:46:32135#### Requirements
136
137Enums logged in histograms must:
138
139- be prefixed with the comment:
140 ```c++
141 // These values are persisted to logs. Entries should not be renumbered and
142 // numeric values should never be reused.
143 ```
144- be numbered starting from `0`. Note this bullet point does *not* apply for
145 enums logged with sparse histograms.
Caitlin Fischerb5e94352020-10-27 17:34:50146- have enumerators with explicit values (`= 0`, `= 1`, `= 2`) to make it clear
Daniel Cheng914170d22019-05-08 09:46:32147 that the actual values are important. This also makes it easy to match the
148 values between the C++/Java definition and [histograms.xml](./histograms.xml).
149- not renumber or reuse enumerator values. When adding a new enumerator, append
150 the new enumerator to the end. When removing an unused enumerator, comment it
151 out, making it clear the value was previously used.
152
153If your enum histogram has a catch-all / miscellaneous bucket, put that bucket
Caitlin Fischerb5e94352020-10-27 17:34:50154first (`= 0`). This makes the bucket easy to find on the dashboard if additional
155buckets are added later.
Daniel Cheng914170d22019-05-08 09:46:32156
157#### Usage
158
Ilya Shermanb6bd3c72020-04-15 23:08:15159*In C++*, define an `enum class` with a `kMaxValue` enumerator:
Daniel Cheng914170d22019-05-08 09:46:32160
Steven Holteecf841d2018-08-10 00:53:34161```c++
Daniel Chengcda1df5b2018-03-30 21:30:16162enum class NewTabPageAction {
163 kUseOmnibox = 0,
164 kClickTitle = 1,
Daniel Cheng914170d22019-05-08 09:46:32165 // kUseSearchbox = 2, // no longer used, combined into omnibox
166 kOpenBookmark = 3,
Daniel Chengcda1df5b2018-03-30 21:30:16167 kMaxValue = kOpenBookmark,
168};
169```
Daniel Chengcda1df5b2018-03-30 21:30:16170
Daniel Cheng914170d22019-05-08 09:46:32171`kMaxValue` is a special enumerator that must share the highest enumerator
172value, typically done by aliasing it with the enumerator with the highest
173value: clang automatically checks that `kMaxValue` is correctly set for `enum
174class`.
175
176The histogram helpers use the `kMaxValue` convention, and the enum may be
177logged with:
178
179```c++
Daniel Chengcda1df5b2018-03-30 21:30:16180UMA_HISTOGRAM_ENUMERATION("NewTabPageAction", action);
181```
Daniel Chengcda1df5b2018-03-30 21:30:16182
Daniel Cheng914170d22019-05-08 09:46:32183or:
184
Steven Holteecf841d2018-08-10 00:53:34185```c++
Daniel Cheng914170d22019-05-08 09:46:32186UmaHistogramEnumeration("NewTabPageAction", action);
Daniel Chengcda1df5b2018-03-30 21:30:16187```
Steven Holteecf841d2018-08-10 00:53:34188
Nate Fischer1f6efe52020-06-17 19:18:21189Logging histograms from Java should look similar:
190
191```java
192// These values are persisted to logs. Entries should not be renumbered and
193// numeric values should never be reused.
194@IntDef({NewTabPageAction.USE_OMNIBOX, NewTabPageAction.CLICK_TITLE,
195 NewTabPageAction.OPEN_BOOKMARK})
196private @interface NewTabPageAction {
197 int USE_OMNIBOX = 0;
198 int CLICK_TITLE = 1;
199 // int USE_SEARCHBOX = 2; // no longer used, combined into omnibox
200 int OPEN_BOOKMARK = 3;
201 int COUNT = 4;
202}
203
204// Using a helper function is optional, but avoids some boilerplate.
205private static void logNewTabPageAction(@NewTabPageAction int action) {
206 RecordHistogram.recordEnumeratedHistogram(
207 "NewTabPageAction", action, NewTabPageAction.COUNT);
208}
209```
210
Daniel Cheng914170d22019-05-08 09:46:32211#### Legacy Enums
212
213**Note: this method of defining histogram enums is deprecated. Do not use this
Ilya Shermanb6bd3c72020-04-15 23:08:15214for new enums *in C++*.**
Daniel Cheng914170d22019-05-08 09:46:32215
Chris Blumebdca7ca2020-06-08 15:48:35216Many legacy enums define a `kCount` sentinel, relying on the compiler to
Daniel Cheng914170d22019-05-08 09:46:32217automatically update it when new entries are added:
218
Steven Holteecf841d2018-08-10 00:53:34219```c++
Daniel Chengcda1df5b2018-03-30 21:30:16220enum class NewTabPageAction {
221 kUseOmnibox = 0,
222 kClickTitle = 1,
Daniel Cheng914170d22019-05-08 09:46:32223 // kUseSearchbox = 2, // no longer used, combined into omnibox
224 kOpenBookmark = 3,
Daniel Chengcda1df5b2018-03-30 21:30:16225 kCount,
226};
Daniel Cheng914170d22019-05-08 09:46:32227```
Steven Holteecf841d2018-08-10 00:53:34228
Daniel Cheng914170d22019-05-08 09:46:32229These enums must be recorded using the legacy helpers:
230
231```c++
Daniel Chengcda1df5b2018-03-30 21:30:16232UMA_HISTOGRAM_ENUMERATION("NewTabPageAction", action, NewTabPageAction::kCount);
233```
234
Daniel Cheng914170d22019-05-08 09:46:32235or:
236
237```c++
238UmaHistogramEnumeration("NewTabPageAction", action, NewTabPageAction::kCount);
239```
mpearsonb36013be2017-02-10 20:10:54240
Matt Giucaf3e0e2532017-10-03 23:07:52241### Flag Histograms
242
243When adding a new flag in
244[about_flags.cc](../../../chrome/browser/about_flags.cc), you need to add a
Caitlin Fischerb5e94352020-10-27 17:34:50245corresponding entry to [enums.xml](./enums.xml). This is automatically verified
246by the `AboutFlagsHistogramTest` unit test.
Matt Giucaf3e0e2532017-10-03 23:07:52247
248To add a new entry:
249
2501. Edit [enums.xml](./enums.xml), adding the feature to the `LoginCustomFlags`
Brett Wilsonf4d58772017-10-30 21:37:57251 enum section, with any unique value (just make one up, although whatever it
Caitlin Fischerb5e94352020-10-27 17:34:50252 is needs to appear in sorted order; `pretty_print.py` can do this for you).
Matt Giucaf3e0e2532017-10-03 23:07:522532. Build `unit_tests`, then run `unit_tests
254 --gtest_filter='AboutFlagsHistogramTest.*'` to compute the correct value.
2553. Update the entry in [enums.xml](./enums.xml) with the correct value, and move
Caitlin Fischerb5e94352020-10-27 17:34:50256 it so the list is sorted by value (`pretty_print.py` can do this for you).
Matt Giucaf3e0e2532017-10-03 23:07:522574. Re-run the test to ensure the value and ordering are correct.
258
259You can also use `tools/metrics/histograms/validate_format.py` to check the
260ordering (but not that the value is correct).
261
262Don't remove entries when removing a flag; they are still used to decode data
263from previous Chrome versions.
264
mpearson2b5f7e02016-10-03 21:27:03265### Count Histograms
266
267[histogram_macros.h](https://cs.chromium.org/chromium/src/base/metrics/histogram_macros.h)
268provides macros for some common count types such as memory or elapsed time, in
Caitlin Fischerb5e94352020-10-27 17:34:50269addition to general count macros. These have reasonable default values; you
270seldom need to choose the number of buckets or histogram min. However, you still
271need to choose the histogram max (use the advice below).
mpearson2b5f7e02016-10-03 21:27:03272
273If none of the default macros work well for you, please thoughtfully choose
274a min, max, and bucket count for your histogram using the advice below.
275
rkaplow6dfcb892016-10-04 14:04:27276#### Count Histograms: Choosing Min and Max
mpearson2b5f7e02016-10-03 21:27:03277
Caitlin Fischerb5e94352020-10-27 17:34:50278For histogram max, choose a value such that very few emissions to the histogram
Robert Kaplowcbc6fd62021-03-19 15:11:40279exceed the max. If a metric emission is above the max value, it will get put
280into an "overflow" bucket. If this bucket is too large, it can be difficult to
281compute statistics. One rule of thumb is at most 1% of samples should be in the
282overflow bucket (and ideally, less). This allows analysis of the 99th
283percentile. Err on the side of too large a range versus too short a range.
284(Remember that if you choose poorly, you'll have to wait for another release
285cycle to fix it.)
mpearson2b5f7e02016-10-03 21:27:03286
287For histogram min, if you care about all possible values (zero and above),
Robert Kaplowcbc6fd62021-03-19 15:11:40288choose a min of 1. All histograms have an underflow bucket for emitted zeros,
289so a min of 1 is appropriate. Otherwise, choose the min appropriate for your
Caitlin Fischerb5e94352020-10-27 17:34:50290particular situation.
mpearson2b5f7e02016-10-03 21:27:03291
rkaplow6dfcb892016-10-04 14:04:27292#### Count Histograms: Choosing Number of Buckets
mpearson2b5f7e02016-10-03 21:27:03293
Caitlin Fischerb5e94352020-10-27 17:34:50294Choose the smallest number of buckets that give you the granularity you need. By
295default, count histogram bucket sizes scale exponentially so you can get fine
296granularity when the numbers are small yet still reasonable resolution for
297larger numbers. The macros default to 50 buckets (or 100 buckets for histograms
298with wide ranges), which is appropriate for most purposes. Because histograms
299pre-allocate all the buckets, the number of buckets selected directly dictates
300how much memory is used. Do not exceed 100 buckets without good reason (and
301consider whether [sparse histograms](#When-To-Use-Sparse-Histograms) might work
302better for you in that case—they do not pre-allocate their buckets).
rkaplow8a62ef62016-10-06 14:42:34303
Mark Pearson6be2f35c2018-08-14 07:06:02304### Timing Histograms
305
306You can easily emit a time duration (time delta) using UMA_HISTOGRAM_TIMES,
Caitlin Fischerb5e94352020-10-27 17:34:50307UMA_HISTOGRAM_MEDIUM_TIMES, UMA_HISTOGRAM_LONG_TIMES macros, and their
308friends, as well as helpers like SCOPED_UMA_HISTOGRAM_TIMER. Many timing
Mark Pearson6be2f35c2018-08-14 07:06:02309histograms are used for performance monitoring; if this is the case for you,
310please read [this document about how to structure timing histograms to make
311them more useful and
Paul Jensen5107d9c2018-10-22 22:24:06312actionable](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/speed/diagnostic_metrics.md).
Mark Pearson6be2f35c2018-08-14 07:06:02313
Mark Pearson49928ec2018-06-05 20:15:49314### Percentage or Ratio Histograms
315
Caitlin Fischerb5e94352020-10-27 17:34:50316You can easily emit a percentage histogram using the UMA_HISTOGRAM_PERCENTAGE
317macro provided in
Mark Pearson49928ec2018-06-05 20:15:49318[histogram_macros.h](https://cs.chromium.org/chromium/src/base/metrics/histogram_macros.h).
Caitlin Fischerb5e94352020-10-27 17:34:50319You can also easily emit any ratio as a linear histogram (for equally sized
320buckets).
Mark Pearson49928ec2018-06-05 20:15:49321
Caitlin Fischerb5e94352020-10-27 17:34:50322For such histograms, you want each value recorded to cover approximately the
323same span of time. This typically means emitting values periodically at a set
324time interval, such as every 5 minutes. We do not recommend recording a ratio at
325the end of a video playback, as video lengths vary greatly.
Mark Pearson49928ec2018-06-05 20:15:49326
Mark Pearson9be8bffa2020-03-03 19:08:02327It is okay to emit at the end of an animation sequence when what's being
Caitlin Fischerb5e94352020-10-27 17:34:50328animated is fixed / known. In this case, each value represents roughly the same
329span of time.
Mark Pearson9be8bffa2020-03-03 19:08:02330
Caitlin Fischerb5e94352020-10-27 17:34:50331Why? You typically cannot make decisions based on histograms whose values are
332recorded in response to an event that varies in length because such metrics can
333conflate heavy usage with light usage. It's easier to reason about metrics that
334avoid this source of bias.
Mark Pearson49928ec2018-06-05 20:15:49335
Caitlin Fischerb5e94352020-10-27 17:34:50336Many developers have been bitten by this. For example, it was previously common
337to emit an actions-per-minute ratio whenever Chrome was backgrounded. Precisely,
338these metrics computed the number of uses of a particular action during a Chrome
339session, divided by length of time Chrome had been open. Sometimes, the recorded
340rate was based on a short interaction with Chrome–a few seconds or a minute.
341Other times, the recorded rate was based on a long interaction, tens of minutes
342or hours. These two situations are indistinguishable in the UMA logs–the
343recorded values can be identical.
Mark Pearson49928ec2018-06-05 20:15:49344
Caitlin Fischerb5e94352020-10-27 17:34:50345The inability to distinguish these two qualitatively different settings make
346such histograms effectively uninterpretable and not actionable. Emitting at a
347regular interval avoids the issue. Each value represents the same amount of time
348(e.g., one minute of video playback).
Mark Pearson49928ec2018-06-05 20:15:49349
rkaplow8a62ef62016-10-06 14:42:34350### Local Histograms
351
Gayane Petrosyana6ee443c2018-05-17 21:39:54352Histograms can be added via [Local macros](https://codesearch.chromium.org/chromium/src/base/metrics/histogram_macros_local.h).
Caitlin Fischerb5e94352020-10-27 17:34:50353These still record locally, but are not uploaded to UMA and are therefore not
354available for analysis. This can be useful for metrics only needed for local
355debugging. We don't recommend using local histograms outside of that scenario.
rkaplow8a62ef62016-10-06 14:42:34356
357### Multidimensional Histograms
358
Caitlin Fischerb5e94352020-10-27 17:34:50359It is common to be interested in logging multidimensional data–where multiple
rkaplow8a62ef62016-10-06 14:42:34360pieces of information need to be logged together. For example, a developer may
361be interested in the counts of features X and Y based on whether a user is in
362state A or B. In this case, they want to know the count of X under state A,
363as well as the other three permutations.
364
365There is no general purpose solution for this type of analysis. We suggest
366using the workaround of using an enum of length MxN, where you log each unique
367pair {state, feature} as a separate entry in the same enum. If this causes a
Gayane Petrosyana6ee443c2018-05-17 21:39:54368large explosion in data (i.e. >100 enum entries), a [sparse histogram](#When-To-Use-Sparse-Histograms)
Caitlin Fischerb5e94352020-10-27 17:34:50369may be appropriate. If you are unsure of the best way to proceed, please contact
370someone from the OWNERS file.
Gayane Petrosyana6ee443c2018-05-17 21:39:54371
372## Histogram Expiry
373
Caitlin Fischerb5e94352020-10-27 17:34:50374Histogram expiry is specified by the `expires_after` attribute in histogram
375descriptions in histograms.xml. The attribute can be specified as date in
376**YYYY-MM-DD** format or as Chrome milestone in **M**\*(e.g. M68) format. In the
377latter case, the actual expiry date is about 12 weeks after that branch is cut,
378or basically when it is replaced on the "stable" channel by the following
Brian Whitefa0a3fa2019-05-13 16:58:11379release.
380
Mark Pearsonce4371c2021-03-15 23:57:42381After a histogram expires, it ceases to be displayed on the dashboard.
382Follow [these directions](#extending) to extend it.
Brian Whitefa0a3fa2019-05-13 16:58:11383
Caitlin Fischerb5e94352020-10-27 17:34:50384Once a histogram has expired, the code that records it becomes dead code and
385should be removed from the codebase along with marking the histogram definition
386as obsolete.
Gayane Petrosyana6ee443c2018-05-17 21:39:54387
Brian White8614f812019-02-07 21:07:01388In **rare** cases, the expiry can be set to "never". This is used to denote
Robert Kaplowcbc6fd62021-03-19 15:11:40389metrics of critical importance that are, typically, used for other reports. For
390example, all metrics of the
391"[heartbeat](https://uma.googleplex.com/p/chrome/variations)" are set to never
392expire. All metrics that never expire must have an XML comment describing why so
393that it can be audited in the future. Setting an expiry to "never" must be
394reviewed by [email protected].
Brian White8614f812019-02-07 21:07:01395
396```
397<!-- expires-never: "heartbeat" metric (internal: go/uma-heartbeats) -->
398```
399
Caitlin Fischerb5e94352020-10-27 17:34:50400For all new histograms, the use of expiry attribute is strongly encouraged and
401enforced by the Chrome Metrics team through reviews.
Gayane Petrosyana6ee443c2018-05-17 21:39:54402
403#### How to choose expiry for histograms
404
Caitlin Fischerb5e94352020-10-27 17:34:50405If you are adding a histogram to evaluate a feature launch, set an expiry date
406consistent with the expected feature launch date. Otherwise, we recommend
407choosing 3-6 months.
Gayane Petrosyana6ee443c2018-05-17 21:39:54408
Ilya Sherman67418ea2019-11-27 01:28:23409Here are some guidelines for common scenarios:
Gayane Petrosyana6ee443c2018-05-17 21:39:54410
Ilya Sherman67418ea2019-11-27 01:28:23411* If the listed owner moved to different project, find a new owner.
412* If neither the owner nor the team uses the histogram, remove it.
413* If the histogram is not in use now, but might be useful in the far future,
414 remove it.
415* If the histogram is not in use now, but might be useful in the near
416 future, pick ~3 months or ~2 milestones ahead.
Caitlin Fischerb5e94352020-10-27 17:34:50417* If the histogram is actively in use now and is useful in the short term,
418 pick 3-6 months or 2-4 milestones ahead.
Ilya Sherman67418ea2019-11-27 01:28:23419* If the histogram is actively in use and seems useful for an indefinite time,
420 pick 1 year.
421
422We also have a tool that automatically extends expiry dates. The 80% more
423frequently accessed histograms are pushed out every Tuesday, to 6 months from
424the date of the run. Googlers can view the [design
425doc](https://docs.google.com/document/d/1IEAeBF9UnYQMDfyh2gdvE7WlUKsfIXIZUw7qNoU89A4).
Gayane Petrosyana6ee443c2018-05-17 21:39:54426
Mark Pearsonce4371c2021-03-15 23:57:42427#### How to extend an expired histogram {#extending}
428
429You can revive an expired histogram by setting the expiration date to a
430date in the future.
431
432There's some leeway here. A client may continue to send data for that
433histogram for some time after the official expiry date so simply bumping
434the 'expires_after' date at HEAD may be sufficient to resurrect it without
435any data discontinuity.
436
437If a histogram expired more than a month ago (for histograms with an
438expiration date) or more than one milestone ago (for histograms with
439expiration milestones; this means top-of-tree is two or more milestones away
440from expired milestone), then you may be outside the safety window. In this
441case, when extending the histogram add to the histogram description a
442message: "Warning: this histogram was expired from DATE to DATE; data may be
443missing." (For milestones, write something similar.)
444
445When reviving a histogram outside the safety window, realize the change to
446histograms.xml to revive it rolls out with the binary release. It takes
447some time to get to the stable channel.
448
449It you need to revive it faster, the histogram can be re-enabled via adding to
450the [expired histogram allowlist](#Expired-histogram-allowlist).
451
Gayane Petrosyana6ee443c2018-05-17 21:39:54452### Expired histogram notifier
453
Caitlin Fischerb5e94352020-10-27 17:34:50454The expired histogram notifier notifies histogram owners before their histograms
455expire by creating crbugs, which are assigned to owners. This allows owners to
456extend the lifetime of their histograms, if needed, or deprecate them. The
457notifier regularly checks all histograms across the histograms.xml files and
458identifies expired or soon-to-be expired histograms. It then creates or updates
459crbugs accordingly.
Gayane Petrosyana6ee443c2018-05-17 21:39:54460
Caitlin Fischer9f4841052020-11-04 21:02:44461### Expired histogram allowlist
Gayane Petrosyana6ee443c2018-05-17 21:39:54462
Caitlin Fischerb5e94352020-10-27 17:34:50463If a histogram expires but turns out to be useful, you can add the histogram's
Caitlin Fischer9f4841052020-11-04 21:02:44464name to the allowlist until the updated expiration date reaches the stable
465channel. When doing so, update the histogram's summary to document the period
466during which the histogram's data is incomplete. To add a histogram to the
467allowlist, see the internal documentation:
Caitlin Fischerb5e94352020-10-27 17:34:50468[Histogram Expiry](https://goto.google.com/histogram-expiry-gdoc).
mpearson2b5f7e02016-10-03 21:27:03469
mpearson72a5c91392017-05-09 22:49:44470## Testing
mpearson2b5f7e02016-10-03 21:27:03471
Caitlin Fischerb5e94352020-10-27 17:34:50472Test your histograms using `chrome://histograms`. Make sure they're being
rkaplow6dfcb892016-10-04 14:04:27473emitted to when you expect and not emitted to at other times. Also check that
Caitlin Fischerb5e94352020-10-27 17:34:50474the values emitted to are correct. Finally, for count histograms, make sure
rkaplow6dfcb892016-10-04 14:04:27475that buckets capture enough precision for your needs over the range.
mpearson2b5f7e02016-10-03 21:27:03476
Ivan Sandrk8ffc5832018-07-09 12:34:58477Pro tip: You can filter the set of histograms shown on `chrome://histograms` by
Caitlin Fischerb5e94352020-10-27 17:34:50478specifying a prefix. For example, `chrome://histograms/Extensions.Load` shows
479only histograms whose names match the pattern "Extensions.Load*".
Ivan Sandrk8ffc5832018-07-09 12:34:58480
mpearson72a5c91392017-05-09 22:49:44481In addition to testing interactively, you can have unit tests examine the
Caitlin Fischerb5e94352020-10-27 17:34:50482values emitted to histograms. See [histogram_tester.h](https://cs.chromium.org/chromium/src/base/test/metrics/histogram_tester.h)
mpearson72a5c91392017-05-09 22:49:44483for details.
mpearson2b5f7e02016-10-03 21:27:03484
Mark Pearson4c4bc972018-05-16 20:01:06485## Interpreting the Resulting Data
486
487The top of [go/uma-guide](http://go/uma-guide) has good advice on how to go
Caitlin Fischerb5e94352020-10-27 17:34:50488about analyzing and interpreting the results of UMA data uploaded by users. If
Mark Pearson4c4bc972018-05-16 20:01:06489you're reading this page, you've probably just finished adding a histogram to
490the Chromium source code and you're waiting for users to update their version of
Caitlin Fischerb5e94352020-10-27 17:34:50491Chrome to a version that includes your code. In this case, the best advice is
492to remind you that users who update frequently / quickly are biased. Best take
Mark Pearson4c4bc972018-05-16 20:01:06493the initial statistics with a grain of salt; they're probably *mostly* right but
494not entirely so.
495
mpearson72a5c91392017-05-09 22:49:44496## Revising Histograms
497
Robert Kaplowcbc6fd62021-03-19 15:11:40498When changing the semantics of a histogram (when it's emitted, what the buckets
499represent, the bucket range or number of buckets, etc.), create a new histogram
500with a new name. Otherwise analysis that mixes the data pre- and post- change
501may be misleading. If the histogram name is still the best name choice, the
502recommendation is to simply append a '2' to the name. See [Cleaning Up Histogram
503Entries](#Cleaning-Up-Histogram-Entries) for details on how to handle the XML
504changes.
mpearson2b5f7e02016-10-03 21:27:03505
mpearson72a5c91392017-05-09 22:49:44506## Deleting Histograms
mpearson2b5f7e02016-10-03 21:27:03507
Caitlin Fischerb5e94352020-10-27 17:34:50508Please delete code that emits to histograms that are no longer needed.
509Histograms take up memory. Cleaning up histograms that you no longer care
510about is good! But see the note below on
Mark Pearson2a311c52019-03-19 21:47:01511[Cleaning Up Histogram Entries](#Cleaning-Up-Histogram-Entries).
mpearson2b5f7e02016-10-03 21:27:03512
513## Documenting Histograms
514
Caitlin Fischerb5e94352020-10-27 17:34:50515Document histograms in [histograms.xml](./histograms.xml). There is also a
Mark Pearson159c38972018-06-05 19:44:08516[google-internal version of the file](http://go/chrome-histograms-internal) for
Caitlin Fischerb5e94352020-10-27 17:34:50517the rare case in which the histogram is confidential (added only to Chrome code,
Mark Pearson159c38972018-06-05 19:44:08518not Chromium code; or, an accurate description about how to interpret the
519histogram would reveal information about Google's plans).
520
mpearson2b5f7e02016-10-03 21:27:03521### Add Histogram and Documentation in the Same Changelist
522
vapier52b9aba2016-12-14 06:09:25523If possible, please add the [histograms.xml](./histograms.xml) description in
Caitlin Fischerb5e94352020-10-27 17:34:50524the same changelist in which you add the histogram-emitting code. This has
525several benefits. One, it sometimes happens that the
vapier52b9aba2016-12-14 06:09:25526[histograms.xml](./histograms.xml) reviewer has questions or concerns about the
527histogram description that reveal problems with interpretation of the data and
Caitlin Fischerb5e94352020-10-27 17:34:50528call for a different recording strategy. Two, it allows the histogram reviewer
vapier52b9aba2016-12-14 06:09:25529to easily review the emission code to see if it comports with these best
Caitlin Fischerb5e94352020-10-27 17:34:50530practices and to look for other errors.
mpearson2b5f7e02016-10-03 21:27:03531
532### Understandable to Everyone
533
534Histogram descriptions should be roughly understandable to someone not familiar
Caitlin Fischerb5e94352020-10-27 17:34:50535with your feature. Please add a sentence or two of background if necessary.
mpearson2b5f7e02016-10-03 21:27:03536
Robert Kaplowcbc6fd62021-03-19 15:11:40537Note any caveats associated with your histogram in the summary. For example, if
538the set of supported platforms is surprising, such as if a desktop feature is
539not available on Mac, the summary should explain where it is recorded. It is
540also common to have caveats along the lines of "this histogram is only recorded
541if X" (e.g., upon a successful connection to a service, a feature is enabled by
542the user).
543
mpearson2b5f7e02016-10-03 21:27:03544
545### State When It Is Recorded
546
547Histogram descriptions should clearly state when the histogram is emitted
548(profile open? network request received? etc.).
549
Mark Pearsond8fc9fd22021-03-12 20:18:58550Some histograms record error conditions. These should be clear about whether
551all errors are recorded or only the first. If only the first, the histogram
552description should have text like:
553```
554In the case of multiple errors, only the first reason encountered is recorded. Refer
555to Class::FunctionImplementingLogic() for details.
556```
557
Ilya Sherman470c95a2020-09-21 23:05:43558### Provide Clear Units or Enum Labels
559
560For enumerated histograms, including boolean and sparse histograms, provide an
561`enum=` attribute mapping enum values to semantically contentful labels. Define
562the `<enum>` in enums.xml if none of the existing enums are a good fit. Use
563labels whenever they would be clearer than raw numeric values.
564
565For non-enumerated histograms, include a `units=` attribute. Be specific:
566e.g. distinguish "MB" vs. "MiB", refine generic labels like "counts" to more
567precise labels like "pages", etc.
568
jsbellda3a66c2017-02-09 21:40:32569### Owners
rkaplow8a62ef62016-10-06 14:42:34570
Caitlin Fischer254a12f72019-07-31 20:57:03571Histograms need owners, who are the experts on the metric and the points of
572contact for any questions or maintenance tasks, such as extending a histogram's
573expiry or deprecating the metric.
rkaplow8a62ef62016-10-06 14:42:34574
Caitlin Fischer254a12f72019-07-31 20:57:03575Histograms must have a primary owner and may have secondary owners. A primary
Mario Bianucci9947bbd2020-10-28 17:41:47576owner is a Googler with an @google.com or @chromium.org email address, e.g.
Caitlin Fischerb5e94352020-10-27 17:34:50577<owner>[email protected]</owner>, who is ultimately responsible for maintaining
578the metric. Secondary owners may be other individuals, team mailing lists, e.g.
579<owner>[email protected]</owner>, or paths to OWNERS files, e.g.
580<owner>src/directory/OWNERS</owner>.
Mark Pearson74c53212019-03-08 00:34:08581
Caitlin Fischer254a12f72019-07-31 20:57:03582It's a best practice to list multiple owners, so that there's no single point
583of failure for histogram-related questions and maintenance tasks. If you are
584using a metric heavily and understand it intimately, feel free to add yourself
Caitlin Fischerb5e94352020-10-27 17:34:50585as an owner.
Mark Pearson74c53212019-03-08 00:34:08586
Caitlin Fischer254a12f72019-07-31 20:57:03587Notably, owners are asked to determine whether histograms have outlived their
Caitlin Fischerb5e94352020-10-27 17:34:50588usefulness. When a histogram is nearing expiry, a robot files a reminder bug in
589Monorail. It's important that somebody familiar with the histogram notices and
590triages such bugs!
rkaplow8a62ef62016-10-06 14:42:34591
Ilya Shermanf64bca252020-11-10 23:16:24592Tip: When removing someone from the owner list for a histogram, it's a nice
593courtesy to ask them for approval.
594
Caitlin Fischerfeafb4392020-10-05 21:10:07595### Components
596
597Histograms may be associated with components, which can help make sure that
598histogram expiry bugs don't fall through the cracks.
599
600There are two ways in which components may be associated with a histogram. The
601first and recommended way is to add a tag to a histogram or histogram suffix,
602e.g. <component>UI&gt;Shell</component>. The second way is to specify an OWNERS
603file as a secondary owner for a histogram. If the OWNERS file contains a
604component, then the component is associated with the histogram. If the specified
605OWNERS file doesn't have a component, but an OWNERS file in a parent directory
606does, then the parent directory's component is used.
607
Mark Pearson2a311c52019-03-19 21:47:01608### Cleaning Up Histogram Entries
mpearson2b5f7e02016-10-03 21:27:03609
Henrique Nakashima78c4547c2021-03-25 21:56:42610Do not delete histograms from histograms.xml files or move them to
611obsolete_histograms.xml. Instead, mark unused histograms as obsolete and
612annotate them with the date or milestone in the `<obsolete>` tag entry. They
613will later get moved to obsolete_histograms.xml via tooling.
Mark Pearson2a311c52019-03-19 21:47:01614
Ilya Sherman9e22dea2020-10-05 22:32:36615If deprecating only some variants of a
616[patterned histogram](#Patterned-Histograms), mark each deprecated `<variant>`
617as obsolete as well. Similarly, if the histogram used histogram suffixes, mark
618the suffix entry for the histogram as obsolete.
Mark Pearson2a311c52019-03-19 21:47:01619
620If the histogram is being replaced by a new version:
621
622* Note in the `<obsolete>` message the name of the replacement histogram.
623
Caitlin Fischerb5e94352020-10-27 17:34:50624* Make sure the descriptions of the original and replacement histogram are
625 different. It's never appropriate for them to be identical. Either the old
626 description was wrong, and it should be revised to explain what it actually
627 measured, or the old histogram was measuring something not as useful as the
628 replacement, in which case the new histogram is measuring something different
629 and needs to have a new description.
mpearson2b5f7e02016-10-03 21:27:03630
Mark Pearsona0109122018-05-30 18:23:05631A changelist that marks a histogram as obsolete should be reviewed by all
632current owners.
633
mpearson2b5f7e02016-10-03 21:27:03634Deleting histogram entries would be bad if someone to accidentally reused your
635old histogram name and thereby corrupts new data with whatever old data is still
Caitlin Fischerb5e94352020-10-27 17:34:50636coming in. It's also useful to keep obsolete histogram descriptions in
637[histograms.xml](./histograms.xml)—that way, if someone is searching for a
vapier52b9aba2016-12-14 06:09:25638histogram to answer a particular question, they can learn if there was a
639histogram at some point that did so even if it isn't active now.
mpearson2b5f7e02016-10-03 21:27:03640
Ilya Sherman8f0034a2020-07-22 22:06:34641*Exception:* It is ok to delete the metadata for any histogram that has never
642been recorded to. For example, it's fine to correct a typo where the histogram
643name in the metadata does not match the name in the Chromium source code.
644
Ilya Sherman9e22dea2020-10-05 22:32:36645### Patterned Histograms
Ilya Shermanf54104b2017-07-12 23:45:47646
647It is sometimes useful to record several closely related metrics, which measure
Ilya Sherman9e22dea2020-10-05 22:32:36648the same type of data, with some minor variations. You can declare the metadata
649for these concisely using patterned histograms. For example:
Ilya Shermanf54104b2017-07-12 23:45:47650
Ilya Sherman9e22dea2020-10-05 22:32:36651```xml
Robert Kaplowe1430ce2021-03-25 19:02:18652<histogram name="Pokemon.{Character}.EfficacyAgainst{OpponentType}"
653 units="multiplier" expires_after="M95">
Ilya Sherman9e22dea2020-10-05 22:32:36654 <owner>[email protected]</owner>
655 <owner>[email protected]</owner>
656 <summary>
657 The efficacy multiplier for {Character} against an opponent of
658 {OpponentType} type.
659 </summary>
660 <token key="Character">
661 <variant name="Bulbasaur"/>
662 <variant name="Charizard"/>
663 <variant name="Mewtwo"/>
664 </token>
665 <token key="OpponentType">
666 <variant name="Dragon" summary="dragon"/>
667 <variant name="Flying" summary="flappity-flap"/>
668 <variant name="Psychic" summary="psychic"/>
669 <variant name="Water" summary="water"/>
670 </token>
671</histogram>
672```
673
674This example defines metadata for 12 (= 3 x 4) concrete histograms, such as
675
676```xml
Robert Kaplowe1430ce2021-03-25 19:02:18677<histogram name="Pokemon.Charizard.EfficacyAgainstWater"
678 units="multiplier" expires_after="M95">
Ilya Sherman9e22dea2020-10-05 22:32:36679 <owner>[email protected]</owner>
680 <owner>[email protected]</owner>
681 <summary>
682 The efficacy multiplier for Charizard against an opponent of water type.
683 </summary>
684</histogram>
685```
686
687Note that each token `<variant>` defines what text should be substituted for it,
688both in the histogram name and in the summary text. As shorthand, a `<variant>`
Caitlin Fischerb5e94352020-10-27 17:34:50689that omits the `summary` attribute substitutes the value of the `name` attribute
690in the histogram's `<summary>` text as well.
Ilya Sherman9e22dea2020-10-05 22:32:36691
692*** promo
693Tip: You can declare an optional token by listing an empty name: `<variant
694name="" summary="aggregated across all breakdowns"/>`. This can be useful when
695recording a "parent" histogram that aggregates across a set of breakdowns.
696***
697
698You can use the `<variants>` tag to define a set of `<variant>`s out-of-line.
699This is useful for token substitutions that are shared among multiple families
700of histograms. See
701[histograms.xml](https://source.chromium.org/search?q=file:histograms.xml%20%3Cvariants)
702for examples.
703
Caitlin Fischerb5e94352020-10-27 17:34:50704By default, a `<variant>` inherits the owners declared for the patterned
Ilya Sherman9e22dea2020-10-05 22:32:36705histogram. Each variant can optionally override the inherited list with custom
706owners:
707```xml
708<variant name="SubteamBreakdown" ...>
709 <owner>[email protected]</owner>
710 <owner>[email protected]</owner>
711</variant>
712```
Mark Pearsona0109122018-05-30 18:23:05713
Mark Pearson2a311c52019-03-19 21:47:01714As [with histogram entries](#Cleaning-Up-Histogram-Entries), never delete
Ilya Sherman9e22dea2020-10-05 22:32:36715variants. If the variant expansion is no longer used, mark it as `<obsolete>`.
Mark Pearson2a311c52019-03-19 21:47:01716
Ilya Sherman9e22dea2020-10-05 22:32:36717*** promo
Oksana Zhuravlova5242ad22021-02-19 00:14:20718Tip: You can run `print_expanded_histograms.py --pattern=` to show all generated
Weilun Shibac61d9d32020-11-12 02:40:26719histograms by patterned histograms or histogram suffixes including their
720summaries and owners. For example, this can be run (from the repo root) as:
721```
Oksana Zhuravlova5242ad22021-02-19 00:14:20722./tools/metrics/histograms/print_expanded_histograms.py --pattern=^UMA.A.B
Weilun Shibac61d9d32020-11-12 02:40:26723```
724***
725
726*** promo
Ilya Sherman9e22dea2020-10-05 22:32:36727Tip: You can run `print_histogram_names.py --diff` to enumerate all the
728histogram names that are generated by a particular CL. For example, this can be
729run (from the repo root) as:
Charlie Harrison90407d92020-05-19 23:57:32730```
731./tools/metrics/histograms/print_histogram_names.py --diff origin/master
732```
Ilya Sherman9e22dea2020-10-05 22:32:36733***
734
735For documentation about the `<histogram_suffixes>` syntax, which is deprecated,
736see
737https://chromium.googlesource.com/chromium/src/+/refs/tags/87.0.4270.1/tools/metrics/histograms/one-pager.md#histogram-suffixes-deprecated-in-favor-of-pattern-histograms
Charlie Harrison90407d92020-05-19 23:57:32738
mpearson2b5f7e02016-10-03 21:27:03739## When To Use Sparse Histograms
740
Caitlin Fischerb5e94352020-10-27 17:34:50741Sparse histograms are well-suited for recording counts of exact sample values
742that are sparsely distributed over a large range. They can be used with enums
Ilya Sherman1eee82c4c2017-12-08 01:22:19743as well as regular integer values. It is often valuable to provide labels in
744[enums.xml](./enums.xml).
mpearson2b5f7e02016-10-03 21:27:03745
746The implementation uses a lock and a map, whereas other histogram types use a
747vector and no lock. It is thus more costly to add values to, and each value
748stored has more overhead, compared to the other histogram types. However it
749may be more efficient in memory if the total number of sample values is small
750compared to the range of their values.
751
Mark Pearsoned73f1f2019-03-22 18:00:12752Please talk with the metrics team if there are more than a thousand possible
753different values that you could emit.
754
rkaplow6dfcb892016-10-04 14:04:27755For more information, see [sparse_histograms.h](https://cs.chromium.org/chromium/src/base/metrics/sparse_histogram.h).
Caitlin Fischerb466a042019-07-31 21:41:46756
Ilya Shermanf64bca252020-11-10 23:16:24757
Caitlin Fischerb466a042019-07-31 21:41:46758# Team Documentation
759
Ilya Shermanf64bca252020-11-10 23:16:24760## Reviewing Metrics CLs
761
Robert Kaplowcbc6fd62021-03-19 15:11:40762If you are a metric OWNER, you have the serious responsibility of ensuring
763Chrome's data collection is following best practices. If there's any concern
764about an incoming metrics changelist, please escalate by assigning to
765[email protected].
766
Ilya Shermanf64bca252020-11-10 23:16:24767When reviewing metrics CLs, look at the following, listed in approximate order
768of importance:
769
770### Privacy
771
772Does anything tickle your privacy senses? (Googlers, see
773[go/uma-privacy](https://goto.google.com/uma-privacy) for guidelines.)
774
775**Please escalate if there's any doubt!**
776
777### Clarity
778
779Is the metadata clear enough for [all Chromies](#Understandable-to-Everyone) to
780understand what the metric is recording? Consider the histogram name,
781description, units, enum labels, etc.
782
783It's really common for developers to forget to list [when the metric is
784recorded](#State-When-It-Is-Recorded). This is particularly important context,
785so please remind developers to clearly document it.
786
787Note: Clarity is a bit less important for very niche metrics used only by a
788couple of engineers. However, it's hard to assess the metric design and
789correctness if the metadata is especially unclear.
790
791### Metric design
792
793* Does the metric definition make sense?
794* Will the resulting data be interpretable at analysis time?
795
796### Correctness
797
798Is the histogram being recorded correctly?
799
800* Does the bucket layout look reasonable?
801
802 * The metrics APIs like base::UmaHistogram* have some sharp edges,
803 especially for the APIs that require specifying the number of
804 buckets. Check for off-by-one errors and unused buckets.
805
806 * Is the bucket layout efficient? Typically, push back if there are >50
807 buckets -- this can be ok in some cases, but make sure that the CL author
808 has consciously considered the tradeoffs here and is making a reasonable
809 choice.
810
811 * For timing metrics, do the min and max bounds make sense for the duration
812 that is being measured?
813
814* The base::UmaHistogram* functions are
815 [generally preferred](#Coding-Emitting-to-Histograms) over the
816 UMA_HISTOGRAM_* macros. If using the macros, remember that names must be
817 runtime constants!
818
819Also, related to [clarity](#Clarity): Does the client logic correctly implement
820the metric described in the XML metadata? Some common errors to watch out for:
821
822* The metric is only emitted within an if-stmt (e.g., only if some data is
823 available) and this restriction isn't mentioned in the metadata description.
824
825* The metric description states that it's recorded when X happens, but it's
826 actually recorded when X is scheduled to occur, or only emitted when X
827 succeeds (but omitted on failure), etc.
828
829When the metadata and the client logic do not match, the appropriate solution
830might be to update the metadata, or it might be to update the client
831logic. Guide this decision by considering what data will be more easily
832interpretable and what data will have hidden surprises/gotchas.
833
834### Sustainability
835
Robert Kaplowcd6e0422021-04-07 21:58:53836* Is the CL adding a reasonable number of metrics/buckets?
Ilya Shermanf64bca252020-11-10 23:16:24837 * When reviewing a CL that is trying to add many metrics at once, guide the CL
838 author toward an appropriate solution for their needs. For example,
839 multidimensional metrics can be recorded via UKM, and we are currently
Robert Kaplowcd6e0422021-04-07 21:58:53840 building support for structured metrics in UMA.
841 * There's no hard rule, but anything above 20 separate histograms should be
842 escalated by being assigned to [email protected].
843 * Similarly, any histogram with more than 100 possible buckets should be
844 escalated by being assigned to [email protected].
Ilya Shermanf64bca252020-11-10 23:16:24845
846* Are expiry dates being set
847 [appropriately](#How-to-choose-expiry-for-histograms)?
848
849### Everything Else!
850
851This document describes many other nuances that are important for defining and
852recording useful metrics. Check CLs for these other types of issues as well.
853
854And, as you would with a language style guide, periodically re-review the doc to
855stay up to date on the details.
856
857### Becoming a Metrics Owner
858
859If you would like to be listed as one of the OWNERS for metrics metadata, reach
860out to one of the existing //base/metrics/OWNERS. Similar to language
861readability review teams, we have a reverse shadow onboarding process:
862
8631. First, read through this document to get up to speed on best practices.
864
8652. Partner up with an experienced reviewer from //base/metrics/OWNERS.
866
8673. Join the cs/chrome-metrics.gwsq.
868
869 Note: This step is optional if you are not on the metrics team. Still,
870 consider temporarily joining the metrics gwsq as a quick way to get a breadth
871 of experience. You can remove yourself once your training is completed.
872
8734. Start reviewing CLs! Once you're ready to approve a CL, add a comment like "I
874 am currently ramping up as a metrics reviewer, +username for OWNERS approval"
875 and add your partner as a reviewer on the CL. Once at a point where there's
876 pretty good alignment in the code review feedback, your partner will add you
877 to the OWNERS file.
878
Caitlin Fischerb466a042019-07-31 21:41:46879
880## Processing histograms.xml
881
882When working with histograms.xml, verify whether you require fully expanded
883OWNERS files. Many scripts in this directory process histograms.xml, and
884sometimes OWNERS file paths are expanded and other times they are not. OWNERS
885paths are expanded when scripts make use of merge_xml's function MergeFiles;
886otherwise, they are not.