| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium 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 #include "chrome/browser/chromeos/external_metrics.h" | 5 #include "chrome/browser/chromeos/external_metrics.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 #include <unistd.h> | 11 #include <unistd.h> |
| 12 #include <sys/file.h> | 12 #include <sys/file.h> |
| 13 #include <sys/stat.h> | 13 #include <sys/stat.h> |
| 14 #include <sys/types.h> | 14 #include <sys/types.h> |
| 15 | 15 |
| 16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 17 #include "base/eintr_wrapper.h" | 17 #include "base/eintr_wrapper.h" |
| 18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/perftimer.h" | 19 #include "base/perftimer.h" |
| 20 #include "base/time.h" | 20 #include "base/time.h" |
| 21 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/browser_thread.h" | 22 #include "chrome/browser/browser_thread.h" |
| 23 #include "chrome/browser/metrics/metrics_service.h" |
| 22 #include "chrome/browser/metrics/user_metrics.h" | 24 #include "chrome/browser/metrics/user_metrics.h" |
| 23 | 25 |
| 24 // Steps to add an action. | 26 // Steps to add an action. |
| 25 // | 27 // |
| 26 // 1. Enter a helper function that calls UserMetrics::RecordAction. | 28 // 1. Enter a helper function that calls UserMetrics::RecordAction. |
| 27 // | 29 // |
| 28 // 2. Add a line for that function in InitializeUserActions. | 30 // 2. Add a line for that function in InitializeUserActions. |
| 29 // | 31 // |
| 30 // 3. Enjoy the recompilation. | 32 // 3. Enjoy the recompilation. |
| 31 // | 33 // |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 } | 75 } |
| 74 } | 76 } |
| 75 | 77 |
| 76 void ExternalMetrics::RecordAction(const char* action) { | 78 void ExternalMetrics::RecordAction(const char* action) { |
| 77 std::string action_string(action); | 79 std::string action_string(action); |
| 78 BrowserThread::PostTask( | 80 BrowserThread::PostTask( |
| 79 BrowserThread::UI, FROM_HERE, | 81 BrowserThread::UI, FROM_HERE, |
| 80 NewRunnableMethod(this, &ExternalMetrics::RecordActionUI, action)); | 82 NewRunnableMethod(this, &ExternalMetrics::RecordActionUI, action)); |
| 81 } | 83 } |
| 82 | 84 |
| 85 void ExternalMetrics::RecordCrashUI(const std::string& crash_kind) { |
| 86 if (g_browser_process && g_browser_process->metrics_service()) { |
| 87 g_browser_process->metrics_service()->LogChromeOSCrash(crash_kind); |
| 88 } |
| 89 } |
| 90 |
| 91 void ExternalMetrics::RecordCrash(const std::string& crash_kind) { |
| 92 BrowserThread::PostTask( |
| 93 BrowserThread::UI, FROM_HERE, |
| 94 NewRunnableMethod(this, &ExternalMetrics::RecordCrashUI, crash_kind)); |
| 95 } |
| 96 |
| 83 void ExternalMetrics::RecordHistogram(const char* histogram_data) { | 97 void ExternalMetrics::RecordHistogram(const char* histogram_data) { |
| 84 int sample, min, max, nbuckets; | 98 int sample, min, max, nbuckets; |
| 85 char name[128]; // length must be consistent with sscanf format below. | 99 char name[128]; // length must be consistent with sscanf format below. |
| 86 int n = sscanf(histogram_data, "%127s %d %d %d %d", | 100 int n = sscanf(histogram_data, "%127s %d %d %d %d", |
| 87 name, &sample, &min, &max, &nbuckets); | 101 name, &sample, &min, &max, &nbuckets); |
| 88 if (n != 5) { | 102 if (n != 5) { |
| 89 LOG(ERROR) << "bad histogram request: " << histogram_data; | 103 LOG(ERROR) << "bad histogram request: " << histogram_data; |
| 90 return; | 104 return; |
| 91 } | 105 } |
| 92 // Do not use the UMA_HISTOGRAM_... macros here. They cache the Histogram | 106 // Do not use the UMA_HISTOGRAM_... macros here. They cache the Histogram |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 memchr(p + 1, '\0', message_size - (p + 1 - buffer))); | 201 memchr(p + 1, '\0', message_size - (p + 1 - buffer))); |
| 188 } | 202 } |
| 189 if (q == NULL) { | 203 if (q == NULL) { |
| 190 LOG(ERROR) << "bad name-value pair for metrics"; | 204 LOG(ERROR) << "bad name-value pair for metrics"; |
| 191 break; | 205 break; |
| 192 } else { | 206 } else { |
| 193 char* name = reinterpret_cast<char*>(buffer); | 207 char* name = reinterpret_cast<char*>(buffer); |
| 194 char* value = reinterpret_cast<char*>(p + 1); | 208 char* value = reinterpret_cast<char*>(p + 1); |
| 195 if (test_recorder_ != NULL) { | 209 if (test_recorder_ != NULL) { |
| 196 test_recorder_(name, value); | 210 test_recorder_(name, value); |
| 211 } else if (strcmp(name, "crash") == 0) { |
| 212 RecordCrash(value); |
| 197 } else if (strcmp(name, "histogram") == 0) { | 213 } else if (strcmp(name, "histogram") == 0) { |
| 198 RecordHistogram(value); | 214 RecordHistogram(value); |
| 199 } else if (strcmp(name, "linearhistogram") == 0) { | 215 } else if (strcmp(name, "linearhistogram") == 0) { |
| 200 RecordLinearHistogram(value); | 216 RecordLinearHistogram(value); |
| 201 } else if (strcmp(name, "useraction") == 0) { | 217 } else if (strcmp(name, "useraction") == 0) { |
| 202 RecordAction(value); | 218 RecordAction(value); |
| 203 } else { | 219 } else { |
| 204 LOG(ERROR) << "invalid event type: " << name; | 220 LOG(ERROR) << "invalid event type: " << name; |
| 205 } | 221 } |
| 206 } | 222 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 230 void ExternalMetrics::ScheduleCollector() { | 246 void ExternalMetrics::ScheduleCollector() { |
| 231 bool result; | 247 bool result; |
| 232 result = BrowserThread::PostDelayedTask( | 248 result = BrowserThread::PostDelayedTask( |
| 233 BrowserThread::FILE, FROM_HERE, NewRunnableMethod( | 249 BrowserThread::FILE, FROM_HERE, NewRunnableMethod( |
| 234 this, &chromeos::ExternalMetrics::CollectEventsAndReschedule), | 250 this, &chromeos::ExternalMetrics::CollectEventsAndReschedule), |
| 235 kExternalMetricsCollectionIntervalMs); | 251 kExternalMetricsCollectionIntervalMs); |
| 236 DCHECK(result); | 252 DCHECK(result); |
| 237 } | 253 } |
| 238 | 254 |
| 239 } // namespace chromeos | 255 } // namespace chromeos |
| OLD | NEW |