blob: 6150dc7bea0c4e5ade288c7f86f1d668770f1847 [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 Petkovfd557982010-10-01 15:11:44 -07005The Chrome OS "metrics" package contains utilities for client-side user metric
Bertrand SIMONNET43bee502014-09-05 05:27:52 -07006collection.
7When Chrome is installed, Chrome will take care of aggregating and uploading the
8metrics to the UMA server.
9When Chrome is not installed (embedded build) and the metrics_uploader USE flag
10is set, metrics_daemon will aggregate and upload the metrics itself.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070011
12
13================================================================================
14The Metrics Library: libmetrics
15================================================================================
16
Darin Petkovfd557982010-10-01 15:11:44 -070017libmetrics is a small library that implements the basic C and C++ API for
18metrics collection. All metrics collection is funneled through this library. The
19easiest and recommended way for a client-side module to collect user metrics is
20to link libmetrics and use its APIs to send metrics to Chrome for transport to
21UMA. In order to use the library in a module, you need to do the following:
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070022
Darin Petkovfd557982010-10-01 15:11:44 -070023- Add a dependence (DEPEND and RDEPEND) on chromeos-base/metrics to the module's
24 ebuild.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070025
Darin Petkovfd557982010-10-01 15:11:44 -070026- Link the module with libmetrics (for example, by passing -lmetrics to the
27 module's link command). Both libmetrics.so and libmetrics.a are built and
28 installed under $SYSROOT/usr/lib/. Note that by default -lmetrics will link
29 against libmetrics.so, which is preferred.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070030
31- To access the metrics library API in the module, include the
Darin Petkovc80dd922010-05-14 09:12:36 -070032 <metrics/metrics_library.h> header file. The file is installed in
Darin Petkovfd557982010-10-01 15:11:44 -070033 $SYSROOT/usr/include/ when the metrics library is built and installed.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070034
Darin Petkoved824852011-01-06 10:51:47 -080035- The API is documented in metrics_library.h under src/platform/metrics/. Before
36 using the API methods, a MetricsLibrary object needs to be constructed and
37 initialized through its Init method.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070038
Darin Petkov32e1df92010-06-17 17:05:06 -070039 For more information on the C API see c_metrics_library.h.
40
Darin Petkovfd557982010-10-01 15:11:44 -070041- Samples are sent to Chrome only if the "/home/chronos/Consent To Send Stats"
Bertrand SIMONNET43bee502014-09-05 05:27:52 -070042 file exists or the metrics are declared enabled in the policy file (see the
43 AreMetricsEnabled API method).
Darin Petkovfd557982010-10-01 15:11:44 -070044
45- On the target platform, shortly after the sample is sent, it should be visible
46 in Chrome through "about:histograms".
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070047
48
49================================================================================
50Histogram Naming Convention
51================================================================================
52
53Use TrackerArea.MetricName. For example:
54
55Logging.CrashCounter
56Network.TimeToDrop
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070057
58
59================================================================================
60Server Side
61================================================================================
62
Darin Petkovfd557982010-10-01 15:11:44 -070063If the histogram data is visible in about:histograms, it will be sent by an
64official Chrome build to UMA, assuming the user has opted into metrics
65collection. To make the histogram visible on "chromedashboard", the histogram
66description XML file needs to be updated (steps 2 and 3 after following the
67"Details on how to add your own histograms" link under the Histograms tab).
68Include the string "Chrome OS" in the histogram description so that it's easier
69to distinguish Chrome OS specific metrics from general Chrome histograms.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070070
Darin Petkovfd557982010-10-01 15:11:44 -070071The UMA server logs and keeps the collected field data even if the metric's name
72is not added to the histogram XML. However, the dashboard histogram for that
73metric will show field data as of the histogram XML update date; it will not
74include data for older dates. If past data needs to be displayed, manual
75server-side intervention is required. In other words, one should assume that
76field data collection starts only after the histogram XML has been updated.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070077
78
79================================================================================
80The Metrics Client: metrics_client
81================================================================================
82
Darin Petkovfd557982010-10-01 15:11:44 -070083metrics_client is a simple shell command-line utility for sending histogram
Darin Petkoved824852011-01-06 10:51:47 -080084samples and user actions. It's installed under /usr/bin on the target platform
85and uses libmetrics to send the data to Chrome. The utility is useful for
86generating metrics from shell scripts.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070087
Darin Petkovfd557982010-10-01 15:11:44 -070088For usage information and command-line options, run "metrics_client" on the
89target platform or look for "Usage:" in metrics_client.cc.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070090
91
92================================================================================
93The Metrics Daemon: metrics_daemon
94================================================================================
95
Darin Petkovfd557982010-10-01 15:11:44 -070096metrics_daemon is a daemon that runs in the background on the target platform
97and is intended for passive or ongoing metrics collection, or metrics collection
98requiring feedback from multiple modules. For example, it listens to D-Bus
99signals related to the user session and screen saver states to determine if the
100user is actively using the device or not and generates the corresponding
101data. The metrics daemon uses libmetrics to send the data to Chrome.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -0700102
Darin Petkovfd557982010-10-01 15:11:44 -0700103The recommended way to generate metrics data from a module is to link and use
104libmetrics directly. However, the module could instead send signals to or
105communicate in some alternative way with the metrics daemon. Then the metrics
106daemon needs to monitor for the relevant events and take appropriate action --
107for example, aggregate data and send the histogram samples.
Darin Petkovc2bf95f2010-06-21 16:27:52 -0700108
109
110================================================================================
111FAQ
112================================================================================
113
114Q. What should my histogram's |min| and |max| values be set at?
115
Darin Petkovfd557982010-10-01 15:11:44 -0700116A. You should set the values to a range that covers the vast majority of samples
117 that would appear in the field. Note that samples below the |min| will still
118 be collected in the underflow bucket and samples above the |max| will end up
119 in the overflow bucket. Also, the reported mean of the data will be correct
120 regardless of the range.
Darin Petkovc2bf95f2010-06-21 16:27:52 -0700121
122Q. How many buckets should I use in my histogram?
123
Darin Petkovfd557982010-10-01 15:11:44 -0700124A. You should allocate as many buckets as necessary to perform proper analysis
125 on the collected data. Note, however, that the memory allocated in Chrome for
126 each histogram is proportional to the number of buckets. Therefore, it is
127 strongly recommended to keep this number low (e.g., 50 is normal, while 100
128 is probably high).
Darin Petkovc2bf95f2010-06-21 16:27:52 -0700129
130Q. When should I use an enumeration (linear) histogram vs. a regular
131 (exponential) histogram?
132
Darin Petkovfd557982010-10-01 15:11:44 -0700133A. Enumeration histograms should really be used only for sampling enumerated
134 events and, in some cases, percentages. Normally, you should use a regular
135 histogram with exponential bucket layout that provides higher resolution at
136 the low end of the range and lower resolution at the high end. Regular
137 histograms are generally used for collecting performance data (e.g., timing,
138 memory usage, power) as well as aggregated event counts.