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

Side by Side Diff: chrome/browser/chromeos/external_metrics.cc

Issue 6077013: Add support for collecting non-Chrome crash stats in Chrome OS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
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
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 &action_string) {
86 if (g_browser_process && g_browser_process->metrics_service()) {
87 g_browser_process->metrics_service()->LogChromeOSCrash(action_string);
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));
petkov 2011/01/06 18:50:36 You probably want to stay on the file thread -- no
kmixter1 2011/01/14 00:07:02 I'm not sure either. Will defer to an owner of th
jar (doing other things) 2011/01/18 22:32:23 I believe jumping over to the UI thread is both co
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
197 } else if (strcmp(name, "histogram") == 0) { 211 } else if (strcmp(name, "histogram") == 0) {
198 RecordHistogram(value); 212 RecordHistogram(value);
199 } else if (strcmp(name, "linearhistogram") == 0) { 213 } else if (strcmp(name, "linearhistogram") == 0) {
200 RecordLinearHistogram(value); 214 RecordLinearHistogram(value);
201 } else if (strcmp(name, "useraction") == 0) { 215 } else if (strcmp(name, "useraction") == 0) {
202 RecordAction(value); 216 RecordAction(value);
217 } else if (strcmp(name, "crash") == 0) {
petkov 2011/01/06 18:50:36 keep the ifs sorted?
kmixter1 2011/01/14 00:07:02 Done.
218 RecordCrash(value);
203 } else { 219 } else {
204 LOG(ERROR) << "invalid event type: " << name; 220 LOG(ERROR) << "invalid event type: " << name;
205 } 221 }
206 } 222 }
207 } 223 }
208 224
209 result = ftruncate(fd, 0); 225 result = ftruncate(fd, 0);
210 if (result < 0) { 226 if (result < 0) {
211 PLOG(ERROR) << "truncate metrics log"; 227 PLOG(ERROR) << "truncate metrics log";
212 } 228 }
(...skipping 17 matching lines...) Expand all
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698