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 <climits> |
8 | 8 |
9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 : histogram_name_(name), | 65 : histogram_name_(name), |
66 flags_(kNoFlags) {} | 66 flags_(kNoFlags) {} |
67 | 67 |
68 HistogramBase::~HistogramBase() {} | 68 HistogramBase::~HistogramBase() {} |
69 | 69 |
70 void HistogramBase::CheckName(const StringPiece& name) const { | 70 void HistogramBase::CheckName(const StringPiece& name) const { |
71 DCHECK_EQ(histogram_name(), name); | 71 DCHECK_EQ(histogram_name(), name); |
72 } | 72 } |
73 | 73 |
74 void HistogramBase::SetFlags(int32 flags) { | 74 void HistogramBase::SetFlags(int32 flags) { |
75 flags_ |= flags; | 75 HistogramBase::Count old_flags = subtle::NoBarrier_Load(&flags_); |
76 subtle::NoBarrier_Store(&flags_, old_flags | flags); | |
Alexander Potapenko
2015/11/18 11:23:28
The question is whether there is any data that is
Alexei Svitkine (slow)
2015/11/18 16:37:12
I don't think there's a case where there is associ
| |
76 } | 77 } |
77 | 78 |
78 void HistogramBase::ClearFlags(int32 flags) { | 79 void HistogramBase::ClearFlags(int32 flags) { |
79 flags_ &= ~flags; | 80 HistogramBase::Count old_flags = subtle::NoBarrier_Load(&flags_); |
81 subtle::NoBarrier_Store(&flags_, old_flags & ~flags); | |
80 } | 82 } |
81 | 83 |
82 void HistogramBase::AddTime(const TimeDelta& time) { | 84 void HistogramBase::AddTime(const TimeDelta& time) { |
83 Add(static_cast<Sample>(time.InMilliseconds())); | 85 Add(static_cast<Sample>(time.InMilliseconds())); |
84 } | 86 } |
85 | 87 |
86 void HistogramBase::AddBoolean(bool value) { | 88 void HistogramBase::AddBoolean(bool value) { |
87 Add(value ? 1 : 0); | 89 Add(value ? 1 : 0); |
88 } | 90 } |
89 | 91 |
(...skipping 22 matching lines...) Expand all Loading... | |
112 root.SetInteger("count", count); | 114 root.SetInteger("count", count); |
113 root.SetDouble("sum", static_cast<double>(sum)); | 115 root.SetDouble("sum", static_cast<double>(sum)); |
114 root.SetInteger("flags", flags()); | 116 root.SetInteger("flags", flags()); |
115 root.Set("params", parameters.Pass()); | 117 root.Set("params", parameters.Pass()); |
116 root.Set("buckets", buckets.Pass()); | 118 root.Set("buckets", buckets.Pass()); |
117 root.SetInteger("pid", GetCurrentProcId()); | 119 root.SetInteger("pid", GetCurrentProcId()); |
118 serializer.Serialize(root); | 120 serializer.Serialize(root); |
119 } | 121 } |
120 | 122 |
121 void HistogramBase::FindAndRunCallback(HistogramBase::Sample sample) const { | 123 void HistogramBase::FindAndRunCallback(HistogramBase::Sample sample) const { |
122 if ((flags_ & kCallbackExists) == 0) | 124 if ((flags() & kCallbackExists) == 0) |
123 return; | 125 return; |
124 | 126 |
125 StatisticsRecorder::OnSampleCallback cb = | 127 StatisticsRecorder::OnSampleCallback cb = |
126 StatisticsRecorder::FindCallback(histogram_name()); | 128 StatisticsRecorder::FindCallback(histogram_name()); |
127 if (!cb.is_null()) | 129 if (!cb.is_null()) |
128 cb.Run(sample); | 130 cb.Run(sample); |
129 } | 131 } |
130 | 132 |
131 void HistogramBase::WriteAsciiBucketGraph(double current_size, | 133 void HistogramBase::WriteAsciiBucketGraph(double current_size, |
132 double max_size, | 134 double max_size, |
(...skipping 20 matching lines...) Expand all Loading... | |
153 return result; | 155 return result; |
154 } | 156 } |
155 | 157 |
156 void HistogramBase::WriteAsciiBucketValue(Count current, | 158 void HistogramBase::WriteAsciiBucketValue(Count current, |
157 double scaled_sum, | 159 double scaled_sum, |
158 std::string* output) const { | 160 std::string* output) const { |
159 StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum); | 161 StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum); |
160 } | 162 } |
161 | 163 |
162 } // namespace base | 164 } // namespace base |
OLD | NEW |