Chromium Code Reviews| 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 | |
| 19 HistogramDeltasSerializer serializer("HistogramDeltasSerializerTest"); | |
| 20 // Store current state for future deltas calculation. | |
| 21 serializer.GetNewDeltas(); | |
|
Ilya Sherman
2013/10/17 04:37:42
I don't follow what the purpose of this line is...
Vitaly Buka (NO REVIEWS)
2013/10/17 10:15:47
Done. It's unnecessary.
| |
| 22 | |
| 23 // Nothing was changed yet. | |
| 24 EXPECT_TRUE(serializer.GetNewDeltas().empty()); | |
| 25 | |
| 26 HistogramBase* histogram = Histogram::FactoryGet( | |
| 27 "TestHistogram", 1, 1000, 10, HistogramBase::kIPCSerializationSourceFlag); | |
| 28 histogram->Add(1); | |
| 29 histogram->Add(10); | |
| 30 histogram->Add(100); | |
| 31 histogram->Add(1000); | |
| 32 | |
| 33 std::vector<std::string> deltas(serializer.GetNewDeltas()); | |
| 34 EXPECT_FALSE(deltas.empty()); | |
| 35 | |
| 36 // The histogram has kIPCSerializationSourceFlag. So samples will be ignored. | |
|
Ilya Sherman
2013/10/17 04:37:42
Did you mean to deserialize the histograms at some
Vitaly Buka (NO REVIEWS)
2013/10/17 10:15:47
No. I just ported this test from prev implementati
Vitaly Buka (NO REVIEWS)
2013/10/17 10:22:33
Let me fix my comment.
I guess author just checks
Ilya Sherman
2013/10/17 22:41:46
I think you're overlooking line 77 of the original
Vitaly Buka (NO REVIEWS)
2013/10/18 05:33:34
Thanks. My understanding of test was incorrect.
| |
| 37 scoped_ptr<HistogramSamples> snapshot(histogram->SnapshotSamples()); | |
| 38 EXPECT_EQ(1, snapshot->GetCount(1)); | |
| 39 EXPECT_EQ(1, snapshot->GetCount(10)); | |
| 40 EXPECT_EQ(1, snapshot->GetCount(100)); | |
| 41 EXPECT_EQ(1, snapshot->GetCount(1000)); | |
| 42 | |
| 43 // Clear kIPCSerializationSourceFlag to emulate multi-process usage. | |
| 44 histogram->ClearFlags(HistogramBase::kIPCSerializationSourceFlag); | |
| 45 HistogramDeltasSerializer::DeserializeAndAddSamples(deltas); | |
| 46 | |
| 47 scoped_ptr<HistogramSamples> snapshot2(histogram->SnapshotSamples()); | |
| 48 EXPECT_EQ(2, snapshot2->GetCount(1)); | |
| 49 EXPECT_EQ(2, snapshot2->GetCount(10)); | |
| 50 EXPECT_EQ(2, snapshot2->GetCount(100)); | |
| 51 EXPECT_EQ(2, snapshot2->GetCount(1000)); | |
| 52 } | |
| 53 | |
| 54 } // namespace base | |
| OLD | NEW |