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

Unified Diff: base/metrics/stats_counters.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/metrics/stats_counters.h ('k') | base/metrics/stats_table.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/stats_counters.cc
diff --git a/base/metrics/stats_counters.cc b/base/metrics/stats_counters.cc
deleted file mode 100644
index 12416d9f0f5578a5c5f14ba2973b7e1ea95d7dce..0000000000000000000000000000000000000000
--- a/base/metrics/stats_counters.cc
+++ /dev/null
@@ -1,125 +0,0 @@
-// 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/metrics/stats_counters.h"
-
-namespace base {
-
-StatsCounter::StatsCounter(const std::string& name)
- : counter_id_(-1) {
- // We prepend the name with 'c:' to indicate that it is a counter.
- if (StatsTable::current()) {
- // TODO(mbelshe): name_ construction is racy and it may corrupt memory for
- // static.
- 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(std::string())) {
- // 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.
- if (StatsTable::current()) {
- // TODO(mbelshe): name_ construction is racy and it may corrupt memory for
- // static.
- name_ = "t:";
- name_.append(name);
- }
-}
-
-StatsCounterTimer::~StatsCounterTimer() {
-}
-
-void StatsCounterTimer::Start() {
- if (!Enabled())
- return;
- start_time_ = TimeTicks::Now();
- stop_time_ = TimeTicks();
-}
-
-// Stop the timer and record the results.
-void StatsCounterTimer::Stop() {
- if (!Enabled() || !Running())
- return;
- stop_time_ = 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(TimeDelta time) {
- Add(static_cast<int>(time.InMilliseconds()));
-}
-
-void StatsCounterTimer::Record() {
- AddTime(stop_time_ - start_time_);
-}
-
-
-StatsRate::StatsRate(const std::string& name)
- : StatsCounterTimer(name),
- counter_(name),
- largest_add_(std::string(" ").append(name).append("MAX")) {
-}
-
-StatsRate::~StatsRate() {
-}
-
-void StatsRate::Add(int value) {
- counter_.Increment();
- StatsCounterTimer::Add(value);
- if (value > largest_add_.value())
- largest_add_.Set(value);
-}
-
-} // namespace base
« no previous file with comments | « base/metrics/stats_counters.h ('k') | base/metrics/stats_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698