OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/metrics/stats_counters.h" | 5 #include "base/metrics/stats_counters.h" |
6 | 6 |
7 namespace base { | 7 namespace base { |
8 | 8 |
9 StatsCounter::StatsCounter(const std::string& name) | 9 StatsCounter::StatsCounter(const std::string& name) |
10 : counter_id_(-1) { | 10 : counter_id_(-1) { |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 int* StatsCounter::GetPtr() { | 39 int* StatsCounter::GetPtr() { |
40 StatsTable* table = StatsTable::current(); | 40 StatsTable* table = StatsTable::current(); |
41 if (!table) | 41 if (!table) |
42 return NULL; | 42 return NULL; |
43 | 43 |
44 // If counter_id_ is -1, then we haven't looked it up yet. | 44 // If counter_id_ is -1, then we haven't looked it up yet. |
45 if (counter_id_ == -1) { | 45 if (counter_id_ == -1) { |
46 counter_id_ = table->FindCounter(name_); | 46 counter_id_ = table->FindCounter(name_); |
47 if (table->GetSlot() == 0) { | 47 if (table->GetSlot() == 0) { |
48 if (!table->RegisterThread("")) { | 48 if (!table->RegisterThread(std::string())) { |
49 // There is no room for this thread. This thread | 49 // There is no room for this thread. This thread |
50 // cannot use counters. | 50 // cannot use counters. |
51 counter_id_ = 0; | 51 counter_id_ = 0; |
52 return NULL; | 52 return NULL; |
53 } | 53 } |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 // If counter_id_ is > 0, then we have a valid counter. | 57 // If counter_id_ is > 0, then we have a valid counter. |
58 if (counter_id_ > 0) | 58 if (counter_id_ > 0) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 } | 116 } |
117 | 117 |
118 void StatsRate::Add(int value) { | 118 void StatsRate::Add(int value) { |
119 counter_.Increment(); | 119 counter_.Increment(); |
120 StatsCounterTimer::Add(value); | 120 StatsCounterTimer::Add(value); |
121 if (value > largest_add_.value()) | 121 if (value > largest_add_.value()) |
122 largest_add_.Set(value); | 122 largest_add_.Set(value); |
123 } | 123 } |
124 | 124 |
125 } // namespace base | 125 } // namespace base |
OLD | NEW |