blob: e5e9024c0d2a462f547bd3fc8cd09223c943140d [file] [log] [blame]
Darin Petkov65b01462010-04-14 13:32:20 -07001// 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
5/*
6 * metrics_library.h
7 *
8 * Created on: Dec 1, 2009
9 * Author: sosa
10 */
11
12#ifndef METRICS_LIBRARY_H_
13#define METRICS_LIBRARY_H_
14
Darin Petkov65b01462010-04-14 13:32:20 -070015#include <string>
16
17// TODO(sosa@chromium.org): Add testing for send methods
18
Darin Petkovfc91b422010-05-12 13:05:45 -070019class MetricsLibraryInterface {
Darin Petkov65b01462010-04-14 13:32:20 -070020 public:
Darin Petkovfc91b422010-05-12 13:05:45 -070021 virtual void Init() = 0;
22 virtual bool SendToUMA(const std::string& name, int sample,
23 int min, int max, int nbuckets) = 0;
24 virtual bool SendEnumToUMA(const std::string& name, int sample, int max) = 0;
25 virtual ~MetricsLibraryInterface() {}
26};
27
28// Library used to send metrics to both Autotest and Chrome/UMA.
29class MetricsLibrary : public MetricsLibraryInterface {
30 public:
31 // Initializes the library.
32 void Init();
33
Darin Petkovc2526a12010-04-21 14:24:04 -070034 // Sends histogram data to Chrome for transport to UMA and returns
35 // true on success. This method results in the equivalent of an
36 // asynchronous non-blocking RPC to UMA_HISTOGRAM_CUSTOM_COUNTS
37 // inside Chrome (see base/histogram.h).
38 //
39 // |sample| is the sample value to be recorded (|min| <= |sample| < |max|).
40 // |min| is the minimum value of the histogram samples (|min| > 0).
41 // |max| is the maximum value of the histogram samples.
42 // |nbuckets| is the number of histogram buckets.
43 // [0,min) is the implicit underflow bucket.
44 // [|max|,infinity) is the implicit overflow bucket.
Darin Petkovfc91b422010-05-12 13:05:45 -070045 bool SendToUMA(const std::string& name, int sample,
46 int min, int max, int nbuckets);
47
48 // Deprecated.
Darin Petkovc2526a12010-04-21 14:24:04 -070049 static bool SendToChrome(const std::string& name, int sample,
50 int min, int max, int nbuckets);
51
Darin Petkov5b7dce12010-04-21 15:45:10 -070052 // Sends linear histogram data to Chrome for transport to UMA and
53 // returns true on success. This method results in the equivalent of
54 // an asynchronous non-blocking RPC to UMA_HISTOGRAM_ENUMERATION
55 // inside Chrome (see base/histogram.h).
56 //
57 // |sample| is the sample value to be recorded (1 <= |sample| < |max|).
58 // |max| is the maximum value of the histogram samples.
59 // 0 is the implicit underflow bucket.
60 // [|max|,infinity) is the implicit overflow bucket.
Darin Petkovfc91b422010-05-12 13:05:45 -070061 bool SendEnumToUMA(const std::string& name, int sample, int max);
62
63 // Deprecated.
Darin Petkov5b7dce12010-04-21 15:45:10 -070064 static bool SendEnumToChrome(const std::string& name, int sample, int max);
65
Darin Petkov4fcb2ac2010-04-15 16:40:23 -070066 // Sends to Autotest and returns true on success.
Darin Petkovc2526a12010-04-21 14:24:04 -070067 static bool SendToAutotest(const std::string& name, int value);
Darin Petkov65b01462010-04-14 13:32:20 -070068};
69
70#endif /* METRICS_LIBRARY_H_ */