OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/metrics/histogram_delta_serializer.h" |
| 6 |
| 7 #include <vector> |
| 8 |
| 9 #include "base/metrics/histogram.h" |
| 10 #include "base/metrics/histogram_base.h" |
| 11 #include "base/metrics/statistics_recorder.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace base { |
| 15 |
| 16 TEST(HistogramDeltasSerializerTest, DeserializeHistogramAndAddSamples) { |
| 17 StatisticsRecorder statistic_recorder; |
| 18 HistogramDeltasSerializer serializer("HistogramDeltasSerializerTest"); |
| 19 // Nothing was changed yet. |
| 20 EXPECT_TRUE(serializer.GetNewDeltas().empty()); |
| 21 |
| 22 HistogramBase* histogram = Histogram::FactoryGet( |
| 23 "TestHistogram", 1, 1000, 10, HistogramBase::kIPCSerializationSourceFlag); |
| 24 histogram->Add(1); |
| 25 histogram->Add(10); |
| 26 histogram->Add(100); |
| 27 histogram->Add(1000); |
| 28 |
| 29 std::vector<std::string> deltas(serializer.GetNewDeltas()); |
| 30 EXPECT_FALSE(deltas.empty()); |
| 31 |
| 32 // The histogram has kIPCSerializationSourceFlag. So samples will be ignored. |
| 33 scoped_ptr<HistogramSamples> snapshot(histogram->SnapshotSamples()); |
| 34 EXPECT_EQ(1, snapshot->GetCount(1)); |
| 35 EXPECT_EQ(1, snapshot->GetCount(10)); |
| 36 EXPECT_EQ(1, snapshot->GetCount(100)); |
| 37 EXPECT_EQ(1, snapshot->GetCount(1000)); |
| 38 |
| 39 // Clear kIPCSerializationSourceFlag to emulate multi-process usage. |
| 40 histogram->ClearFlags(HistogramBase::kIPCSerializationSourceFlag); |
| 41 HistogramDeltasSerializer::DeserializeAndAddSamples(deltas); |
| 42 |
| 43 scoped_ptr<HistogramSamples> snapshot2(histogram->SnapshotSamples()); |
| 44 EXPECT_EQ(2, snapshot2->GetCount(1)); |
| 45 EXPECT_EQ(2, snapshot2->GetCount(10)); |
| 46 EXPECT_EQ(2, snapshot2->GetCount(100)); |
| 47 EXPECT_EQ(2, snapshot2->GetCount(1000)); |
| 48 } |
| 49 |
| 50 } // namespace base |
OLD | NEW |