Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(566)

Side by Side Diff: base/metrics/histogram_base_unittest.cc

Issue 27460003: Consolidate serialization code in base::HistogramDeltasSerializer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/metrics/histogram_base.cc ('k') | base/metrics/histogram_delta_serialization.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <vector> 5 #include <vector>
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/metrics/histogram_base.h" 8 #include "base/metrics/histogram_base.h"
9 #include "base/metrics/sparse_histogram.h" 9 #include "base/metrics/sparse_histogram.h"
10 #include "base/metrics/statistics_recorder.h" 10 #include "base/metrics/statistics_recorder.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 deserialized = DeserializeHistogramInfo(&iter2); 54 deserialized = DeserializeHistogramInfo(&iter2);
55 EXPECT_TRUE(deserialized); 55 EXPECT_TRUE(deserialized);
56 EXPECT_NE(histogram, deserialized); 56 EXPECT_NE(histogram, deserialized);
57 EXPECT_EQ("TestHistogram", deserialized->histogram_name()); 57 EXPECT_EQ("TestHistogram", deserialized->histogram_name());
58 EXPECT_TRUE(deserialized->HasConstructionArguments(1, 1000, 10)); 58 EXPECT_TRUE(deserialized->HasConstructionArguments(1, 1000, 10));
59 59
60 // kIPCSerializationSourceFlag will be cleared. 60 // kIPCSerializationSourceFlag will be cleared.
61 EXPECT_EQ(HistogramBase::kUmaTargetedHistogramFlag, deserialized->flags()); 61 EXPECT_EQ(HistogramBase::kUmaTargetedHistogramFlag, deserialized->flags());
62 } 62 }
63 63
64 TEST_F(HistogramBaseTest, DeserializeHistogramAndAddSamples) {
65 HistogramBase* histogram = Histogram::FactoryGet(
66 "TestHistogram", 1, 1000, 10, HistogramBase::kIPCSerializationSourceFlag);
67 histogram->Add(1);
68 histogram->Add(10);
69 histogram->Add(100);
70 histogram->Add(1000);
71
72 Pickle pickle;
73 ASSERT_TRUE(histogram->SerializeInfo(&pickle));
74 histogram->SnapshotSamples()->Serialize(&pickle);
75
76 PickleIterator iter(pickle);
77 DeserializeHistogramAndAddSamples(&iter);
78
79 // The histogram has kIPCSerializationSourceFlag. So samples will be ignored.
80 scoped_ptr<HistogramSamples> snapshot(histogram->SnapshotSamples());
81 EXPECT_EQ(1, snapshot->GetCount(1));
82 EXPECT_EQ(1, snapshot->GetCount(10));
83 EXPECT_EQ(1, snapshot->GetCount(100));
84 EXPECT_EQ(1, snapshot->GetCount(1000));
85
86 // Clear kIPCSerializationSourceFlag to emulate multi-process usage.
87 histogram->ClearFlags(HistogramBase::kIPCSerializationSourceFlag);
88 PickleIterator iter2(pickle);
89 DeserializeHistogramAndAddSamples(&iter2);
90
91 scoped_ptr<HistogramSamples> snapshot2(histogram->SnapshotSamples());
92 EXPECT_EQ(2, snapshot2->GetCount(1));
93 EXPECT_EQ(2, snapshot2->GetCount(10));
94 EXPECT_EQ(2, snapshot2->GetCount(100));
95 EXPECT_EQ(2, snapshot2->GetCount(1000));
96 }
97
98 TEST_F(HistogramBaseTest, DeserializeLinearHistogram) { 64 TEST_F(HistogramBaseTest, DeserializeLinearHistogram) {
99 HistogramBase* histogram = LinearHistogram::FactoryGet( 65 HistogramBase* histogram = LinearHistogram::FactoryGet(
100 "TestHistogram", 1, 1000, 10, 66 "TestHistogram", 1, 1000, 10,
101 HistogramBase::kIPCSerializationSourceFlag); 67 HistogramBase::kIPCSerializationSourceFlag);
102 68
103 Pickle pickle; 69 Pickle pickle;
104 ASSERT_TRUE(histogram->SerializeInfo(&pickle)); 70 ASSERT_TRUE(histogram->SerializeInfo(&pickle));
105 71
106 PickleIterator iter(pickle); 72 PickleIterator iter(pickle);
107 HistogramBase* deserialized = DeserializeHistogramInfo(&iter); 73 HistogramBase* deserialized = DeserializeHistogramInfo(&iter);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 148
183 PickleIterator iter2(pickle); 149 PickleIterator iter2(pickle);
184 deserialized = DeserializeHistogramInfo(&iter2); 150 deserialized = DeserializeHistogramInfo(&iter2);
185 EXPECT_TRUE(deserialized); 151 EXPECT_TRUE(deserialized);
186 EXPECT_NE(histogram, deserialized); 152 EXPECT_NE(histogram, deserialized);
187 EXPECT_EQ("TestHistogram", deserialized->histogram_name()); 153 EXPECT_EQ("TestHistogram", deserialized->histogram_name());
188 EXPECT_EQ(0, deserialized->flags()); 154 EXPECT_EQ(0, deserialized->flags());
189 } 155 }
190 156
191 } // namespace base 157 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram_base.cc ('k') | base/metrics/histogram_delta_serialization.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698