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

Side by Side Diff: chrome/browser/chromeos/cros/cros_library_loader.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/cros/cros_library_loader.h" 5 #include "chrome/browser/chromeos/cros/cros_library_loader.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
14 #include "third_party/cros/chromeos_cros_api.h" 14 #include "third_party/cros/chromeos_cros_api.h"
15 15
16 namespace chromeos { 16 namespace chromeos {
17 17
18 namespace { 18 namespace {
19 19
20 void addLibcrosTimeHistogram(const char* name, const base::TimeDelta& delta) { 20 void addLibcrosTimeHistogram(const char* name, const base::TimeDelta& delta) {
21 static const base::TimeDelta min_time = base::TimeDelta::FromMilliseconds(1); 21 static const base::TimeDelta min_time = base::TimeDelta::FromMilliseconds(1);
22 static const base::TimeDelta max_time = base::TimeDelta::FromSeconds(1); 22 static const base::TimeDelta max_time = base::TimeDelta::FromSeconds(1);
23 const size_t bucket_count(10); 23 const size_t bucket_count(10);
24 DCHECK(name); 24 DCHECK(name);
25 scoped_refptr<base::Histogram> counter = base::Histogram::FactoryTimeGet( 25 base::Histogram* counter = base::Histogram::FactoryTimeGet(
26 std::string(name), 26 std::string(name),
27 min_time, 27 min_time,
28 max_time, 28 max_time,
29 bucket_count, 29 bucket_count,
30 base::Histogram::kNoFlags); 30 base::Histogram::kNoFlags);
31 if (counter.get()) { 31 counter->AddTime(delta);
32 counter->AddTime(delta); 32 VLOG(1) << "Cros Time: " << name << ": " << delta.InMilliseconds() << "ms.";
33 VLOG(1) << "Cros Time: " << name << ": " << delta.InMilliseconds() << "ms.";
34 }
35 } 33 }
36 34
37 } // namespace 35 } // namespace
38 36
39 bool CrosLibraryLoader::Load(std::string* load_error_string) { 37 bool CrosLibraryLoader::Load(std::string* load_error_string) {
40 bool loaded = false; 38 bool loaded = false;
41 FilePath path; 39 FilePath path;
42 if (PathService::Get(chrome::FILE_CHROMEOS_API, &path)) { 40 if (PathService::Get(chrome::FILE_CHROMEOS_API, &path)) {
43 loaded = LoadLibcros(path.value().c_str(), *load_error_string); 41 loaded = LoadLibcros(path.value().c_str(), *load_error_string);
44 if (loaded) 42 if (loaded)
45 SetLibcrosTimeHistogramFunction(addLibcrosTimeHistogram); 43 SetLibcrosTimeHistogramFunction(addLibcrosTimeHistogram);
46 } 44 }
47 45
48 if (!loaded) { 46 if (!loaded) {
49 LOG(ERROR) << "Problem loading chromeos shared object: " 47 LOG(ERROR) << "Problem loading chromeos shared object: "
50 << *load_error_string; 48 << *load_error_string;
51 } 49 }
52 return loaded; 50 return loaded;
53 } 51 }
54 52
55 } // namespace chromeos 53 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/boot_times_loader.cc ('k') | chrome/browser/chromeos/external_metrics.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698