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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/metrics/histogram.h" |
| 13 #include "base/metrics/histogram_samples.h" |
| 14 #include "base/metrics/sparse_histogram.h" |
| 15 #include "base/pickle.h" |
12 #include "base/values.h" | 16 #include "base/values.h" |
13 | 17 |
14 namespace base { | 18 namespace base { |
15 | 19 |
16 std::string HistogramTypeToString(HistogramType type) { | 20 std::string HistogramTypeToString(HistogramType type) { |
17 switch(type) { | 21 switch(type) { |
18 case HISTOGRAM: | 22 case HISTOGRAM: |
19 return "HISTOGRAM"; | 23 return "HISTOGRAM"; |
20 case LINEAR_HISTOGRAM: | 24 case LINEAR_HISTOGRAM: |
21 return "LINEAR_HISTOGRAM"; | 25 return "LINEAR_HISTOGRAM"; |
(...skipping 10 matching lines...) Expand all Loading... |
32 } | 36 } |
33 | 37 |
34 const HistogramBase::Sample HistogramBase::kSampleType_MAX = INT_MAX; | 38 const HistogramBase::Sample HistogramBase::kSampleType_MAX = INT_MAX; |
35 | 39 |
36 HistogramBase::HistogramBase(const std::string& name) | 40 HistogramBase::HistogramBase(const std::string& name) |
37 : histogram_name_(name), | 41 : histogram_name_(name), |
38 flags_(kNoFlags) {} | 42 flags_(kNoFlags) {} |
39 | 43 |
40 HistogramBase::~HistogramBase() {} | 44 HistogramBase::~HistogramBase() {} |
41 | 45 |
| 46 // static |
| 47 HistogramBase* HistogramBase::DeserializeHistogramInfo(PickleIterator* iter) { |
| 48 int type; |
| 49 if (!iter->ReadInt(&type)) |
| 50 return NULL; |
| 51 |
| 52 switch (type) { |
| 53 case HISTOGRAM: |
| 54 return Histogram::DeserializeHistogramInfo(iter); |
| 55 case LINEAR_HISTOGRAM: |
| 56 return LinearHistogram::DeserializeHistogramInfo(iter); |
| 57 case BOOLEAN_HISTOGRAM: |
| 58 return BooleanHistogram::DeserializeHistogramInfo(iter); |
| 59 case CUSTOM_HISTOGRAM: |
| 60 return CustomHistogram::DeserializeHistogramInfo(iter); |
| 61 case SPARSE_HISTOGRAM: |
| 62 return SparseHistogram::DeserializeHistogramInfo(iter); |
| 63 default: |
| 64 return NULL; |
| 65 } |
| 66 } |
| 67 |
42 void HistogramBase::SetFlags(int32 flags) { | 68 void HistogramBase::SetFlags(int32 flags) { |
43 flags_ |= flags; | 69 flags_ |= flags; |
44 } | 70 } |
45 | 71 |
46 void HistogramBase::ClearFlags(int32 flags) { | 72 void HistogramBase::ClearFlags(int32 flags) { |
47 flags_ &= ~flags; | 73 flags_ &= ~flags; |
48 } | 74 } |
49 | 75 |
| 76 bool HistogramBase::SerializeInfo(Pickle* pickle) const { |
| 77 if (!pickle->WriteInt(GetHistogramType())) |
| 78 return false; |
| 79 return SerializeInfoImpl(pickle); |
| 80 } |
| 81 |
50 void HistogramBase::WriteJSON(std::string* output) const { | 82 void HistogramBase::WriteJSON(std::string* output) const { |
51 Count count; | 83 Count count; |
52 scoped_ptr<ListValue> buckets(new ListValue()); | 84 scoped_ptr<ListValue> buckets(new ListValue()); |
53 GetCountAndBucketData(&count, buckets.get()); | 85 GetCountAndBucketData(&count, buckets.get()); |
54 scoped_ptr<DictionaryValue> parameters(new DictionaryValue()); | 86 scoped_ptr<DictionaryValue> parameters(new DictionaryValue()); |
55 GetParameters(parameters.get()); | 87 GetParameters(parameters.get()); |
56 | 88 |
57 JSONStringValueSerializer serializer(output); | 89 JSONStringValueSerializer serializer(output); |
58 DictionaryValue root; | 90 DictionaryValue root; |
59 root.SetString("name", histogram_name()); | 91 root.SetString("name", histogram_name()); |
60 root.SetInteger("count", count); | 92 root.SetInteger("count", count); |
61 root.SetInteger("flags", flags()); | 93 root.SetInteger("flags", flags()); |
62 root.Set("params", parameters.release()); | 94 root.Set("params", parameters.release()); |
63 root.Set("buckets", buckets.release()); | 95 root.Set("buckets", buckets.release()); |
64 serializer.Serialize(root); | 96 serializer.Serialize(root); |
65 } | 97 } |
66 | 98 |
67 } // namespace base | 99 } // namespace base |
OLD | NEW |