Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 5 | #ifndef METRICS_LIBRARY_H_ |
| 6 | #define METRICS_LIBRARY_H_ |
| 7 | |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 8 | #include <string> |
| 9 | |
| 10 | // TODO(sosa@chromium.org): Add testing for send methods |
| 11 | |
Darin Petkov | fc91b42 | 2010-05-12 13:05:45 -0700 | [diff] [blame] | 12 | class MetricsLibraryInterface { |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 13 | public: |
Darin Petkov | fc91b42 | 2010-05-12 13:05:45 -0700 | [diff] [blame] | 14 | virtual void Init() = 0; |
| 15 | virtual bool SendToUMA(const std::string& name, int sample, |
| 16 | int min, int max, int nbuckets) = 0; |
| 17 | virtual bool SendEnumToUMA(const std::string& name, int sample, int max) = 0; |
| 18 | virtual ~MetricsLibraryInterface() {} |
| 19 | }; |
| 20 | |
| 21 | // Library used to send metrics to both Autotest and Chrome/UMA. |
| 22 | class MetricsLibrary : public MetricsLibraryInterface { |
| 23 | public: |
| 24 | // Initializes the library. |
| 25 | void Init(); |
| 26 | |
Darin Petkov | c2526a1 | 2010-04-21 14:24:04 -0700 | [diff] [blame] | 27 | // Sends histogram data to Chrome for transport to UMA and returns |
| 28 | // true on success. This method results in the equivalent of an |
| 29 | // asynchronous non-blocking RPC to UMA_HISTOGRAM_CUSTOM_COUNTS |
| 30 | // inside Chrome (see base/histogram.h). |
| 31 | // |
| 32 | // |sample| is the sample value to be recorded (|min| <= |sample| < |max|). |
| 33 | // |min| is the minimum value of the histogram samples (|min| > 0). |
| 34 | // |max| is the maximum value of the histogram samples. |
| 35 | // |nbuckets| is the number of histogram buckets. |
| 36 | // [0,min) is the implicit underflow bucket. |
| 37 | // [|max|,infinity) is the implicit overflow bucket. |
Darin Petkov | fc91b42 | 2010-05-12 13:05:45 -0700 | [diff] [blame] | 38 | bool SendToUMA(const std::string& name, int sample, |
| 39 | int min, int max, int nbuckets); |
| 40 | |
Darin Petkov | 5b7dce1 | 2010-04-21 15:45:10 -0700 | [diff] [blame] | 41 | // Sends linear histogram data to Chrome for transport to UMA and |
| 42 | // returns true on success. This method results in the equivalent of |
| 43 | // an asynchronous non-blocking RPC to UMA_HISTOGRAM_ENUMERATION |
| 44 | // inside Chrome (see base/histogram.h). |
| 45 | // |
| 46 | // |sample| is the sample value to be recorded (1 <= |sample| < |max|). |
| 47 | // |max| is the maximum value of the histogram samples. |
| 48 | // 0 is the implicit underflow bucket. |
| 49 | // [|max|,infinity) is the implicit overflow bucket. |
Darin Petkov | fc91b42 | 2010-05-12 13:05:45 -0700 | [diff] [blame] | 50 | bool SendEnumToUMA(const std::string& name, int sample, int max); |
| 51 | |
Darin Petkov | 4fcb2ac | 2010-04-15 16:40:23 -0700 | [diff] [blame] | 52 | // Sends to Autotest and returns true on success. |
Darin Petkov | c2526a1 | 2010-04-21 14:24:04 -0700 | [diff] [blame] | 53 | static bool SendToAutotest(const std::string& name, int value); |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | #endif /* METRICS_LIBRARY_H_ */ |