blob: 677e6b75c5fa88d6148d8189a11ba2d20c75fdbf [file] [log] [blame]
Darin Petkov4fd6d3f2010-05-11 09:47:43 -07001Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2Use of this source code is governed by a BSD-style license that can be
3found in the LICENSE file.
Darin Petkov65b01462010-04-14 13:32:20 -07004
Darin Petkov4fd6d3f2010-05-11 09:47:43 -07005The Chrome OS "metrics" package contains utilities for client-side
6user metric collection. The collected data is sent to Chrome for
7transport to the UMA server.
8
9
10================================================================================
11The Metrics Library: libmetrics
12================================================================================
13
Darin Petkov32e1df92010-06-17 17:05:06 -070014libmetrics is a small library that implements the basic C and C++ API
15for metrics collection. All metrics collection is funneled through
16this library. The easiest and recommended way for a client-side module
17to collect user metrics is to link libmetrics and use its APIs to send
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070018metrics to Chrome for transport to UMA. In order to use the library in
19a module, you need to do the following:
20
21- Add a dependence (DEPEND and RDEPEND) on chromeos-base/metrics to
22 the module's ebuild.
23
24- Link the module with libmetrics (for example, by passing -lmetrics
25 to the module's link command). Both libmetrics.so and libmetrics.a
26 are built and installed under $SYSROOT/usr/lib/. Note that by
27 default -lmetrics will link against libmetrics.so, which is
28 preferred.
29
30- To access the metrics library API in the module, include the
Darin Petkovc80dd922010-05-14 09:12:36 -070031 <metrics/metrics_library.h> header file. The file is installed in
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070032 $SYSROOT/usr/include/ when the metrics library is built and
33 installed.
34
Darin Petkovfc91b422010-05-12 13:05:45 -070035- The API includes two methods:
36
37 bool MetricsLibrary::SendToUMA(const std::string& name, int sample,
38 int min, int max, int nbuckets)
39 sends a sample for a regular (exponential) histogram.
40
41 bool MetricsLibrary::SendEnumToUMA(const std::string& name, int sample,
42 int max)
43 sends a sample for an enumeration (linear) histogram.
44
Darin Petkov21cd2c52010-05-12 15:26:16 -070045 Before using these methods, a MetricsLibrary object needs to be
46 constructed and initialized through its Init method. See the
47 complete API documentation in metrics_library.h under
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070048 src/platform/metrics/.
49
Darin Petkov32e1df92010-06-17 17:05:06 -070050 For more information on the C API see c_metrics_library.h.
51
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070052- On the target platform, shortly after the sample is sent it should
53 be visible in Chrome through "about:histograms".
54
55
56================================================================================
57Histogram Naming Convention
58================================================================================
59
60Use TrackerArea.MetricName. For example:
61
62Logging.CrashCounter
63Network.TimeToDrop
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070064
65
66================================================================================
67Server Side
68================================================================================
69
70If the histogram data is visible in about:histograms, it will be sent
71by an official Chrome build to UMA, assuming the user has opted into
72metrics collection. To make the histogram visible on
73"chromedashboard", the histogram wiki needs to be updated (steps 2 and
743 after following the "Details on how to add your own histograms" link
Darin Petkov99c64a02010-06-10 15:46:39 -070075under the Histograms tab). Include the string "Chrome OS" in the
76histogram description so that it's easier to distinguish Chrome OS
77specific metrics from general Chrome histograms.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070078
79The UMA server logs and keeps the collected field data even if the
80metric's name is not added to the histogram wiki. However, the
81dashboard histogram for that metric will show field data as of the
82histogram wiki update date; it will not include data for older
83dates. If past data needs to be displayed, manual server-side
84intervention is required. In other words, one should assume that field
85data collection starts only after the histogram wiki has been updated.
86
87
88================================================================================
89The Metrics Client: metrics_client
90================================================================================
91
92metrics_client is a simple shell command-line utility for sending
93histogram samples. It's installed under /usr/bin on the target
94platform and uses libmetrics to send the data to Chrome. The utility
95is useful for generating metrics from shell scripts.
96
97For usage information and command-line options, run "metrics_client"
98on the target platform or look for "Usage:" in metrics_client.cc.
99
100
101================================================================================
102The Metrics Daemon: metrics_daemon
103================================================================================
104
105metrics_daemon is a daemon that runs in the background on the target
106platform and is intended for passive or ongoing metrics collection, or
107metrics collection requiring feedback from multiple modules. For
108example, it listens to D-Bus signals related to the user session and
109screen saver states to determine if the user is actively using the
110device or not and generates the corresponding data. The metrics daemon
111uses libmetrics to send the data to Chrome.
112
113The recommended way to generate metrics data from a module is to link
114and use libmetrics directly. However, the module could instead send
115signals to or communicate in some alternative way with the metrics
116daemon. Then the metrics daemon needs to monitor for the relevant
117events and take appropriate action -- for example, aggregate data and
118send the histogram samples.
Darin Petkovc2bf95f2010-06-21 16:27:52 -0700119
120
121================================================================================
122FAQ
123================================================================================
124
125Q. What should my histogram's |min| and |max| values be set at?
126
127A. You should set the values to a range that covers the vast majority
128 of samples that would appear in the field. Note that samples below
129 the |min| will still be collected in the underflow bucket and
130 samples above the |max| will end up in the overflow bucket. Also,
131 the reported mean of the data will be correct regardless of the
132 range.
133
134Q. How many buckets should I use in my histogram?
135
136A. You should allocate as many buckets as necessary to perform proper
137 analysis on the collected data. Note, however, that the memory
138 allocated in Chrome for each histogram is proportional to the
139 number of buckets. Therefore, it is strongly recommended to keep
140 this number low (e.g., 50 is normal, while 100 is probably high).
141
142Q. When should I use an enumeration (linear) histogram vs. a regular
143 (exponential) histogram?
144
145A. Enumeration histograms should really be used only for sampling
146 enumerated events and, in some cases, percentages. Normally, you
147 should use a regular histogram with exponential bucket layout that
148 provides higher resolution at the low end of the range and lower
149 resolution at the high end. Regular histograms are generally used
150 for collecting performance data (e.g., timing, memory usage, power)
151 as well as aggregated event counts.