OLD | NEW |
---|---|
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 <sys/types.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include <gtest/gtest_prod.h> // for FRIEND_TEST | 11 #include <gtest/gtest_prod.h> // for FRIEND_TEST |
12 | 12 |
13 class MetricsLibraryInterface { | 13 class MetricsLibraryInterface { |
14 public: | 14 public: |
15 virtual void Init() = 0; | 15 virtual void Init() = 0; |
16 virtual bool SendToUMA(const std::string& name, int sample, | 16 virtual bool SendToUMA(const std::string& name, int sample, |
17 int min, int max, int nbuckets) = 0; | 17 int min, int max, int nbuckets) = 0; |
18 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; |
19 virtual ~MetricsLibraryInterface() {} | 19 virtual ~MetricsLibraryInterface() {} |
20 }; | 20 }; |
21 | 21 |
22 // Library used to send metrics to both Autotest and Chrome/UMA. | 22 // Library used to send metrics to both Autotest and Chrome/UMA. |
23 class MetricsLibrary : public MetricsLibraryInterface { | 23 class MetricsLibrary : public MetricsLibraryInterface { |
24 public: | 24 public: |
25 MetricsLibrary(); | 25 MetricsLibrary(); |
26 | 26 |
27 // Initializes the library. | 27 // Initializes the library. |
28 void Init(); | 28 void Init(); |
29 | 29 |
30 // Returns whether or not the machine is running in guest mode. | |
31 bool IsGuestMode(); | |
32 | |
30 // Returns whether or not metrics collection is enabled. | 33 // Returns whether or not metrics collection is enabled. |
31 bool AreMetricsEnabled(); | 34 bool AreMetricsEnabled(); |
32 | 35 |
33 // Sends histogram data to Chrome for transport to UMA and returns | 36 // Sends histogram data to Chrome for transport to UMA and returns |
34 // true on success. This method results in the equivalent of an | 37 // true on success. This method results in the equivalent of an |
35 // asynchronous non-blocking RPC to UMA_HISTOGRAM_CUSTOM_COUNTS | 38 // asynchronous non-blocking RPC to UMA_HISTOGRAM_CUSTOM_COUNTS |
36 // inside Chrome (see base/histogram.h). | 39 // inside Chrome (see base/histogram.h). |
37 // | 40 // |
38 // |sample| is the sample value to be recorded (|min| <= |sample| < |max|). | 41 // |sample| is the sample value to be recorded (|min| <= |sample| < |max|). |
39 // |min| is the minimum value of the histogram samples (|min| > 0). | 42 // |min| is the minimum value of the histogram samples (|min| > 0). |
(...skipping 28 matching lines...) Expand all Loading... | |
68 | 71 |
69 // Sends to Autotest and returns true on success. | 72 // Sends to Autotest and returns true on success. |
70 static bool SendToAutotest(const std::string& name, int value); | 73 static bool SendToAutotest(const std::string& name, int value); |
71 | 74 |
72 private: | 75 private: |
73 friend class CMetricsLibraryTest; | 76 friend class CMetricsLibraryTest; |
74 friend class MetricsLibraryTest; | 77 friend class MetricsLibraryTest; |
75 FRIEND_TEST(MetricsLibraryTest, AreMetricsEnabled); | 78 FRIEND_TEST(MetricsLibraryTest, AreMetricsEnabled); |
76 FRIEND_TEST(MetricsLibraryTest, FormatChromeMessage); | 79 FRIEND_TEST(MetricsLibraryTest, FormatChromeMessage); |
77 FRIEND_TEST(MetricsLibraryTest, FormatChromeMessageTooLong); | 80 FRIEND_TEST(MetricsLibraryTest, FormatChromeMessageTooLong); |
81 FRIEND_TEST(MetricsLibraryTest, IsDeviceMounted); | |
78 FRIEND_TEST(MetricsLibraryTest, SendMessageToChrome); | 82 FRIEND_TEST(MetricsLibraryTest, SendMessageToChrome); |
79 FRIEND_TEST(MetricsLibraryTest, SendMessageToChromeUMAEventsBadFileLocation); | 83 FRIEND_TEST(MetricsLibraryTest, SendMessageToChromeUMAEventsBadFileLocation); |
80 | 84 |
85 // Sets |*result| to whether or not the |mounts_file| indicates that | |
86 // the |device_name| is currently mounted. Uses |buffer| of | |
87 // |buffer_size| to read the file. Returns false if any error. | |
88 bool IsDeviceMounted(const char* device_name, | |
89 const char* mounts_file, | |
90 char* buffer, int buffer_size, | |
petkov
2010/10/01 16:13:09
the buffer is allocated on the stack anyway. you m
| |
91 bool* result); | |
92 | |
81 // Sends message of size |length| to Chrome for transport to UMA and | 93 // Sends message of size |length| to Chrome for transport to UMA and |
82 // returns true on success. | 94 // returns true on success. |
83 bool SendMessageToChrome(int32_t length, const char* message); | 95 bool SendMessageToChrome(int32_t length, const char* message); |
84 | 96 |
85 // Formats a name/value message for Chrome in |buffer| and returns the | 97 // Formats a name/value message for Chrome in |buffer| and returns the |
86 // length of the message or a negative value on error. | 98 // length of the message or a negative value on error. |
87 // | 99 // |
88 // Message format is: | LENGTH(binary) | NAME | \0 | VALUE | \0 | | 100 // Message format is: | LENGTH(binary) | NAME | \0 | VALUE | \0 | |
89 // | 101 // |
90 // The arbitrary |format| argument covers the non-LENGTH portion of the | 102 // The arbitrary |format| argument covers the non-LENGTH portion of the |
91 // message. The caller is responsible to store the \0 character | 103 // message. The caller is responsible to store the \0 character |
92 // between NAME and VALUE (e.g. "%s%c%d", name, '\0', value). | 104 // between NAME and VALUE (e.g. "%s%c%d", name, '\0', value). |
93 int32_t FormatChromeMessage(int32_t buffer_size, char* buffer, | 105 int32_t FormatChromeMessage(int32_t buffer_size, char* buffer, |
94 const char* format, ...); | 106 const char* format, ...); |
95 | 107 |
96 // Time at which we last checked if metrics were enabled. | 108 // Time at which we last checked if metrics were enabled. |
97 static time_t cached_enabled_time_; | 109 static time_t cached_enabled_time_; |
98 | 110 |
99 // Cached state of whether or not metrics were enabled. | 111 // Cached state of whether or not metrics were enabled. |
100 static bool cached_enabled_; | 112 static bool cached_enabled_; |
101 | 113 |
102 const char* uma_events_file_; | 114 const char* uma_events_file_; |
103 const char* consent_file_; | 115 const char* consent_file_; |
104 }; | 116 }; |
105 | 117 |
106 #endif // METRICS_LIBRARY_H_ | 118 #endif // METRICS_LIBRARY_H_ |
OLD | NEW |