OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/histogram_base.h" | 5 #include "base/metrics/histogram_base.h" |
6 | 6 |
7 #include <climits> | 7 #include <limits.h> |
| 8 |
8 #include <utility> | 9 #include <utility> |
9 | 10 |
10 #include "base/json/json_string_value_serializer.h" | 11 #include "base/json/json_string_value_serializer.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
14 #include "base/metrics/histogram_samples.h" | 15 #include "base/metrics/histogram_samples.h" |
15 #include "base/metrics/sparse_histogram.h" | 16 #include "base/metrics/sparse_histogram.h" |
16 #include "base/metrics/statistics_recorder.h" | 17 #include "base/metrics/statistics_recorder.h" |
17 #include "base/pickle.h" | 18 #include "base/pickle.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 HistogramBase::HistogramBase(const std::string& name) | 66 HistogramBase::HistogramBase(const std::string& name) |
66 : histogram_name_(name), | 67 : histogram_name_(name), |
67 flags_(kNoFlags) {} | 68 flags_(kNoFlags) {} |
68 | 69 |
69 HistogramBase::~HistogramBase() {} | 70 HistogramBase::~HistogramBase() {} |
70 | 71 |
71 void HistogramBase::CheckName(const StringPiece& name) const { | 72 void HistogramBase::CheckName(const StringPiece& name) const { |
72 DCHECK_EQ(histogram_name(), name); | 73 DCHECK_EQ(histogram_name(), name); |
73 } | 74 } |
74 | 75 |
75 void HistogramBase::SetFlags(int32 flags) { | 76 void HistogramBase::SetFlags(int32_t flags) { |
76 HistogramBase::Count old_flags = subtle::NoBarrier_Load(&flags_); | 77 HistogramBase::Count old_flags = subtle::NoBarrier_Load(&flags_); |
77 subtle::NoBarrier_Store(&flags_, old_flags | flags); | 78 subtle::NoBarrier_Store(&flags_, old_flags | flags); |
78 } | 79 } |
79 | 80 |
80 void HistogramBase::ClearFlags(int32 flags) { | 81 void HistogramBase::ClearFlags(int32_t flags) { |
81 HistogramBase::Count old_flags = subtle::NoBarrier_Load(&flags_); | 82 HistogramBase::Count old_flags = subtle::NoBarrier_Load(&flags_); |
82 subtle::NoBarrier_Store(&flags_, old_flags & ~flags); | 83 subtle::NoBarrier_Store(&flags_, old_flags & ~flags); |
83 } | 84 } |
84 | 85 |
85 void HistogramBase::AddTime(const TimeDelta& time) { | 86 void HistogramBase::AddTime(const TimeDelta& time) { |
86 Add(static_cast<Sample>(time.InMilliseconds())); | 87 Add(static_cast<Sample>(time.InMilliseconds())); |
87 } | 88 } |
88 | 89 |
89 void HistogramBase::AddBoolean(bool value) { | 90 void HistogramBase::AddBoolean(bool value) { |
90 Add(value ? 1 : 0); | 91 Add(value ? 1 : 0); |
91 } | 92 } |
92 | 93 |
93 bool HistogramBase::SerializeInfo(Pickle* pickle) const { | 94 bool HistogramBase::SerializeInfo(Pickle* pickle) const { |
94 if (!pickle->WriteInt(GetHistogramType())) | 95 if (!pickle->WriteInt(GetHistogramType())) |
95 return false; | 96 return false; |
96 return SerializeInfoImpl(pickle); | 97 return SerializeInfoImpl(pickle); |
97 } | 98 } |
98 | 99 |
99 int HistogramBase::FindCorruption(const HistogramSamples& samples) const { | 100 int HistogramBase::FindCorruption(const HistogramSamples& samples) const { |
100 // Not supported by default. | 101 // Not supported by default. |
101 return NO_INCONSISTENCIES; | 102 return NO_INCONSISTENCIES; |
102 } | 103 } |
103 | 104 |
104 void HistogramBase::WriteJSON(std::string* output) const { | 105 void HistogramBase::WriteJSON(std::string* output) const { |
105 Count count; | 106 Count count; |
106 int64 sum; | 107 int64_t sum; |
107 scoped_ptr<ListValue> buckets(new ListValue()); | 108 scoped_ptr<ListValue> buckets(new ListValue()); |
108 GetCountAndBucketData(&count, &sum, buckets.get()); | 109 GetCountAndBucketData(&count, &sum, buckets.get()); |
109 scoped_ptr<DictionaryValue> parameters(new DictionaryValue()); | 110 scoped_ptr<DictionaryValue> parameters(new DictionaryValue()); |
110 GetParameters(parameters.get()); | 111 GetParameters(parameters.get()); |
111 | 112 |
112 JSONStringValueSerializer serializer(output); | 113 JSONStringValueSerializer serializer(output); |
113 DictionaryValue root; | 114 DictionaryValue root; |
114 root.SetString("name", histogram_name()); | 115 root.SetString("name", histogram_name()); |
115 root.SetInteger("count", count); | 116 root.SetInteger("count", count); |
116 root.SetDouble("sum", static_cast<double>(sum)); | 117 root.SetDouble("sum", static_cast<double>(sum)); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 return result; | 157 return result; |
157 } | 158 } |
158 | 159 |
159 void HistogramBase::WriteAsciiBucketValue(Count current, | 160 void HistogramBase::WriteAsciiBucketValue(Count current, |
160 double scaled_sum, | 161 double scaled_sum, |
161 std::string* output) const { | 162 std::string* output) const { |
162 StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum); | 163 StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum); |
163 } | 164 } |
164 | 165 |
165 } // namespace base | 166 } // namespace base |
OLD | NEW |