diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-23 22:43:53 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-23 22:43:53 +0000 |
commit | dec76e804867ced17b032571f440adf4945c4d99 (patch) | |
tree | fd798a848d7967b28d89350a55f48285057e2739 /base | |
parent | 0695ef4d095a441148ae80a08576c25c2ab8bc40 (diff) | |
download | chromium_src-dec76e804867ced17b032571f440adf4945c4d99.zip chromium_src-dec76e804867ced17b032571f440adf4945c4d99.tar.gz chromium_src-dec76e804867ced17b032571f440adf4945c4d99.tar.bz2 |
FBTF: Move virtual methods to implementation files.
Remove logging.h and other headers where possible.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3461019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60369 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/base.gypi | 1 | ||||
-rw-r--r-- | base/stats_counters.cc | 113 | ||||
-rw-r--r-- | base/stats_counters.h | 98 | ||||
-rw-r--r-- | base/watchdog.cc | 5 | ||||
-rw-r--r-- | base/watchdog.h | 5 |
5 files changed, 136 insertions, 86 deletions
diff --git a/base/base.gypi b/base/base.gypi index d594972..3c5e1a0 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -221,6 +221,7 @@ 'singleton.h', 'spin_wait.h', 'stack_container.h', + 'stats_counters.cc', 'stats_counters.h', 'stats_table.cc', 'stats_table.h', diff --git a/base/stats_counters.cc b/base/stats_counters.cc new file mode 100644 index 0000000..345e1d6 --- /dev/null +++ b/base/stats_counters.cc @@ -0,0 +1,113 @@ +// Copyright (c) 2010 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. + +#include "base/stats_counters.h" + +StatsCounter::StatsCounter(const std::string& name) + : counter_id_(-1) { + // We prepend the name with 'c:' to indicate that it is a counter. + name_ = "c:"; + name_.append(name); +} + +StatsCounter::~StatsCounter() { +} + +void StatsCounter::Set(int value) { + int* loc = GetPtr(); + if (loc) + *loc = value; +} + +void StatsCounter::Add(int value) { + int* loc = GetPtr(); + if (loc) + (*loc) += value; +} + +StatsCounter::StatsCounter() + : counter_id_(-1) { +} + +int* StatsCounter::GetPtr() { + StatsTable* table = StatsTable::current(); + if (!table) + return NULL; + + // If counter_id_ is -1, then we haven't looked it up yet. + if (counter_id_ == -1) { + counter_id_ = table->FindCounter(name_); + if (table->GetSlot() == 0) { + if (!table->RegisterThread("")) { + // There is no room for this thread. This thread + // cannot use counters. + counter_id_ = 0; + return NULL; + } + } + } + + // If counter_id_ is > 0, then we have a valid counter. + if (counter_id_ > 0) + return table->GetLocation(counter_id_, table->GetSlot()); + + // counter_id_ was zero, which means the table is full. + return NULL; +} + + +StatsCounterTimer::StatsCounterTimer(const std::string& name) { + // we prepend the name with 't:' to indicate that it is a timer. + name_ = "t:"; + name_.append(name); +} + +StatsCounterTimer::~StatsCounterTimer() { +} + +void StatsCounterTimer::Start() { + if (!Enabled()) + return; + start_time_ = base::TimeTicks::Now(); + stop_time_ = base::TimeTicks(); +} + +// Stop the timer and record the results. +void StatsCounterTimer::Stop() { + if (!Enabled() || !Running()) + return; + stop_time_ = base::TimeTicks::Now(); + Record(); +} + +// Returns true if the timer is running. +bool StatsCounterTimer::Running() { + return Enabled() && !start_time_.is_null() && stop_time_.is_null(); +} + +// Accept a TimeDelta to increment. +void StatsCounterTimer::AddTime(base::TimeDelta time) { + Add(static_cast<int>(time.InMilliseconds())); +} + +void StatsCounterTimer::Record() { + AddTime(stop_time_ - start_time_); +} + + +StatsRate::StatsRate(const char* name) + : StatsCounterTimer(name), + counter_(name), + largest_add_(std::string(" ").append(name).append("MAX").c_str()) { +} + +StatsRate::~StatsRate() { +} + +void StatsRate::Add(int value) { + counter_.Increment(); + StatsCounterTimer::Add(value); + if (value > largest_add_.value()) + largest_add_.Set(value); +} diff --git a/base/stats_counters.h b/base/stats_counters.h index b328736..defb9ee 100644 --- a/base/stats_counters.h +++ b/base/stats_counters.h @@ -75,31 +75,18 @@ class StatsCounter { public: // Create a StatsCounter object. - explicit StatsCounter(const std::string& name) - : counter_id_(-1) { - // We prepend the name with 'c:' to indicate that it is a counter. - name_ = "c:"; - name_.append(name); - }; - - virtual ~StatsCounter() {} + explicit StatsCounter(const std::string& name); + virtual ~StatsCounter(); // Sets the counter to a specific value. - void Set(int value) { - int* loc = GetPtr(); - if (loc) *loc = value; - } + void Set(int value); // Increments the counter. void Increment() { Add(1); } - virtual void Add(int value) { - int* loc = GetPtr(); - if (loc) - (*loc) += value; - } + virtual void Add(int value); // Decrements the counter. void Decrement() { @@ -123,36 +110,10 @@ class StatsCounter { } protected: - StatsCounter() - : counter_id_(-1) { - } + StatsCounter(); // Returns the cached address of this counter location. - int* GetPtr() { - StatsTable* table = StatsTable::current(); - if (!table) - return NULL; - - // If counter_id_ is -1, then we haven't looked it up yet. - if (counter_id_ == -1) { - counter_id_ = table->FindCounter(name_); - if (table->GetSlot() == 0) { - if (!table->RegisterThread("")) { - // There is no room for this thread. This thread - // cannot use counters. - counter_id_ = 0; - return NULL; - } - } - } - - // If counter_id_ is > 0, then we have a valid counter. - if (counter_id_ > 0) - return table->GetLocation(counter_id_, table->GetSlot()); - - // counter_id_ was zero, which means the table is full. - return NULL; - } + int* GetPtr(); std::string name_; // The counter id in the table. We initialize to -1 (an invalid value) @@ -168,43 +129,24 @@ class StatsCounter { class StatsCounterTimer : protected StatsCounter { public: // Constructs and starts the timer. - explicit StatsCounterTimer(const std::string& name) { - // we prepend the name with 't:' to indicate that it is a timer. - name_ = "t:"; - name_.append(name); - } + explicit StatsCounterTimer(const std::string& name); + virtual ~StatsCounterTimer(); // Start the timer. - void Start() { - if (!Enabled()) - return; - start_time_ = base::TimeTicks::Now(); - stop_time_ = base::TimeTicks(); - } + void Start(); // Stop the timer and record the results. - void Stop() { - if (!Enabled() || !Running()) - return; - stop_time_ = base::TimeTicks::Now(); - Record(); - } + void Stop(); // Returns true if the timer is running. - bool Running() { - return Enabled() && !start_time_.is_null() && stop_time_.is_null(); - } + bool Running(); // Accept a TimeDelta to increment. - virtual void AddTime(base::TimeDelta time) { - Add(static_cast<int>(time.InMilliseconds())); - } + virtual void AddTime(base::TimeDelta time); protected: // Compute the delta between start and stop, in milliseconds. - void Record() { - AddTime(stop_time_ - start_time_); - } + void Record(); base::TimeTicks start_time_; base::TimeTicks stop_time_; @@ -216,18 +158,10 @@ class StatsCounterTimer : protected StatsCounter { class StatsRate : public StatsCounterTimer { public: // Constructs and starts the timer. - explicit StatsRate(const char* name) - : StatsCounterTimer(name), - counter_(name), - largest_add_(std::string(" ").append(name).append("MAX").c_str()) { - } + explicit StatsRate(const char* name); + virtual ~StatsRate(); - virtual void Add(int value) { - counter_.Increment(); - StatsCounterTimer::Add(value); - if (value > largest_add_.value()) - largest_add_.Set(value); - } + virtual void Add(int value); private: StatsCounter counter_; diff --git a/base/watchdog.cc b/base/watchdog.cc index d78ec0c..b20d9fa 100644 --- a/base/watchdog.cc +++ b/base/watchdog.cc @@ -5,6 +5,7 @@ #include "base/watchdog.h" #include "base/compiler_specific.h" +#include "base/logging.h" #include "base/platform_thread.h" using base::TimeDelta; @@ -72,6 +73,10 @@ void Watchdog::Disarm() { // will check its state and time, and act accordingly. } +void Watchdog::Alarm() { + DLOG(INFO) << "Watchdog alarmed for " << thread_watched_name_; +} + //------------------------------------------------------------------------------ // Internal private methods that the watchdog thread uses. diff --git a/base/watchdog.h b/base/watchdog.h index fd8f444..b4262d4 100644 --- a/base/watchdog.h +++ b/base/watchdog.h @@ -23,7 +23,6 @@ #include "base/condition_variable.h" #include "base/lock.h" -#include "base/logging.h" #include "base/platform_thread.h" #include "base/time.h" @@ -45,9 +44,7 @@ class Watchdog { // Alarm is called if the time expires after an Arm() without someone calling // Disarm(). This method can be overridden to create testable classes. - virtual void Alarm() { - DLOG(INFO) << "Watchdog alarmed for " << thread_watched_name_; - } + virtual void Alarm(); // Reset static data to initial state. Useful for tests, to ensure // they are independent. |