blob: d4c9a0e5800341fc0bd387c7f54c9ce2e1b328a7 [file] [log] [blame]
Bertrand SIMONNET52e5b992015-08-10 15:18:00 -07001Copyright (C) 2015 The Android Open Source Project
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14
15================================================================================
Darin Petkov65b01462010-04-14 13:32:20 -070016
Darin Petkovfd557982010-10-01 15:11:44 -070017The Chrome OS "metrics" package contains utilities for client-side user metric
Bertrand SIMONNET43bee502014-09-05 05:27:52 -070018collection.
19When Chrome is installed, Chrome will take care of aggregating and uploading the
20metrics to the UMA server.
21When Chrome is not installed (embedded build) and the metrics_uploader USE flag
22is set, metrics_daemon will aggregate and upload the metrics itself.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070023
24
25================================================================================
26The Metrics Library: libmetrics
27================================================================================
28
Darin Petkovfd557982010-10-01 15:11:44 -070029libmetrics is a small library that implements the basic C and C++ API for
30metrics collection. All metrics collection is funneled through this library. The
31easiest and recommended way for a client-side module to collect user metrics is
32to link libmetrics and use its APIs to send metrics to Chrome for transport to
33UMA. In order to use the library in a module, you need to do the following:
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070034
Darin Petkovfd557982010-10-01 15:11:44 -070035- Add a dependence (DEPEND and RDEPEND) on chromeos-base/metrics to the module's
36 ebuild.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070037
Darin Petkovfd557982010-10-01 15:11:44 -070038- Link the module with libmetrics (for example, by passing -lmetrics to the
39 module's link command). Both libmetrics.so and libmetrics.a are built and
40 installed under $SYSROOT/usr/lib/. Note that by default -lmetrics will link
41 against libmetrics.so, which is preferred.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070042
43- To access the metrics library API in the module, include the
Darin Petkovc80dd922010-05-14 09:12:36 -070044 <metrics/metrics_library.h> header file. The file is installed in
Darin Petkovfd557982010-10-01 15:11:44 -070045 $SYSROOT/usr/include/ when the metrics library is built and installed.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070046
Darin Petkoved824852011-01-06 10:51:47 -080047- The API is documented in metrics_library.h under src/platform/metrics/. Before
48 using the API methods, a MetricsLibrary object needs to be constructed and
49 initialized through its Init method.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070050
Darin Petkov32e1df92010-06-17 17:05:06 -070051 For more information on the C API see c_metrics_library.h.
52
Darin Petkovfd557982010-10-01 15:11:44 -070053- Samples are sent to Chrome only if the "/home/chronos/Consent To Send Stats"
Bertrand SIMONNET43bee502014-09-05 05:27:52 -070054 file exists or the metrics are declared enabled in the policy file (see the
55 AreMetricsEnabled API method).
Darin Petkovfd557982010-10-01 15:11:44 -070056
57- On the target platform, shortly after the sample is sent, it should be visible
58 in Chrome through "about:histograms".
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070059
60
61================================================================================
62Histogram Naming Convention
63================================================================================
64
65Use TrackerArea.MetricName. For example:
66
Luigi Semenzatodc865892015-07-09 08:28:08 -070067Platform.DailyUseTime
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070068Network.TimeToDrop
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070069
70
71================================================================================
72Server Side
73================================================================================
74
Darin Petkovfd557982010-10-01 15:11:44 -070075If the histogram data is visible in about:histograms, it will be sent by an
76official Chrome build to UMA, assuming the user has opted into metrics
77collection. To make the histogram visible on "chromedashboard", the histogram
78description XML file needs to be updated (steps 2 and 3 after following the
79"Details on how to add your own histograms" link under the Histograms tab).
80Include the string "Chrome OS" in the histogram description so that it's easier
81to distinguish Chrome OS specific metrics from general Chrome histograms.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070082
Darin Petkovfd557982010-10-01 15:11:44 -070083The UMA server logs and keeps the collected field data even if the metric's name
84is not added to the histogram XML. However, the dashboard histogram for that
85metric will show field data as of the histogram XML update date; it will not
86include data for older dates. If past data needs to be displayed, manual
87server-side intervention is required. In other words, one should assume that
88field data collection starts only after the histogram XML has been updated.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070089
90
91================================================================================
92The Metrics Client: metrics_client
93================================================================================
94
Darin Petkovfd557982010-10-01 15:11:44 -070095metrics_client is a simple shell command-line utility for sending histogram
Darin Petkoved824852011-01-06 10:51:47 -080096samples and user actions. It's installed under /usr/bin on the target platform
97and uses libmetrics to send the data to Chrome. The utility is useful for
98generating metrics from shell scripts.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070099
Darin Petkovfd557982010-10-01 15:11:44 -0700100For usage information and command-line options, run "metrics_client" on the
101target platform or look for "Usage:" in metrics_client.cc.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -0700102
103
104================================================================================
105The Metrics Daemon: metrics_daemon
106================================================================================
107
Darin Petkovfd557982010-10-01 15:11:44 -0700108metrics_daemon is a daemon that runs in the background on the target platform
109and is intended for passive or ongoing metrics collection, or metrics collection
110requiring feedback from multiple modules. For example, it listens to D-Bus
111signals related to the user session and screen saver states to determine if the
112user is actively using the device or not and generates the corresponding
113data. The metrics daemon uses libmetrics to send the data to Chrome.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -0700114
Darin Petkovfd557982010-10-01 15:11:44 -0700115The recommended way to generate metrics data from a module is to link and use
116libmetrics directly. However, the module could instead send signals to or
117communicate in some alternative way with the metrics daemon. Then the metrics
118daemon needs to monitor for the relevant events and take appropriate action --
119for example, aggregate data and send the histogram samples.
Darin Petkovc2bf95f2010-06-21 16:27:52 -0700120
121
122================================================================================
123FAQ
124================================================================================
125
126Q. What should my histogram's |min| and |max| values be set at?
127
Darin Petkovfd557982010-10-01 15:11:44 -0700128A. You should set the values to a range that covers the vast majority of samples
129 that would appear in the field. Note that samples below the |min| will still
130 be collected in the underflow bucket and samples above the |max| will end up
131 in the overflow bucket. Also, the reported mean of the data will be correct
132 regardless of the range.
Darin Petkovc2bf95f2010-06-21 16:27:52 -0700133
134Q. How many buckets should I use in my histogram?
135
Darin Petkovfd557982010-10-01 15:11:44 -0700136A. You should allocate as many buckets as necessary to perform proper analysis
137 on the collected data. Note, however, that the memory allocated in Chrome for
138 each histogram is proportional to the number of buckets. Therefore, it is
139 strongly recommended to keep this number low (e.g., 50 is normal, while 100
140 is probably high).
Darin Petkovc2bf95f2010-06-21 16:27:52 -0700141
142Q. When should I use an enumeration (linear) histogram vs. a regular
143 (exponential) histogram?
144
Darin Petkovfd557982010-10-01 15:11:44 -0700145A. Enumeration histograms should really be used only for sampling enumerated
146 events and, in some cases, percentages. Normally, you should use a regular
147 histogram with exponential bucket layout that provides higher resolution at
148 the low end of the range and lower resolution at the high end. Regular
149 histograms are generally used for collecting performance data (e.g., timing,
150 memory usage, power) as well as aggregated event counts.