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

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

Issue 6780035: Use lock-free lazy initialization for static histogram references (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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) 2011 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>
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 int sample, min, max, nbuckets; 79 int sample, min, max, nbuckets;
80 char name[128]; // length must be consistent with sscanf format below. 80 char name[128]; // length must be consistent with sscanf format below.
81 int n = sscanf(histogram_data, "%127s %d %d %d %d", 81 int n = sscanf(histogram_data, "%127s %d %d %d %d",
82 name, &sample, &min, &max, &nbuckets); 82 name, &sample, &min, &max, &nbuckets);
83 if (n != 5) { 83 if (n != 5) {
84 LOG(ERROR) << "bad histogram request: " << histogram_data; 84 LOG(ERROR) << "bad histogram request: " << histogram_data;
85 return; 85 return;
86 } 86 }
87 // Do not use the UMA_HISTOGRAM_... macros here. They cache the Histogram 87 // Do not use the UMA_HISTOGRAM_... macros here. They cache the Histogram
88 // instance and thus only work if |name| is constant. 88 // instance and thus only work if |name| is constant.
89 scoped_refptr<base::Histogram> counter = base::Histogram::FactoryGet( 89 base::Histogram* counter = base::Histogram::FactoryGet(
90 name, min, max, nbuckets, base::Histogram::kUmaTargetedHistogramFlag); 90 name, min, max, nbuckets, base::Histogram::kUmaTargetedHistogramFlag);
91 counter->Add(sample); 91 counter->Add(sample);
92 } 92 }
93 93
94 void ExternalMetrics::RecordLinearHistogram(const char* histogram_data) { 94 void ExternalMetrics::RecordLinearHistogram(const char* histogram_data) {
95 int sample, max; 95 int sample, max;
96 char name[128]; // length must be consistent with sscanf format below. 96 char name[128]; // length must be consistent with sscanf format below.
97 int n = sscanf(histogram_data, "%127s %d %d", name, &sample, &max); 97 int n = sscanf(histogram_data, "%127s %d %d", name, &sample, &max);
98 if (n != 3) { 98 if (n != 3) {
99 LOG(ERROR) << "bad linear histogram request: " << histogram_data; 99 LOG(ERROR) << "bad linear histogram request: " << histogram_data;
100 return; 100 return;
101 } 101 }
102 // Do not use the UMA_HISTOGRAM_... macros here. They cache the Histogram 102 // Do not use the UMA_HISTOGRAM_... macros here. They cache the Histogram
103 // instance and thus only work if |name| is constant. 103 // instance and thus only work if |name| is constant.
104 scoped_refptr<base::Histogram> counter = base::LinearHistogram::FactoryGet( 104 base::Histogram* counter = base::LinearHistogram::FactoryGet(
105 name, 1, max, max + 1, base::Histogram::kUmaTargetedHistogramFlag); 105 name, 1, max, max + 1, base::Histogram::kUmaTargetedHistogramFlag);
106 counter->Add(sample); 106 counter->Add(sample);
107 } 107 }
108 108
109 void ExternalMetrics::CollectEvents() { 109 void ExternalMetrics::CollectEvents() {
110 const char* event_file_path = "/var/log/metrics/uma-events"; 110 const char* event_file_path = "/var/log/metrics/uma-events";
111 struct stat stat_buf; 111 struct stat stat_buf;
112 int result; 112 int result;
113 if (!test_path_.empty()) { 113 if (!test_path_.empty()) {
114 event_file_path = test_path_.value().c_str(); 114 event_file_path = test_path_.value().c_str();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 void ExternalMetrics::ScheduleCollector() { 227 void ExternalMetrics::ScheduleCollector() {
228 bool result; 228 bool result;
229 result = BrowserThread::PostDelayedTask( 229 result = BrowserThread::PostDelayedTask(
230 BrowserThread::FILE, FROM_HERE, NewRunnableMethod( 230 BrowserThread::FILE, FROM_HERE, NewRunnableMethod(
231 this, &chromeos::ExternalMetrics::CollectEventsAndReschedule), 231 this, &chromeos::ExternalMetrics::CollectEventsAndReschedule),
232 kExternalMetricsCollectionIntervalMs); 232 kExternalMetricsCollectionIntervalMs);
233 DCHECK(result); 233 DCHECK(result);
234 } 234 }
235 235
236 } // namespace chromeos 236 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/cros_library_loader.cc ('k') | chrome/browser/extensions/extension_metrics_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698