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

Unified Diff: test/unittests/counters-unittest.cc

Issue 1125683004: Add aggregated memory histograms. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add comments Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: test/unittests/counters-unittest.cc
diff --git a/test/unittests/counters-unittest.cc b/test/unittests/counters-unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dd60a0d9c1a7a87a9a9b3ee50e88300915969a4e
--- /dev/null
+++ b/test/unittests/counters-unittest.cc
@@ -0,0 +1,200 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <vector>
+
+#include "src/counters.h"
+#include "src/handles-inl.h"
+#include "src/objects-inl.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace v8 {
+namespace internal {
+
+namespace {
+
+class MockHistogram : public Histogram {
+ public:
+ void AddSample(int value) { samples_.push_back(value); }
+ std::vector<int>* samples() { return &samples_; }
+
+ private:
+ std::vector<int> samples_;
+};
+
+
+class AggregatedMemoryHistogramTest : public ::testing::Test {
+ public:
+ AggregatedMemoryHistogramTest() {
+ aggregated_ = AggregatedMemoryHistogram<MockHistogram>(&mock_);
+ }
+ virtual ~AggregatedMemoryHistogramTest() {}
+
+ void AddSample(double current_ms, double current_value) {
+ aggregated_.AddSample(current_ms, current_value);
+ }
+
+ std::vector<int>* samples() { return mock_.samples(); }
+
+ private:
+ AggregatedMemoryHistogram<MockHistogram> aggregated_;
+ MockHistogram mock_;
+};
+
+} // namespace
+
+
+TEST_F(AggregatedMemoryHistogramTest, OneSample1) {
+ FLAG_histogram_interval = 10;
+ AddSample(10, 1000);
+ AddSample(20, 1000);
+ EXPECT_EQ(1, samples()->size());
+ EXPECT_EQ(1000, (*samples())[0]);
+}
+
+
+TEST_F(AggregatedMemoryHistogramTest, OneSample2) {
+ FLAG_histogram_interval = 10;
+ AddSample(10, 500);
+ AddSample(20, 1000);
+ EXPECT_EQ(1, samples()->size());
+ EXPECT_EQ(750, (*samples())[0]);
+}
+
+
+TEST_F(AggregatedMemoryHistogramTest, OneSample3) {
+ FLAG_histogram_interval = 10;
+ AddSample(10, 500);
+ AddSample(15, 500);
+ AddSample(15, 1000);
+ AddSample(20, 1000);
+ EXPECT_EQ(1, samples()->size());
+ EXPECT_EQ(750, (*samples())[0]);
+}
+
+
+TEST_F(AggregatedMemoryHistogramTest, OneSample4) {
+ FLAG_histogram_interval = 10;
+ AddSample(10, 500);
+ AddSample(15, 750);
+ AddSample(20, 1000);
+ EXPECT_EQ(1, samples()->size());
+ EXPECT_EQ(750, (*samples())[0]);
+}
+
+
+TEST_F(AggregatedMemoryHistogramTest, TwoSamples1) {
+ FLAG_histogram_interval = 10;
+ AddSample(10, 1000);
+ AddSample(30, 1000);
+ EXPECT_EQ(2, samples()->size());
+ EXPECT_EQ(1000, (*samples())[0]);
+ EXPECT_EQ(1000, (*samples())[1]);
+}
+
+
+TEST_F(AggregatedMemoryHistogramTest, TwoSamples2) {
+ FLAG_histogram_interval = 10;
+ AddSample(10, 1000);
+ AddSample(20, 1000);
+ AddSample(30, 1000);
+ EXPECT_EQ(2, samples()->size());
+ EXPECT_EQ(1000, (*samples())[0]);
+ EXPECT_EQ(1000, (*samples())[1]);
+}
+
+
+TEST_F(AggregatedMemoryHistogramTest, TwoSamples3) {
+ FLAG_histogram_interval = 10;
+ AddSample(10, 1000);
+ AddSample(20, 1000);
+ AddSample(20, 500);
+ AddSample(30, 500);
+ EXPECT_EQ(2, samples()->size());
+ EXPECT_EQ(1000, (*samples())[0]);
+ EXPECT_EQ(500, (*samples())[1]);
+}
+
+
+TEST_F(AggregatedMemoryHistogramTest, TwoSamples4) {
+ FLAG_histogram_interval = 10;
+ AddSample(10, 1000);
+ AddSample(30, 0);
+ EXPECT_EQ(2, samples()->size());
+ EXPECT_EQ(750, (*samples())[0]);
+ EXPECT_EQ(250, (*samples())[1]);
+}
+
+
+TEST_F(AggregatedMemoryHistogramTest, TwoSamples5) {
+ FLAG_histogram_interval = 10;
+ AddSample(10, 0);
+ AddSample(30, 1000);
+ EXPECT_EQ(2, samples()->size());
+ EXPECT_EQ(250, (*samples())[0]);
+ EXPECT_EQ(750, (*samples())[1]);
+}
+
+
+TEST_F(AggregatedMemoryHistogramTest, TwoSamples6) {
+ FLAG_histogram_interval = 10;
+ AddSample(10, 0);
+ AddSample(15, 1000);
+ AddSample(30, 1000);
+ EXPECT_EQ(2, samples()->size());
+ EXPECT_EQ((500 + 1000) / 2, (*samples())[0]);
+ EXPECT_EQ(1000, (*samples())[1]);
+}
+
+
+TEST_F(AggregatedMemoryHistogramTest, TwoSamples7) {
+ FLAG_histogram_interval = 10;
+ AddSample(10, 0);
+ AddSample(15, 1000);
+ AddSample(25, 0);
+ AddSample(30, 1000);
+ EXPECT_EQ(2, samples()->size());
+ EXPECT_EQ((500 + 750) / 2, (*samples())[0]);
+ EXPECT_EQ((250 + 500) / 2, (*samples())[1]);
+}
+
+
+TEST_F(AggregatedMemoryHistogramTest, TwoSamples8) {
+ FLAG_histogram_interval = 10;
+ AddSample(10, 1000);
+ AddSample(15, 0);
+ AddSample(25, 1000);
+ AddSample(30, 0);
+ EXPECT_EQ(2, samples()->size());
+ EXPECT_EQ((500 + 250) / 2, (*samples())[0]);
+ EXPECT_EQ((750 + 500) / 2, (*samples())[1]);
+}
+
+
+TEST_F(AggregatedMemoryHistogramTest, ManySamples1) {
+ FLAG_histogram_interval = 10;
+ const int kMaxSamples = 1000;
+ AddSample(0, 0);
+ AddSample(10 * kMaxSamples, 10 * kMaxSamples);
+ EXPECT_EQ(kMaxSamples, samples()->size());
+ for (int i = 0; i < kMaxSamples; i++) {
+ EXPECT_EQ(i * 10 + 5, (*samples())[i]);
+ }
+}
+
+
+TEST_F(AggregatedMemoryHistogramTest, ManySamples2) {
+ FLAG_histogram_interval = 10;
+ const int kMaxSamples = 1000;
+ AddSample(0, 0);
+ AddSample(10 * (2 * kMaxSamples), 10 * (2 * kMaxSamples));
+ EXPECT_EQ(kMaxSamples, samples()->size());
+ for (int i = 0; i < kMaxSamples; i++) {
+ EXPECT_EQ(i * 10 + 5, (*samples())[i]);
+ }
+}
+
+
+} // namespace internal
+} // namespace v8
« src/counters.h ('K') | « src/heap/heap.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698