Bertrand SIMONNET | 52e5b99 | 2015-08-10 15:18:00 -0700 | [diff] [blame] | 1 | Copyright (C) 2015 The Android Open Source Project |
| 2 | |
| 3 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | you may not use this file except in compliance with the License. |
| 5 | You may obtain a copy of the License at |
| 6 | |
| 7 | http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | |
| 9 | Unless required by applicable law or agreed to in writing, software |
| 10 | distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | See the License for the specific language governing permissions and |
| 13 | limitations under the License. |
| 14 | |
| 15 | ================================================================================ |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 16 | |
Darin Petkov | fd55798 | 2010-10-01 15:11:44 -0700 | [diff] [blame] | 17 | The Chrome OS "metrics" package contains utilities for client-side user metric |
Bertrand SIMONNET | 43bee50 | 2014-09-05 05:27:52 -0700 | [diff] [blame] | 18 | collection. |
| 19 | When Chrome is installed, Chrome will take care of aggregating and uploading the |
| 20 | metrics to the UMA server. |
| 21 | When Chrome is not installed (embedded build) and the metrics_uploader USE flag |
| 22 | is set, metrics_daemon will aggregate and upload the metrics itself. |
Darin Petkov | 4fd6d3f | 2010-05-11 09:47:43 -0700 | [diff] [blame] | 23 | |
| 24 | |
| 25 | ================================================================================ |
| 26 | The Metrics Library: libmetrics |
| 27 | ================================================================================ |
| 28 | |
Darin Petkov | fd55798 | 2010-10-01 15:11:44 -0700 | [diff] [blame] | 29 | libmetrics is a small library that implements the basic C and C++ API for |
| 30 | metrics collection. All metrics collection is funneled through this library. The |
| 31 | easiest and recommended way for a client-side module to collect user metrics is |
| 32 | to link libmetrics and use its APIs to send metrics to Chrome for transport to |
| 33 | UMA. In order to use the library in a module, you need to do the following: |
Darin Petkov | 4fd6d3f | 2010-05-11 09:47:43 -0700 | [diff] [blame] | 34 | |
Darin Petkov | fd55798 | 2010-10-01 15:11:44 -0700 | [diff] [blame] | 35 | - Add a dependence (DEPEND and RDEPEND) on chromeos-base/metrics to the module's |
| 36 | ebuild. |
Darin Petkov | 4fd6d3f | 2010-05-11 09:47:43 -0700 | [diff] [blame] | 37 | |
Darin Petkov | fd55798 | 2010-10-01 15:11:44 -0700 | [diff] [blame] | 38 | - 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 Petkov | 4fd6d3f | 2010-05-11 09:47:43 -0700 | [diff] [blame] | 42 | |
| 43 | - To access the metrics library API in the module, include the |
Darin Petkov | c80dd92 | 2010-05-14 09:12:36 -0700 | [diff] [blame] | 44 | <metrics/metrics_library.h> header file. The file is installed in |
Darin Petkov | fd55798 | 2010-10-01 15:11:44 -0700 | [diff] [blame] | 45 | $SYSROOT/usr/include/ when the metrics library is built and installed. |
Darin Petkov | 4fd6d3f | 2010-05-11 09:47:43 -0700 | [diff] [blame] | 46 | |
Darin Petkov | ed82485 | 2011-01-06 10:51:47 -0800 | [diff] [blame] | 47 | - 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 Petkov | 4fd6d3f | 2010-05-11 09:47:43 -0700 | [diff] [blame] | 50 | |
Darin Petkov | 32e1df9 | 2010-06-17 17:05:06 -0700 | [diff] [blame] | 51 | For more information on the C API see c_metrics_library.h. |
| 52 | |
Darin Petkov | fd55798 | 2010-10-01 15:11:44 -0700 | [diff] [blame] | 53 | - Samples are sent to Chrome only if the "/home/chronos/Consent To Send Stats" |
Bertrand SIMONNET | 43bee50 | 2014-09-05 05:27:52 -0700 | [diff] [blame] | 54 | file exists or the metrics are declared enabled in the policy file (see the |
| 55 | AreMetricsEnabled API method). |
Darin Petkov | fd55798 | 2010-10-01 15:11:44 -0700 | [diff] [blame] | 56 | |
| 57 | - On the target platform, shortly after the sample is sent, it should be visible |
| 58 | in Chrome through "about:histograms". |
Darin Petkov | 4fd6d3f | 2010-05-11 09:47:43 -0700 | [diff] [blame] | 59 | |
| 60 | |
| 61 | ================================================================================ |
| 62 | Histogram Naming Convention |
| 63 | ================================================================================ |
| 64 | |
| 65 | Use TrackerArea.MetricName. For example: |
| 66 | |
Luigi Semenzato | dc86589 | 2015-07-09 08:28:08 -0700 | [diff] [blame] | 67 | Platform.DailyUseTime |
Darin Petkov | 4fd6d3f | 2010-05-11 09:47:43 -0700 | [diff] [blame] | 68 | Network.TimeToDrop |
Darin Petkov | 4fd6d3f | 2010-05-11 09:47:43 -0700 | [diff] [blame] | 69 | |
| 70 | |
| 71 | ================================================================================ |
| 72 | Server Side |
| 73 | ================================================================================ |
| 74 | |
Darin Petkov | fd55798 | 2010-10-01 15:11:44 -0700 | [diff] [blame] | 75 | If the histogram data is visible in about:histograms, it will be sent by an |
| 76 | official Chrome build to UMA, assuming the user has opted into metrics |
| 77 | collection. To make the histogram visible on "chromedashboard", the histogram |
| 78 | description 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). |
| 80 | Include the string "Chrome OS" in the histogram description so that it's easier |
| 81 | to distinguish Chrome OS specific metrics from general Chrome histograms. |
Darin Petkov | 4fd6d3f | 2010-05-11 09:47:43 -0700 | [diff] [blame] | 82 | |
Darin Petkov | fd55798 | 2010-10-01 15:11:44 -0700 | [diff] [blame] | 83 | The UMA server logs and keeps the collected field data even if the metric's name |
| 84 | is not added to the histogram XML. However, the dashboard histogram for that |
| 85 | metric will show field data as of the histogram XML update date; it will not |
| 86 | include data for older dates. If past data needs to be displayed, manual |
| 87 | server-side intervention is required. In other words, one should assume that |
| 88 | field data collection starts only after the histogram XML has been updated. |
Darin Petkov | 4fd6d3f | 2010-05-11 09:47:43 -0700 | [diff] [blame] | 89 | |
| 90 | |
| 91 | ================================================================================ |
| 92 | The Metrics Client: metrics_client |
| 93 | ================================================================================ |
| 94 | |
Darin Petkov | fd55798 | 2010-10-01 15:11:44 -0700 | [diff] [blame] | 95 | metrics_client is a simple shell command-line utility for sending histogram |
Darin Petkov | ed82485 | 2011-01-06 10:51:47 -0800 | [diff] [blame] | 96 | samples and user actions. It's installed under /usr/bin on the target platform |
| 97 | and uses libmetrics to send the data to Chrome. The utility is useful for |
| 98 | generating metrics from shell scripts. |
Darin Petkov | 4fd6d3f | 2010-05-11 09:47:43 -0700 | [diff] [blame] | 99 | |
Darin Petkov | fd55798 | 2010-10-01 15:11:44 -0700 | [diff] [blame] | 100 | For usage information and command-line options, run "metrics_client" on the |
| 101 | target platform or look for "Usage:" in metrics_client.cc. |
Darin Petkov | 4fd6d3f | 2010-05-11 09:47:43 -0700 | [diff] [blame] | 102 | |
| 103 | |
| 104 | ================================================================================ |
| 105 | The Metrics Daemon: metrics_daemon |
| 106 | ================================================================================ |
| 107 | |
Darin Petkov | fd55798 | 2010-10-01 15:11:44 -0700 | [diff] [blame] | 108 | metrics_daemon is a daemon that runs in the background on the target platform |
| 109 | and is intended for passive or ongoing metrics collection, or metrics collection |
| 110 | requiring feedback from multiple modules. For example, it listens to D-Bus |
| 111 | signals related to the user session and screen saver states to determine if the |
| 112 | user is actively using the device or not and generates the corresponding |
| 113 | data. The metrics daemon uses libmetrics to send the data to Chrome. |
Darin Petkov | 4fd6d3f | 2010-05-11 09:47:43 -0700 | [diff] [blame] | 114 | |
Darin Petkov | fd55798 | 2010-10-01 15:11:44 -0700 | [diff] [blame] | 115 | The recommended way to generate metrics data from a module is to link and use |
| 116 | libmetrics directly. However, the module could instead send signals to or |
| 117 | communicate in some alternative way with the metrics daemon. Then the metrics |
| 118 | daemon needs to monitor for the relevant events and take appropriate action -- |
| 119 | for example, aggregate data and send the histogram samples. |
Darin Petkov | c2bf95f | 2010-06-21 16:27:52 -0700 | [diff] [blame] | 120 | |
| 121 | |
| 122 | ================================================================================ |
| 123 | FAQ |
| 124 | ================================================================================ |
| 125 | |
| 126 | Q. What should my histogram's |min| and |max| values be set at? |
| 127 | |
Darin Petkov | fd55798 | 2010-10-01 15:11:44 -0700 | [diff] [blame] | 128 | A. 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 Petkov | c2bf95f | 2010-06-21 16:27:52 -0700 | [diff] [blame] | 133 | |
| 134 | Q. How many buckets should I use in my histogram? |
| 135 | |
Darin Petkov | fd55798 | 2010-10-01 15:11:44 -0700 | [diff] [blame] | 136 | A. 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 Petkov | c2bf95f | 2010-06-21 16:27:52 -0700 | [diff] [blame] | 141 | |
| 142 | Q. When should I use an enumeration (linear) histogram vs. a regular |
| 143 | (exponential) histogram? |
| 144 | |
Darin Petkov | fd55798 | 2010-10-01 15:11:44 -0700 | [diff] [blame] | 145 | A. 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. |