blob: 2a6412cb4cc0c8aca2bc5916230aede75b0730aa [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
Darin Petkov65b01462010-04-14 13:32:20 -07005#ifndef METRICS_LIBRARY_H_
6#define METRICS_LIBRARY_H_
7
Darin Petkov65b01462010-04-14 13:32:20 -07008#include <string>
9
10// TODO(sosa@chromium.org): Add testing for send methods
11
Darin Petkovfc91b422010-05-12 13:05:45 -070012class MetricsLibraryInterface {
Darin Petkov65b01462010-04-14 13:32:20 -070013 public:
Darin Petkovfc91b422010-05-12 13:05:45 -070014 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.
22class MetricsLibrary : public MetricsLibraryInterface {
23 public:
24 // Initializes the library.
25 void Init();
26
Darin Petkovc2526a12010-04-21 14:24:04 -070027 // 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 Petkovfc91b422010-05-12 13:05:45 -070038 bool SendToUMA(const std::string& name, int sample,
39 int min, int max, int nbuckets);
40
Darin Petkov5b7dce12010-04-21 15:45:10 -070041 // 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 Petkovfc91b422010-05-12 13:05:45 -070050 bool SendEnumToUMA(const std::string& name, int sample, int max);
51
Darin Petkov4fcb2ac2010-04-15 16:40:23 -070052 // Sends to Autotest and returns true on success.
Darin Petkovc2526a12010-04-21 14:24:04 -070053 static bool SendToAutotest(const std::string& name, int value);
Darin Petkov65b01462010-04-14 13:32:20 -070054};
55
56#endif /* METRICS_LIBRARY_H_ */