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 /* | 5 /* |
6 * metrics_library.cc | 6 * metrics_library.cc |
7 * | 7 * |
8 * Created on: Dec 1, 2009 | 8 * Created on: Dec 1, 2009 |
9 * Author: sosa | 9 * Author: sosa |
10 */ | 10 */ |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 if (message_length > buffer_size) { | 114 if (message_length > buffer_size) { |
115 PrintError("chrome message too long", NULL, 0); | 115 PrintError("chrome message too long", NULL, 0); |
116 return -1; | 116 return -1; |
117 } | 117 } |
118 | 118 |
119 // Prepend LENGTH to the message. | 119 // Prepend LENGTH to the message. |
120 memcpy(buffer, &message_length, len_size); | 120 memcpy(buffer, &message_length, len_size); |
121 return message_length; | 121 return message_length; |
122 } | 122 } |
123 | 123 |
| 124 void MetricsLibrary::Init() { |
| 125 } |
| 126 |
124 // static | 127 // static |
125 bool MetricsLibrary::SendToAutotest(const string& name, int value) { | 128 bool MetricsLibrary::SendToAutotest(const string& name, int value) { |
126 FILE *autotest_file = fopen(kAutotestPath, "a+"); | 129 FILE *autotest_file = fopen(kAutotestPath, "a+"); |
127 if (autotest_file == NULL) { | 130 if (autotest_file == NULL) { |
128 PrintError("fopen", kAutotestPath, errno); | 131 PrintError("fopen", kAutotestPath, errno); |
129 return false; | 132 return false; |
130 } | 133 } |
131 | 134 |
132 fprintf(autotest_file, "%s=%d\n", name.c_str(), value); | 135 fprintf(autotest_file, "%s=%d\n", name.c_str(), value); |
133 fclose(autotest_file); | 136 fclose(autotest_file); |
(...skipping 10 matching lines...) Expand all Loading... |
144 "histogram%c%s %d %d %d %d", '\0', | 147 "histogram%c%s %d %d %d %d", '\0', |
145 name.c_str(), sample, min, max, nbuckets); | 148 name.c_str(), sample, min, max, nbuckets); |
146 | 149 |
147 if (message_length < 0) | 150 if (message_length < 0) |
148 return false; | 151 return false; |
149 | 152 |
150 // Send the message. | 153 // Send the message. |
151 return SendMessageToChrome(message_length, message); | 154 return SendMessageToChrome(message_length, message); |
152 } | 155 } |
153 | 156 |
| 157 bool MetricsLibrary::SendToUMA(const string& name, int sample, |
| 158 int min, int max, int nbuckets) { |
| 159 return SendToChrome(name, sample, min, max, nbuckets); |
| 160 } |
| 161 |
154 //static | 162 //static |
155 bool MetricsLibrary::SendEnumToChrome(const std::string& name, int sample, | 163 bool MetricsLibrary::SendEnumToChrome(const std::string& name, int sample, |
156 int max) { | 164 int max) { |
157 // Format the message. | 165 // Format the message. |
158 char message[kBufferSize]; | 166 char message[kBufferSize]; |
159 int32_t message_length = | 167 int32_t message_length = |
160 FormatChromeMessage(kBufferSize, message, | 168 FormatChromeMessage(kBufferSize, message, |
161 "linearhistogram%c%s %d %d", '\0', | 169 "linearhistogram%c%s %d %d", '\0', |
162 name.c_str(), sample, max); | 170 name.c_str(), sample, max); |
163 | 171 |
164 if (message_length < 0) | 172 if (message_length < 0) |
165 return false; | 173 return false; |
166 | 174 |
167 // Send the message. | 175 // Send the message. |
168 return SendMessageToChrome(message_length, message); | 176 return SendMessageToChrome(message_length, message); |
169 } | 177 } |
| 178 |
| 179 bool MetricsLibrary::SendEnumToUMA(const std::string& name, int sample, |
| 180 int max) { |
| 181 return SendEnumToChrome(name, sample, max); |
| 182 } |
OLD | NEW |