diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-11 00:50:59 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-11 00:50:59 +0000 |
commit | eae9c0623d1800201739b4be146649103a45cd93 (patch) | |
tree | 2ce42f83e18d8a0a618ffd6dbe69b1acade5bda4 /base/metrics | |
parent | 26f0821d0a34a79e551213d56054366aab6c70f7 (diff) | |
download | chromium_src-eae9c0623d1800201739b4be146649103a45cd93.zip chromium_src-eae9c0623d1800201739b4be146649103a45cd93.tar.gz chromium_src-eae9c0623d1800201739b4be146649103a45cd93.tar.bz2 |
Order function definitions in base/ according to the header.
BUG=68682
TEST=compiles
Review URL: http://codereview.chromium.org/6085015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70975 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/metrics')
-rw-r--r-- | base/metrics/field_trial.cc | 30 | ||||
-rw-r--r-- | base/metrics/stats_table.cc | 254 |
2 files changed, 142 insertions, 142 deletions
diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc index d29ed2d..654746c 100644 --- a/base/metrics/field_trial.cc +++ b/base/metrics/field_trial.cc @@ -117,6 +117,14 @@ void FieldTrialList::Register(FieldTrial* trial) { } // static +FieldTrial* FieldTrialList::Find(const std::string& name) { + if (!global_) + return NULL; + AutoLock auto_lock(global_->lock_); + return global_->PreLockedFind(name); +} + +// static int FieldTrialList::FindValue(const std::string& name) { FieldTrial* field_trial = Find(name); if (field_trial) @@ -133,21 +141,6 @@ std::string FieldTrialList::FindFullName(const std::string& name) { } // static -FieldTrial* FieldTrialList::Find(const std::string& name) { - if (!global_) - return NULL; - AutoLock auto_lock(global_->lock_); - return global_->PreLockedFind(name); -} - -FieldTrial* FieldTrialList::PreLockedFind(const std::string& name) { - RegistrationList::iterator it = registered_.find(name); - if (registered_.end() == it) - return NULL; - return it->second; -} - -// static void FieldTrialList::StatesToString(std::string* output) { if (!global_) return; @@ -210,4 +203,11 @@ size_t FieldTrialList::GetFieldTrialCount() { return global_->registered_.size(); } +FieldTrial* FieldTrialList::PreLockedFind(const std::string& name) { + RegistrationList::iterator it = registered_.find(name); + if (registered_.end() == it) + return NULL; + return it->second; +} + } // namespace base diff --git a/base/metrics/stats_table.cc b/base/metrics/stats_table.cc index 0e4cad9..bae2c96 100644 --- a/base/metrics/stats_table.cc +++ b/base/metrics/stats_table.cc @@ -278,6 +278,13 @@ StatsTable::~StatsTable() { global_table_ = NULL; } +int StatsTable::GetSlot() const { + TLSData* data = GetTLSData(); + if (!data) + return 0; + return data->slot; +} + int StatsTable::RegisterThread(const std::string& name) { int slot = 0; if (!impl_) @@ -311,15 +318,121 @@ int StatsTable::RegisterThread(const std::string& name) { return slot; } -StatsTable::TLSData* StatsTable::GetTLSData() const { - TLSData* data = - static_cast<TLSData*>(tls_index_.Get()); - if (!data) +int StatsTable::CountThreadsRegistered() const { + if (!impl_) + return 0; + + // Loop through the shared memory and count the threads that are active. + // We intentionally do not lock the table during the operation. + int count = 0; + for (int index = 1; index <= impl_->max_threads(); index++) { + char* name = impl_->thread_name(index); + if (*name != '\0') + count++; + } + return count; +} + +int StatsTable::FindCounter(const std::string& name) { + // Note: the API returns counters numbered from 1..N, although + // internally, the array is 0..N-1. This is so that we can return + // zero as "not found". + if (!impl_) + return 0; + + // Create a scope for our auto-lock. + { + AutoLock scoped_lock(counters_lock_); + + // Attempt to find the counter. + CountersMap::const_iterator iter; + iter = counters_.find(name); + if (iter != counters_.end()) + return iter->second; + } + + // Counter does not exist, so add it. + return AddCounter(name); +} + +int* StatsTable::GetLocation(int counter_id, int slot_id) const { + if (!impl_) + return NULL; + if (slot_id > impl_->max_threads()) return NULL; - DCHECK(data->slot); - DCHECK_EQ(data->table, this); - return data; + int* row = impl_->row(counter_id); + return &(row[slot_id-1]); +} + +const char* StatsTable::GetRowName(int index) const { + if (!impl_) + return NULL; + + return impl_->counter_name(index); +} + +int StatsTable::GetRowValue(int index) const { + return GetRowValue(index, 0); +} + +int StatsTable::GetRowValue(int index, int pid) const { + if (!impl_) + return 0; + + int rv = 0; + int* row = impl_->row(index); + for (int slot_id = 0; slot_id < impl_->max_threads(); slot_id++) { + if (pid == 0 || *impl_->thread_pid(slot_id) == pid) + rv += row[slot_id]; + } + return rv; +} + +int StatsTable::GetCounterValue(const std::string& name) { + return GetCounterValue(name, 0); +} + +int StatsTable::GetCounterValue(const std::string& name, int pid) { + if (!impl_) + return 0; + + int row = FindCounter(name); + if (!row) + return 0; + return GetRowValue(row, pid); +} + +int StatsTable::GetMaxCounters() const { + if (!impl_) + return 0; + return impl_->max_counters(); +} + +int StatsTable::GetMaxThreads() const { + if (!impl_) + return 0; + return impl_->max_threads(); +} + +int* StatsTable::FindLocation(const char* name) { + // Get the static StatsTable + StatsTable *table = StatsTable::current(); + if (!table) + return NULL; + + // Get the slot for this thread. Try to register + // it if none exists. + int slot = table->GetSlot(); + if (!slot && !(slot = table->RegisterThread(""))) + return NULL; + + // Find the counter id for the counter. + std::string str_name(name); + int counter = table->FindCounter(str_name); + + // Now we can find the location in the table. + return table->GetLocation(counter, slot); } void StatsTable::UnregisterThread() { @@ -351,28 +464,6 @@ void StatsTable::SlotReturnFunction(void* data) { } } -int StatsTable::CountThreadsRegistered() const { - if (!impl_) - return 0; - - // Loop through the shared memory and count the threads that are active. - // We intentionally do not lock the table during the operation. - int count = 0; - for (int index = 1; index <= impl_->max_threads(); index++) { - char* name = impl_->thread_name(index); - if (*name != '\0') - count++; - } - return count; -} - -int StatsTable::GetSlot() const { - TLSData* data = GetTLSData(); - if (!data) - return 0; - return data->slot; -} - int StatsTable::FindEmptyThread() const { // Note: the API returns slots numbered from 1..N, although // internally, the array is 0..N-1. This is so that we can return @@ -418,28 +509,6 @@ int StatsTable::FindCounterOrEmptyRow(const std::string& name) const { return free_slot; } -int StatsTable::FindCounter(const std::string& name) { - // Note: the API returns counters numbered from 1..N, although - // internally, the array is 0..N-1. This is so that we can return - // zero as "not found". - if (!impl_) - return 0; - - // Create a scope for our auto-lock. - { - AutoLock scoped_lock(counters_lock_); - - // Attempt to find the counter. - CountersMap::const_iterator iter; - iter = counters_.find(name); - if (iter != counters_.end()) - return iter->second; - } - - // Counter does not exist, so add it. - return AddCounter(name); -} - int StatsTable::AddCounter(const std::string& name) { if (!impl_) return 0; @@ -470,84 +539,15 @@ int StatsTable::AddCounter(const std::string& name) { return counter_id; } -int* StatsTable::GetLocation(int counter_id, int slot_id) const { - if (!impl_) - return NULL; - if (slot_id > impl_->max_threads()) - return NULL; - - int* row = impl_->row(counter_id); - return &(row[slot_id-1]); -} - -const char* StatsTable::GetRowName(int index) const { - if (!impl_) - return NULL; - - return impl_->counter_name(index); -} - -int StatsTable::GetRowValue(int index, int pid) const { - if (!impl_) - return 0; - - int rv = 0; - int* row = impl_->row(index); - for (int slot_id = 0; slot_id < impl_->max_threads(); slot_id++) { - if (pid == 0 || *impl_->thread_pid(slot_id) == pid) - rv += row[slot_id]; - } - return rv; -} - -int StatsTable::GetRowValue(int index) const { - return GetRowValue(index, 0); -} - -int StatsTable::GetCounterValue(const std::string& name, int pid) { - if (!impl_) - return 0; - - int row = FindCounter(name); - if (!row) - return 0; - return GetRowValue(row, pid); -} - -int StatsTable::GetCounterValue(const std::string& name) { - return GetCounterValue(name, 0); -} - -int StatsTable::GetMaxCounters() const { - if (!impl_) - return 0; - return impl_->max_counters(); -} - -int StatsTable::GetMaxThreads() const { - if (!impl_) - return 0; - return impl_->max_threads(); -} - -int* StatsTable::FindLocation(const char* name) { - // Get the static StatsTable - StatsTable *table = StatsTable::current(); - if (!table) +StatsTable::TLSData* StatsTable::GetTLSData() const { + TLSData* data = + static_cast<TLSData*>(tls_index_.Get()); + if (!data) return NULL; - // Get the slot for this thread. Try to register - // it if none exists. - int slot = table->GetSlot(); - if (!slot && !(slot = table->RegisterThread(""))) - return NULL; - - // Find the counter id for the counter. - std::string str_name(name); - int counter = table->FindCounter(str_name); - - // Now we can find the location in the table. - return table->GetLocation(counter, slot); + DCHECK(data->slot); + DCHECK_EQ(data->table, this); + return data; } } // namespace base |