Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: src/platform/metrics/metrics_library.h

Issue 2079007: Add metrics library tests. Some metrics daemon API cleanup. (Closed) Base URL: ssh://git@chromiumos-git/chromeos
Patch Set: A bit more cleanup. Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/platform/metrics/metrics_daemon_test.cc ('k') | src/platform/metrics/metrics_library.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef METRICS_LIBRARY_H_ 5 #ifndef METRICS_LIBRARY_H_
6 #define METRICS_LIBRARY_H_ 6 #define METRICS_LIBRARY_H_
7 7
8 #include <sys/types.h>
8 #include <string> 9 #include <string>
9 10
10 // TODO(sosa@chromium.org): Add testing for send methods 11 #include <gtest/gtest_prod.h> // for FRIEND_TEST
11 12
12 class MetricsLibraryInterface { 13 class MetricsLibraryInterface {
13 public: 14 public:
14 virtual void Init() = 0; 15 virtual void Init() = 0;
15 virtual bool SendToUMA(const std::string& name, int sample, 16 virtual bool SendToUMA(const std::string& name, int sample,
16 int min, int max, int nbuckets) = 0; 17 int min, int max, int nbuckets) = 0;
17 virtual bool SendEnumToUMA(const std::string& name, int sample, int max) = 0; 18 virtual bool SendEnumToUMA(const std::string& name, int sample, int max) = 0;
18 virtual ~MetricsLibraryInterface() {} 19 virtual ~MetricsLibraryInterface() {}
19 }; 20 };
20 21
21 // Library used to send metrics to both Autotest and Chrome/UMA. 22 // Library used to send metrics to both Autotest and Chrome/UMA.
22 class MetricsLibrary : public MetricsLibraryInterface { 23 class MetricsLibrary : public MetricsLibraryInterface {
23 public: 24 public:
25 MetricsLibrary();
26
24 // Initializes the library. 27 // Initializes the library.
25 void Init(); 28 void Init();
26 29
27 // Sends histogram data to Chrome for transport to UMA and returns 30 // Sends histogram data to Chrome for transport to UMA and returns
28 // true on success. This method results in the equivalent of an 31 // true on success. This method results in the equivalent of an
29 // asynchronous non-blocking RPC to UMA_HISTOGRAM_CUSTOM_COUNTS 32 // asynchronous non-blocking RPC to UMA_HISTOGRAM_CUSTOM_COUNTS
30 // inside Chrome (see base/histogram.h). 33 // inside Chrome (see base/histogram.h).
31 // 34 //
32 // |sample| is the sample value to be recorded (|min| <= |sample| < |max|). 35 // |sample| is the sample value to be recorded (|min| <= |sample| < |max|).
33 // |min| is the minimum value of the histogram samples (|min| > 0). 36 // |min| is the minimum value of the histogram samples (|min| > 0).
(...skipping 10 matching lines...) Expand all
44 // inside Chrome (see base/histogram.h). 47 // inside Chrome (see base/histogram.h).
45 // 48 //
46 // |sample| is the sample value to be recorded (1 <= |sample| < |max|). 49 // |sample| is the sample value to be recorded (1 <= |sample| < |max|).
47 // |max| is the maximum value of the histogram samples. 50 // |max| is the maximum value of the histogram samples.
48 // 0 is the implicit underflow bucket. 51 // 0 is the implicit underflow bucket.
49 // [|max|,infinity) is the implicit overflow bucket. 52 // [|max|,infinity) is the implicit overflow bucket.
50 bool SendEnumToUMA(const std::string& name, int sample, int max); 53 bool SendEnumToUMA(const std::string& name, int sample, int max);
51 54
52 // Sends to Autotest and returns true on success. 55 // Sends to Autotest and returns true on success.
53 static bool SendToAutotest(const std::string& name, int value); 56 static bool SendToAutotest(const std::string& name, int value);
57
58 private:
59 friend class MetricsLibraryTest;
60 FRIEND_TEST(MetricsLibraryTest, FormatChromeMessage);
61 FRIEND_TEST(MetricsLibraryTest, FormatChromeMessageTooLong);
62 FRIEND_TEST(MetricsLibraryTest, SendMessageToChrome);
63 FRIEND_TEST(MetricsLibraryTest, SendMessageToChromeUMAEventsBadFileLocation);
64
65 // Sends message of size |length| to Chrome for transport to UMA and
66 // returns true on success.
67 bool SendMessageToChrome(int32_t length, const char* message);
68
69 // Formats a name/value message for Chrome in |buffer| and returns the
70 // length of the message or a negative value on error.
71 //
72 // Message format is: | LENGTH(binary) | NAME | \0 | VALUE | \0 |
73 //
74 // The arbitrary |format| argument covers the non-LENGTH portion of the
75 // message. The caller is responsible to store the \0 character
76 // between NAME and VALUE (e.g. "%s%c%d", name, '\0', value).
77 int32_t FormatChromeMessage(int32_t buffer_size, char* buffer,
78 const char *format, ...);
79
80 const char* uma_events_file_;
54 }; 81 };
55 82
56 #endif /* METRICS_LIBRARY_H_ */ 83 #endif /* METRICS_LIBRARY_H_ */
OLDNEW
« no previous file with comments | « src/platform/metrics/metrics_daemon_test.cc ('k') | src/platform/metrics/metrics_library.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698