blob: 2ecec5f42c3417f00b97f55d1a39ceacb5bdda48 [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
6collection. The collected data is sent to Chrome for transport to the UMA
7server.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -07008
9
10================================================================================
11The Metrics Library: libmetrics
12================================================================================
13
Darin Petkovfd557982010-10-01 15:11:44 -070014libmetrics is a small library that implements the basic C and C++ API for
15metrics collection. All metrics collection is funneled through this library. The
16easiest and recommended way for a client-side module to collect user metrics is
17to link libmetrics and use its APIs to send metrics to Chrome for transport to
18UMA. In order to use the library in a module, you need to do the following:
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070019
Darin Petkovfd557982010-10-01 15:11:44 -070020- Add a dependence (DEPEND and RDEPEND) on chromeos-base/metrics to the module's
21 ebuild.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070022
Darin Petkovfd557982010-10-01 15:11:44 -070023- Link the module with libmetrics (for example, by passing -lmetrics to the
24 module's link command). Both libmetrics.so and libmetrics.a are built and
25 installed under $SYSROOT/usr/lib/. Note that by default -lmetrics will link
26 against libmetrics.so, which is preferred.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070027
28- To access the metrics library API in the module, include the
Darin Petkovc80dd922010-05-14 09:12:36 -070029 <metrics/metrics_library.h> header file. The file is installed in
Darin Petkovfd557982010-10-01 15:11:44 -070030 $SYSROOT/usr/include/ when the metrics library is built and installed.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070031
Darin Petkoved824852011-01-06 10:51:47 -080032- The API is documented in metrics_library.h under src/platform/metrics/. Before
33 using the API methods, a MetricsLibrary object needs to be constructed and
34 initialized through its Init method.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070035
Darin Petkov32e1df92010-06-17 17:05:06 -070036 For more information on the C API see c_metrics_library.h.
37
Darin Petkovfd557982010-10-01 15:11:44 -070038- Samples are sent to Chrome only if the "/home/chronos/Consent To Send Stats"
39 file exists (see the AreMetricsEnabled API method). Normally, this file is
40 created when the user opts into metrics collection.
41
42- On the target platform, shortly after the sample is sent, it should be visible
43 in Chrome through "about:histograms".
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070044
45
46================================================================================
47Histogram Naming Convention
48================================================================================
49
50Use TrackerArea.MetricName. For example:
51
52Logging.CrashCounter
53Network.TimeToDrop
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070054
55
56================================================================================
57Server Side
58================================================================================
59
Darin Petkovfd557982010-10-01 15:11:44 -070060If the histogram data is visible in about:histograms, it will be sent by an
61official Chrome build to UMA, assuming the user has opted into metrics
62collection. To make the histogram visible on "chromedashboard", the histogram
63description XML file needs to be updated (steps 2 and 3 after following the
64"Details on how to add your own histograms" link under the Histograms tab).
65Include the string "Chrome OS" in the histogram description so that it's easier
66to distinguish Chrome OS specific metrics from general Chrome histograms.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070067
Darin Petkovfd557982010-10-01 15:11:44 -070068The UMA server logs and keeps the collected field data even if the metric's name
69is not added to the histogram XML. However, the dashboard histogram for that
70metric will show field data as of the histogram XML update date; it will not
71include data for older dates. If past data needs to be displayed, manual
72server-side intervention is required. In other words, one should assume that
73field data collection starts only after the histogram XML has been updated.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070074
75
76================================================================================
77The Metrics Client: metrics_client
78================================================================================
79
Darin Petkovfd557982010-10-01 15:11:44 -070080metrics_client is a simple shell command-line utility for sending histogram
Darin Petkoved824852011-01-06 10:51:47 -080081samples and user actions. It's installed under /usr/bin on the target platform
82and uses libmetrics to send the data to Chrome. The utility is useful for
83generating metrics from shell scripts.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070084
Darin Petkovfd557982010-10-01 15:11:44 -070085For usage information and command-line options, run "metrics_client" on the
86target platform or look for "Usage:" in metrics_client.cc.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070087
88
89================================================================================
90The Metrics Daemon: metrics_daemon
91================================================================================
92
Darin Petkovfd557982010-10-01 15:11:44 -070093metrics_daemon is a daemon that runs in the background on the target platform
94and is intended for passive or ongoing metrics collection, or metrics collection
95requiring feedback from multiple modules. For example, it listens to D-Bus
96signals related to the user session and screen saver states to determine if the
97user is actively using the device or not and generates the corresponding
98data. The metrics daemon uses libmetrics to send the data to Chrome.
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070099
Darin Petkovfd557982010-10-01 15:11:44 -0700100The recommended way to generate metrics data from a module is to link and use
101libmetrics directly. However, the module could instead send signals to or
102communicate in some alternative way with the metrics daemon. Then the metrics
103daemon needs to monitor for the relevant events and take appropriate action --
104for example, aggregate data and send the histogram samples.
Darin Petkovc2bf95f2010-06-21 16:27:52 -0700105
106
107================================================================================
108FAQ
109================================================================================
110
111Q. What should my histogram's |min| and |max| values be set at?
112
Darin Petkovfd557982010-10-01 15:11:44 -0700113A. You should set the values to a range that covers the vast majority of samples
114 that would appear in the field. Note that samples below the |min| will still
115 be collected in the underflow bucket and samples above the |max| will end up
116 in the overflow bucket. Also, the reported mean of the data will be correct
117 regardless of the range.
Darin Petkovc2bf95f2010-06-21 16:27:52 -0700118
119Q. How many buckets should I use in my histogram?
120
Darin Petkovfd557982010-10-01 15:11:44 -0700121A. You should allocate as many buckets as necessary to perform proper analysis
122 on the collected data. Note, however, that the memory allocated in Chrome for
123 each histogram is proportional to the number of buckets. Therefore, it is
124 strongly recommended to keep this number low (e.g., 50 is normal, while 100
125 is probably high).
Darin Petkovc2bf95f2010-06-21 16:27:52 -0700126
127Q. When should I use an enumeration (linear) histogram vs. a regular
128 (exponential) histogram?
129
Darin Petkovfd557982010-10-01 15:11:44 -0700130A. Enumeration histograms should really be used only for sampling enumerated
131 events and, in some cases, percentages. Normally, you should use a regular
132 histogram with exponential bucket layout that provides higher resolution at
133 the low end of the range and lower resolution at the high end. Regular
134 histograms are generally used for collecting performance data (e.g., timing,
135 memory usage, power) as well as aggregated event counts.