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