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

Side by Side Diff: chrome/browser/net/websocket_experiment/websocket_experiment_task.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
« no previous file with comments | « chrome/browser/net/url_info.cc ('k') | chrome/browser/sessions/session_restore.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 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/net/websocket_experiment/websocket_experiment_task.h" 5 #include "chrome/browser/net/websocket_experiment/websocket_experiment_task.h"
6 6
7 #include "base/hash_tables.h" 7 #include "base/hash_tables.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "content/browser/browser_thread.h" 10 #include "content/browser/browser_thread.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 DCHECK(g_histogram_table); 166 DCHECK(g_histogram_table);
167 std::string counter_name = GetCounterNameForConfig(config, name); 167 std::string counter_name = GetCounterNameForConfig(config, name);
168 base::hash_map<std::string, Histogram*>::iterator found = 168 base::hash_map<std::string, Histogram*>::iterator found =
169 g_histogram_table->find(counter_name); 169 g_histogram_table->find(counter_name);
170 if (found != g_histogram_table->end()) { 170 if (found != g_histogram_table->end()) {
171 return found->second; 171 return found->second;
172 } 172 }
173 Histogram* counter = LinearHistogram::FactoryGet( 173 Histogram* counter = LinearHistogram::FactoryGet(
174 counter_name, 1, boundary_value, boundary_value + 1, 174 counter_name, 1, boundary_value, boundary_value + 1,
175 Histogram::kUmaTargetedHistogramFlag); 175 Histogram::kUmaTargetedHistogramFlag);
176 counter->AddRef(); // Released in ReleaseHistogram().
177 g_histogram_table->insert(std::make_pair(counter_name, counter)); 176 g_histogram_table->insert(std::make_pair(counter_name, counter));
178 return counter; 177 return counter;
179 } 178 }
180 179
181 static Histogram* GetTimesHistogramForConfig( 180 static Histogram* GetTimesHistogramForConfig(
182 const WebSocketExperimentTask::Config& config, 181 const WebSocketExperimentTask::Config& config,
183 const std::string& name, 182 const std::string& name,
184 base::TimeDelta min, 183 base::TimeDelta min,
185 base::TimeDelta max, 184 base::TimeDelta max,
186 size_t bucket_count) { 185 size_t bucket_count) {
187 DCHECK(g_histogram_table); 186 DCHECK(g_histogram_table);
188 std::string counter_name = GetCounterNameForConfig(config, name); 187 std::string counter_name = GetCounterNameForConfig(config, name);
189 base::hash_map<std::string, Histogram*>::iterator found = 188 base::hash_map<std::string, Histogram*>::iterator found =
190 g_histogram_table->find(counter_name); 189 g_histogram_table->find(counter_name);
191 if (found != g_histogram_table->end()) { 190 if (found != g_histogram_table->end()) {
192 return found->second; 191 return found->second;
193 } 192 }
194 Histogram* counter = Histogram::FactoryTimeGet( 193 Histogram* counter = Histogram::FactoryTimeGet(
195 counter_name, min, max, bucket_count, 194 counter_name, min, max, bucket_count,
196 Histogram::kUmaTargetedHistogramFlag); 195 Histogram::kUmaTargetedHistogramFlag);
197 counter->AddRef(); // Released in ReleaseHistogram().
198 g_histogram_table->insert(std::make_pair(counter_name, counter)); 196 g_histogram_table->insert(std::make_pair(counter_name, counter));
199 return counter; 197 return counter;
200 } 198 }
201 199
202 static void UpdateHistogramEnums( 200 static void UpdateHistogramEnums(
203 const WebSocketExperimentTask::Config& config, 201 const WebSocketExperimentTask::Config& config,
204 const std::string& name, 202 const std::string& name,
205 Histogram::Sample sample, 203 Histogram::Sample sample,
206 Histogram::Sample boundary_value) { 204 Histogram::Sample boundary_value) {
207 Histogram* counter = GetEnumsHistogramForConfig(config, name, boundary_value); 205 Histogram* counter = GetEnumsHistogramForConfig(config, name, boundary_value);
208 counter->Add(sample); 206 counter->Add(sample);
209 } 207 }
210 208
211 static void UpdateHistogramTimes( 209 static void UpdateHistogramTimes(
212 const WebSocketExperimentTask::Config& config, 210 const WebSocketExperimentTask::Config& config,
213 const std::string& name, 211 const std::string& name,
214 base::TimeDelta sample, 212 base::TimeDelta sample,
215 base::TimeDelta min, 213 base::TimeDelta min,
216 base::TimeDelta max, 214 base::TimeDelta max,
217 size_t bucket_count) { 215 size_t bucket_count) {
218 Histogram* counter = GetTimesHistogramForConfig( 216 Histogram* counter = GetTimesHistogramForConfig(
219 config, name, min, max, bucket_count); 217 config, name, min, max, bucket_count);
220 counter->AddTime(sample); 218 counter->AddTime(sample);
221 } 219 }
222 220
223 /* static */ 221 /* static */
224 void WebSocketExperimentTask::ReleaseHistogram() { 222 void WebSocketExperimentTask::ReleaseHistogram() {
225 DCHECK(g_histogram_table); 223 DCHECK(g_histogram_table);
226 for (base::hash_map<std::string, Histogram*>::iterator iter =
227 g_histogram_table->begin();
228 iter != g_histogram_table->end();
229 ++iter) {
230 Histogram* counter = iter->second;
231 if (counter != NULL)
232 counter->Release();
233 iter->second = NULL;
234 }
235 delete g_histogram_table; 224 delete g_histogram_table;
236 g_histogram_table = NULL; 225 g_histogram_table = NULL;
237 } 226 }
238 227
239 void WebSocketExperimentTask::Run() { 228 void WebSocketExperimentTask::Run() {
240 DVLOG(1) << "Run WebSocket experiment for " << config_.url << " " 229 DVLOG(1) << "Run WebSocket experiment for " << config_.url << " "
241 << GetProtocolVersionName(config_.protocol_version); 230 << GetProtocolVersionName(config_.protocol_version);
242 next_state_ = STATE_URL_FETCH; 231 next_state_ = STATE_URL_FETCH;
243 DoLoop(net::OK); 232 DoLoop(net::OK);
244 } 233 }
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 if (websocket) 636 if (websocket)
648 websocket->DetachDelegate(); 637 websocket->DetachDelegate();
649 DVLOG(1) << "Finish WebSocket experiment for " << config_.url 638 DVLOG(1) << "Finish WebSocket experiment for " << config_.url
650 << " " << GetProtocolVersionName(config_.protocol_version) 639 << " " << GetProtocolVersionName(config_.protocol_version)
651 << " next_state=" << next_state_ 640 << " next_state=" << next_state_
652 << " result=" << net::ErrorToString(result); 641 << " result=" << net::ErrorToString(result);
653 callback_->Run(result); // will release this. 642 callback_->Run(result); // will release this.
654 } 643 }
655 644
656 } // namespace chrome_browser_net 645 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/url_info.cc ('k') | chrome/browser/sessions/session_restore.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698