summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-05 04:48:53 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-05 04:48:53 +0000
commit81ce9f3b1eb34dc7f6954f0f6657a76b0f01fc12 (patch)
tree41b3caf1a55ba3cfa2f6cf13b0a5ce3d773d631f /chrome
parent4f7f4854821e8e4933ad2c662bfd9417eb604a68 (diff)
downloadchromium_src-81ce9f3b1eb34dc7f6954f0f6657a76b0f01fc12.zip
chromium_src-81ce9f3b1eb34dc7f6954f0f6657a76b0f01fc12.tar.gz
chromium_src-81ce9f3b1eb34dc7f6954f0f6657a76b0f01fc12.tar.bz2
Use lock-free lazy initialization for static histogram references
Make all histogram macros thread safe, and fast by again using statics to achieve performance. ...at the cost of: Leak all histograms to avoid races at shutdown. Also included leak suppression for valgrind. r=rtenneti BUG=78207 Review URL: http://codereview.chromium.org/6780035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80412 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete.cc2
-rw-r--r--chrome/browser/autocomplete/history_quick_provider.cc2
-rw-r--r--chrome/browser/chromeos/boot_times_loader.cc4
-rw-r--r--chrome/browser/chromeos/cros/cros_library_loader.cc10
-rw-r--r--chrome/browser/chromeos/external_metrics.cc6
-rw-r--r--chrome/browser/extensions/extension_metrics_apitest.cc2
-rw-r--r--chrome/browser/extensions/extension_metrics_module.cc4
-rw-r--r--chrome/browser/jankometer.cc16
-rw-r--r--chrome/browser/metrics/thread_watcher.cc1
-rw-r--r--chrome/browser/metrics/thread_watcher.h2
-rw-r--r--chrome/browser/net/url_info.cc9
-rw-r--r--chrome/browser/net/websocket_experiment/websocket_experiment_task.cc11
-rw-r--r--chrome/browser/sessions/session_restore.cc4
-rw-r--r--chrome/renderer/render_thread.cc8
-rw-r--r--chrome/renderer/renderer_main.cc2
15 files changed, 34 insertions, 49 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc
index 6d2c6c9..b076dc0 100644
--- a/chrome/browser/autocomplete/autocomplete.cc
+++ b/chrome/browser/autocomplete/autocomplete.cc
@@ -863,7 +863,7 @@ void AutocompleteController::Start(
if (matches_requested == AutocompleteInput::ALL_MATCHES && text.size() < 6) {
base::TimeTicks end_time = base::TimeTicks::Now();
std::string name = "Omnibox.QueryTime." + base::IntToString(text.size());
- scoped_refptr<base::Histogram> counter = base::Histogram::FactoryGet(
+ base::Histogram* counter = base::Histogram::FactoryGet(
name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag);
counter->Add(static_cast<int>((end_time - start_time).InMilliseconds()));
}
diff --git a/chrome/browser/autocomplete/history_quick_provider.cc b/chrome/browser/autocomplete/history_quick_provider.cc
index 778d345..8a7046a 100644
--- a/chrome/browser/autocomplete/history_quick_provider.cc
+++ b/chrome/browser/autocomplete/history_quick_provider.cc
@@ -71,7 +71,7 @@ void HistoryQuickProvider::Start(const AutocompleteInput& input,
base::TimeTicks end_time = base::TimeTicks::Now();
std::string name = "HistoryQuickProvider.QueryIndexTime." +
base::IntToString(input.text().size());
- scoped_refptr<base::Histogram> counter = base::Histogram::FactoryGet(
+ base::Histogram* counter = base::Histogram::FactoryGet(
name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag);
counter->Add(static_cast<int>((end_time - start_time).InMilliseconds()));
}
diff --git a/chrome/browser/chromeos/boot_times_loader.cc b/chrome/browser/chromeos/boot_times_loader.cc
index 4e08290..03359cf 100644
--- a/chrome/browser/chromeos/boot_times_loader.cc
+++ b/chrome/browser/chromeos/boot_times_loader.cc
@@ -259,7 +259,7 @@ void BootTimesLoader::WriteTimes(
base::Time first = login_times.front().time();
base::Time last = login_times.back().time();
base::TimeDelta total = last - first;
- scoped_refptr<base::Histogram>total_hist = base::Histogram::FactoryTimeGet(
+ base::Histogram* total_hist = base::Histogram::FactoryTimeGet(
uma_name,
base::TimeDelta::FromMilliseconds(kMinTimeMillis),
base::TimeDelta::FromMilliseconds(kMaxTimeMillis),
@@ -277,7 +277,7 @@ void BootTimesLoader::WriteTimes(
if (tm.send_to_uma()) {
name = uma_prefix + tm.name();
- scoped_refptr<base::Histogram>prev_hist = base::Histogram::FactoryTimeGet(
+ base::Histogram* prev_hist = base::Histogram::FactoryTimeGet(
name,
base::TimeDelta::FromMilliseconds(kMinTimeMillis),
base::TimeDelta::FromMilliseconds(kMaxTimeMillis),
diff --git a/chrome/browser/chromeos/cros/cros_library_loader.cc b/chrome/browser/chromeos/cros/cros_library_loader.cc
index d631a6c..660bc2c 100644
--- a/chrome/browser/chromeos/cros/cros_library_loader.cc
+++ b/chrome/browser/chromeos/cros/cros_library_loader.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -22,16 +22,14 @@ void addLibcrosTimeHistogram(const char* name, const base::TimeDelta& delta) {
static const base::TimeDelta max_time = base::TimeDelta::FromSeconds(1);
const size_t bucket_count(10);
DCHECK(name);
- scoped_refptr<base::Histogram> counter = base::Histogram::FactoryTimeGet(
+ base::Histogram* counter = base::Histogram::FactoryTimeGet(
std::string(name),
min_time,
max_time,
bucket_count,
base::Histogram::kNoFlags);
- if (counter.get()) {
- counter->AddTime(delta);
- VLOG(1) << "Cros Time: " << name << ": " << delta.InMilliseconds() << "ms.";
- }
+ counter->AddTime(delta);
+ VLOG(1) << "Cros Time: " << name << ": " << delta.InMilliseconds() << "ms.";
}
} // namespace
diff --git a/chrome/browser/chromeos/external_metrics.cc b/chrome/browser/chromeos/external_metrics.cc
index edd48c0..830de18 100644
--- a/chrome/browser/chromeos/external_metrics.cc
+++ b/chrome/browser/chromeos/external_metrics.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -86,7 +86,7 @@ void ExternalMetrics::RecordHistogram(const char* histogram_data) {
}
// Do not use the UMA_HISTOGRAM_... macros here. They cache the Histogram
// instance and thus only work if |name| is constant.
- scoped_refptr<base::Histogram> counter = base::Histogram::FactoryGet(
+ base::Histogram* counter = base::Histogram::FactoryGet(
name, min, max, nbuckets, base::Histogram::kUmaTargetedHistogramFlag);
counter->Add(sample);
}
@@ -101,7 +101,7 @@ void ExternalMetrics::RecordLinearHistogram(const char* histogram_data) {
}
// Do not use the UMA_HISTOGRAM_... macros here. They cache the Histogram
// instance and thus only work if |name| is constant.
- scoped_refptr<base::Histogram> counter = base::LinearHistogram::FactoryGet(
+ base::Histogram* counter = base::LinearHistogram::FactoryGet(
name, 1, max, max + 1, base::Histogram::kUmaTargetedHistogramFlag);
counter->Add(sample);
}
diff --git a/chrome/browser/extensions/extension_metrics_apitest.cc b/chrome/browser/extensions/extension_metrics_apitest.cc
index ea5f9c6..522ea40 100644
--- a/chrome/browser/extensions/extension_metrics_apitest.cc
+++ b/chrome/browser/extensions/extension_metrics_apitest.cc
@@ -123,7 +123,7 @@ void ValidateHistograms(const Extension* extension,
size_t j = 0;
for (j = 0; j < histograms.size(); ++j) {
- scoped_refptr<base::Histogram> histogram(histograms[j]);
+ base::Histogram* histogram(histograms[j]);
if (name == histogram->histogram_name()) {
EXPECT_EQ(r.type, histogram->histogram_type());
diff --git a/chrome/browser/extensions/extension_metrics_module.cc b/chrome/browser/extensions/extension_metrics_module.cc
index a06d6fd..9681d84 100644
--- a/chrome/browser/extensions/extension_metrics_module.cc
+++ b/chrome/browser/extensions/extension_metrics_module.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -75,7 +75,7 @@ bool MetricsHistogramHelperFunction::RecordValue(const std::string& name,
size_t buckets,
int sample) {
std::string full_name = BuildMetricName(name, GetExtension());
- scoped_refptr<Histogram> counter;
+ Histogram* counter;
if (type == Histogram::LINEAR_HISTOGRAM) {
counter = LinearHistogram::FactoryGet(full_name,
min,
diff --git a/chrome/browser/jankometer.cc b/chrome/browser/jankometer.cc
index 294860c..14be3be 100644
--- a/chrome/browser/jankometer.cc
+++ b/chrome/browser/jankometer.cc
@@ -119,8 +119,8 @@ class JankObserverHelper {
// Counters for the two types of jank we measure.
base::StatsCounter slow_processing_counter_; // Msgs w/ long proc time.
base::StatsCounter queueing_delay_counter_; // Msgs w/ long queueing delay.
- scoped_refptr<base::Histogram> process_times_; // Time spent proc. task.
- scoped_refptr<base::Histogram> total_times_; // Total queueing plus proc.
+ base::Histogram* const process_times_; // Time spent proc. task.
+ base::Histogram* const total_times_; // Total queueing plus proc.
JankWatchdog total_time_watchdog_; // Watching for excessive total_time.
DISALLOW_COPY_AND_ASSIGN(JankObserverHelper);
@@ -135,13 +135,13 @@ JankObserverHelper::JankObserverHelper(
events_till_measurement_(0),
slow_processing_counter_(std::string("Chrome.SlowMsg") + thread_name),
queueing_delay_counter_(std::string("Chrome.DelayMsg") + thread_name),
+ process_times_(base::Histogram::FactoryGet(
+ std::string("Chrome.ProcMsgL ") + thread_name,
+ 1, 3600000, 50, base::Histogram::kUmaTargetedHistogramFlag)),
+ total_times_(base::Histogram::FactoryGet(
+ std::string("Chrome.TotalMsgL ") + thread_name,
+ 1, 3600000, 50, base::Histogram::kUmaTargetedHistogramFlag)),
total_time_watchdog_(excessive_duration, thread_name, watchdog_enable) {
- process_times_ = base::Histogram::FactoryGet(
- std::string("Chrome.ProcMsgL ") + thread_name,
- 1, 3600000, 50, base::Histogram::kUmaTargetedHistogramFlag);
- total_times_ = base::Histogram::FactoryGet(
- std::string("Chrome.TotalMsgL ") + thread_name,
- 1, 3600000, 50, base::Histogram::kUmaTargetedHistogramFlag);
if (discard_count_ > 0) {
// Select a vaguely random sample-start-point.
events_till_measurement_ = static_cast<int>(
diff --git a/chrome/browser/metrics/thread_watcher.cc b/chrome/browser/metrics/thread_watcher.cc
index dcad2bd..8318f8c 100644
--- a/chrome/browser/metrics/thread_watcher.cc
+++ b/chrome/browser/metrics/thread_watcher.cc
@@ -28,6 +28,7 @@ ThreadWatcher::ThreadWatcher(const BrowserThread::ID& thread_id,
ping_sequence_number_(0),
active_(false),
ping_count_(kPingCount),
+ histogram_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
Initialize();
}
diff --git a/chrome/browser/metrics/thread_watcher.h b/chrome/browser/metrics/thread_watcher.h
index ed9f84c..53cdb8d 100644
--- a/chrome/browser/metrics/thread_watcher.h
+++ b/chrome/browser/metrics/thread_watcher.h
@@ -186,7 +186,7 @@ class ThreadWatcher {
int ping_count_;
// Histogram that keeps track of response times for the watched thread.
- scoped_refptr<base::Histogram> histogram_;
+ base::Histogram* histogram_;
// We use this factory to create callback tasks for ThreadWatcher object. We
// use this during ping-pong messaging between WatchDog thread and watched
diff --git a/chrome/browser/net/url_info.cc b/chrome/browser/net/url_info.cc
index 3ed81a1..9606ff5 100644
--- a/chrome/browser/net/url_info.cc
+++ b/chrome/browser/net/url_info.cc
@@ -120,10 +120,11 @@ void UrlInfo::RemoveFromQueue() {
}
// Make a custom linear histogram for the region from 0 to boundary.
const size_t kBucketCount = 52;
- scoped_refptr<base::Histogram> histogram =
- base::LinearHistogram::FactoryTimeGet(
- "DNS.QueueRecycledUnder2", TimeDelta(), kBoundary, kBucketCount,
- base::Histogram::kUmaTargetedHistogramFlag);
+ static base::Histogram* histogram(NULL);
+ if (!histogram)
+ histogram = base::LinearHistogram::FactoryTimeGet(
+ "DNS.QueueRecycledUnder2", TimeDelta(), kBoundary, kBucketCount,
+ base::Histogram::kUmaTargetedHistogramFlag);
histogram->AddTime(queue_duration_);
}
diff --git a/chrome/browser/net/websocket_experiment/websocket_experiment_task.cc b/chrome/browser/net/websocket_experiment/websocket_experiment_task.cc
index c410778..6e59658 100644
--- a/chrome/browser/net/websocket_experiment/websocket_experiment_task.cc
+++ b/chrome/browser/net/websocket_experiment/websocket_experiment_task.cc
@@ -173,7 +173,6 @@ static Histogram* GetEnumsHistogramForConfig(
Histogram* counter = LinearHistogram::FactoryGet(
counter_name, 1, boundary_value, boundary_value + 1,
Histogram::kUmaTargetedHistogramFlag);
- counter->AddRef(); // Released in ReleaseHistogram().
g_histogram_table->insert(std::make_pair(counter_name, counter));
return counter;
}
@@ -194,7 +193,6 @@ static Histogram* GetTimesHistogramForConfig(
Histogram* counter = Histogram::FactoryTimeGet(
counter_name, min, max, bucket_count,
Histogram::kUmaTargetedHistogramFlag);
- counter->AddRef(); // Released in ReleaseHistogram().
g_histogram_table->insert(std::make_pair(counter_name, counter));
return counter;
}
@@ -223,15 +221,6 @@ static void UpdateHistogramTimes(
/* static */
void WebSocketExperimentTask::ReleaseHistogram() {
DCHECK(g_histogram_table);
- for (base::hash_map<std::string, Histogram*>::iterator iter =
- g_histogram_table->begin();
- iter != g_histogram_table->end();
- ++iter) {
- Histogram* counter = iter->second;
- if (counter != NULL)
- counter->Release();
- iter->second = NULL;
- }
delete g_histogram_table;
g_histogram_table = NULL;
}
diff --git a/chrome/browser/sessions/session_restore.cc b/chrome/browser/sessions/session_restore.cc
index c98f7b3..bf60878 100644
--- a/chrome/browser/sessions/session_restore.cc
+++ b/chrome/browser/sessions/session_restore.cc
@@ -300,7 +300,7 @@ void TabLoader::Observe(NotificationType type,
// contention.
std::string time_for_count =
StringPrintf("SessionRestore.FirstTabPainted_%d", tab_count_);
- scoped_refptr<base::Histogram> counter_for_count =
+ base::Histogram* counter_for_count =
base::Histogram::FactoryTimeGet(
time_for_count,
base::TimeDelta::FromMilliseconds(10),
@@ -388,7 +388,7 @@ void TabLoader::HandleTabClosedOrLoaded(NavigationController* tab) {
// Record a time for the number of tabs, to help track down contention.
std::string time_for_count =
StringPrintf("SessionRestore.AllTabsLoaded_%d", tab_count_);
- scoped_refptr<base::Histogram> counter_for_count =
+ base::Histogram* counter_for_count =
base::Histogram::FactoryTimeGet(
time_for_count,
base::TimeDelta::FromMilliseconds(10),
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc
index 77b6fcc..456bedf 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -798,13 +798,9 @@ static void* CreateHistogram(
const char *name, int min, int max, size_t buckets) {
if (min <= 0)
min = 1;
- scoped_refptr<base::Histogram> histogram = base::Histogram::FactoryGet(
+ base::Histogram* histogram = base::Histogram::FactoryGet(
name, min, max, buckets, base::Histogram::kUmaTargetedHistogramFlag);
- // We'll end up leaking these histograms, unless there is some code hiding in
- // there to do the dec-ref.
- // TODO(jar): Handle reference counting in webkit glue.
- histogram->AddRef();
- return histogram.get();
+ return histogram;
}
static void AddHistogramSample(void* hist, int sample) {
diff --git a/chrome/renderer/renderer_main.cc b/chrome/renderer/renderer_main.cc
index cd3bb5d..df75219e 100644
--- a/chrome/renderer/renderer_main.cc
+++ b/chrome/renderer/renderer_main.cc
@@ -197,7 +197,7 @@ class RendererMessageLoopObserver : public MessageLoop::TaskObserver {
private:
base::TimeTicks begin_process_message_;
- scoped_refptr<base::Histogram> process_times_;
+ base::Histogram* const process_times_;
DISALLOW_COPY_AND_ASSIGN(RendererMessageLoopObserver);
};