blob: d8f17c4445fc801774fb9e818c2aa43f4b4a191b [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
14libmetrics is a small library that implements the basic C++ API for
15metrics collection. All metrics collection is funneled through this
16library. The easiest and recommended way for a client-side module to
17collect user metrics is to link libmetrics and use its APIs to send
18metrics 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
31 <metrics_library.h> header file. The file is installed in
32 $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
45 Currently, the API also includes two deprecated static methods:
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070046
47 bool MetricsLibrary::SendToChrome(const std::string& name, int sample,
48 int min, int max, int nbuckets)
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070049 bool MetricsLibrary::SendEnumToChrome(const std::string& name, int sample,
50 int max)
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070051
Darin Petkovfc91b422010-05-12 13:05:45 -070052 See the API documentation in metrics_library.h under
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070053 src/platform/metrics/.
54
Darin Petkov4fd6d3f2010-05-11 09:47:43 -070055- On the target platform, shortly after the sample is sent it should
56 be visible in Chrome through "about:histograms".
57
58
59================================================================================
60Histogram Naming Convention
61================================================================================
62
63Use TrackerArea.MetricName. For example:
64
65Logging.CrashCounter
66Network.TimeToDrop
67Platform.BootTime
68
69
70================================================================================
71Server Side
72================================================================================
73
74If the histogram data is visible in about:histograms, it will be sent
75by an official Chrome build to UMA, assuming the user has opted into
76metrics collection. To make the histogram visible on
77"chromedashboard", the histogram wiki needs to be updated (steps 2 and
783 after following the "Details on how to add your own histograms" link
79under the Histograms tab).
80
81The UMA server logs and keeps the collected field data even if the
82metric's name is not added to the histogram wiki. However, the
83dashboard histogram for that metric will show field data as of the
84histogram wiki update date; it will not include data for older
85dates. If past data needs to be displayed, manual server-side
86intervention is required. In other words, one should assume that field
87data collection starts only after the histogram wiki has been updated.
88
89
90================================================================================
91The Metrics Client: metrics_client
92================================================================================
93
94metrics_client is a simple shell command-line utility for sending
95histogram samples. It's installed under /usr/bin on the target
96platform and uses libmetrics to send the data to Chrome. The utility
97is useful for generating metrics from shell scripts.
98
99For usage information and command-line options, run "metrics_client"
100on the target platform or look for "Usage:" in metrics_client.cc.
101
102
103================================================================================
104The Metrics Daemon: metrics_daemon
105================================================================================
106
107metrics_daemon is a daemon that runs in the background on the target
108platform and is intended for passive or ongoing metrics collection, or
109metrics collection requiring feedback from multiple modules. For
110example, it listens to D-Bus signals related to the user session and
111screen saver states to determine if the user is actively using the
112device or not and generates the corresponding data. The metrics daemon
113uses libmetrics to send the data to Chrome.
114
115The recommended way to generate metrics data from a module is to link
116and use libmetrics directly. However, the module could instead send
117signals to or communicate in some alternative way with the metrics
118daemon. Then the metrics daemon needs to monitor for the relevant
119events and take appropriate action -- for example, aggregate data and
120send the histogram samples.