| 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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/metrics/histogram_samples.h" | 13 #include "base/metrics/histogram_samples.h" |
| 14 #include "base/metrics/sparse_histogram.h" | 14 #include "base/metrics/sparse_histogram.h" |
| 15 #include "base/metrics/statistics_recorder.h" |
| 15 #include "base/pickle.h" | 16 #include "base/pickle.h" |
| 16 #include "base/process/process_handle.h" | 17 #include "base/process/process_handle.h" |
| 17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 18 #include "base/values.h" | 19 #include "base/values.h" |
| 19 | 20 |
| 20 namespace base { | 21 namespace base { |
| 21 | 22 |
| 22 std::string HistogramTypeToString(HistogramType type) { | 23 std::string HistogramTypeToString(HistogramType type) { |
| 23 switch (type) { | 24 switch (type) { |
| 24 case HISTOGRAM: | 25 case HISTOGRAM: |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 root.SetString("name", histogram_name()); | 111 root.SetString("name", histogram_name()); |
| 111 root.SetInteger("count", count); | 112 root.SetInteger("count", count); |
| 112 root.SetDouble("sum", static_cast<double>(sum)); | 113 root.SetDouble("sum", static_cast<double>(sum)); |
| 113 root.SetInteger("flags", flags()); | 114 root.SetInteger("flags", flags()); |
| 114 root.Set("params", parameters.Pass()); | 115 root.Set("params", parameters.Pass()); |
| 115 root.Set("buckets", buckets.Pass()); | 116 root.Set("buckets", buckets.Pass()); |
| 116 root.SetInteger("pid", GetCurrentProcId()); | 117 root.SetInteger("pid", GetCurrentProcId()); |
| 117 serializer.Serialize(root); | 118 serializer.Serialize(root); |
| 118 } | 119 } |
| 119 | 120 |
| 121 void HistogramBase::FindAndRunCallback(HistogramBase::Sample sample) const { |
| 122 if ((flags_ & kCallbackExists) == 0) |
| 123 return; |
| 124 |
| 125 StatisticsRecorder::OnSampleCallback cb = |
| 126 StatisticsRecorder::FindCallback(histogram_name()); |
| 127 if (!cb.is_null()) |
| 128 cb.Run(sample); |
| 129 } |
| 130 |
| 120 void HistogramBase::WriteAsciiBucketGraph(double current_size, | 131 void HistogramBase::WriteAsciiBucketGraph(double current_size, |
| 121 double max_size, | 132 double max_size, |
| 122 std::string* output) const { | 133 std::string* output) const { |
| 123 const int k_line_length = 72; // Maximal horizontal width of graph. | 134 const int k_line_length = 72; // Maximal horizontal width of graph. |
| 124 int x_count = static_cast<int>(k_line_length * (current_size / max_size) | 135 int x_count = static_cast<int>(k_line_length * (current_size / max_size) |
| 125 + 0.5); | 136 + 0.5); |
| 126 int x_remainder = k_line_length - x_count; | 137 int x_remainder = k_line_length - x_count; |
| 127 | 138 |
| 128 while (0 < x_count--) | 139 while (0 < x_count--) |
| 129 output->append("-"); | 140 output->append("-"); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 142 return result; | 153 return result; |
| 143 } | 154 } |
| 144 | 155 |
| 145 void HistogramBase::WriteAsciiBucketValue(Count current, | 156 void HistogramBase::WriteAsciiBucketValue(Count current, |
| 146 double scaled_sum, | 157 double scaled_sum, |
| 147 std::string* output) const { | 158 std::string* output) const { |
| 148 StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum); | 159 StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum); |
| 149 } | 160 } |
| 150 | 161 |
| 151 } // namespace base | 162 } // namespace base |
| OLD | NEW |