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

Unified Diff: components/metrics/leak_detector/call_stack_table_unittest.cc

Issue 2403223002: Leak reports collect information about the last uptrend (Closed)
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
Index: components/metrics/leak_detector/call_stack_table_unittest.cc
diff --git a/components/metrics/leak_detector/call_stack_table_unittest.cc b/components/metrics/leak_detector/call_stack_table_unittest.cc
index f56f628499e34915851a5344a11c89fedf269287..3b7918a9725ae1fd91a016db7f273b5af9abffde 100644
--- a/components/metrics/leak_detector/call_stack_table_unittest.cc
+++ b/components/metrics/leak_detector/call_stack_table_unittest.cc
@@ -360,5 +360,95 @@ TEST_F(CallStackTableTest, GetTopCallStacks) {
EXPECT_EQ(stack2_, iter->value.call_stack());
}
+TEST_F(CallStackTableTest, GetLastUptrendInfo) {
+ CallStackTable table(kDefaultLeakThreshold);
+ size_t timestamp_delta;
Simon Que 2016/10/11 01:11:06 Declare these right before they are used.
mwlodar 2016/10/11 07:13:24 Done.
+ uint32_t count_delta;
+
+ // Add some stack0_ and stack1_.
+ for (int i = 0; i < 60; ++i)
+ table.Add(stack0_);
+ for (int i = 0; i < 60; ++i)
+ table.Add(stack1_);
+ table.UpdateLastDropInfo(100);
+
+ table.GetLastUptrendInfo(stack0_, 100, &timestamp_delta, &count_delta);
+ EXPECT_EQ(0U, timestamp_delta);
+ EXPECT_EQ(0U, count_delta);
+
+ // Remove stack0_ and add stack1_.
Simon Que 2016/10/11 01:11:06 Nit: refer to variables as |stack_*|.
mwlodar 2016/10/11 07:13:24 Done.
+ for (int i = 0; i < 30; ++i)
+ table.Remove(stack0_);
Simon Que 2016/10/11 01:11:06 Nit: fix indendation.
mwlodar 2016/10/11 07:13:24 Done.
+ for (int i = 0; i < 30; ++i)
+ table.Add(stack1_);
+ table.UpdateLastDropInfo(200);
+
+ table.GetLastUptrendInfo(stack0_, 200, &timestamp_delta, &count_delta);
+ EXPECT_EQ(0U, timestamp_delta);
+ EXPECT_EQ(0U, count_delta);
+
+ table.GetLastUptrendInfo(stack1_, 200, &timestamp_delta, &count_delta);
+ EXPECT_EQ(100U, timestamp_delta);
+ EXPECT_EQ(30U, count_delta);
+
+ // Check if previous drop of stack0_ was recorded and introduce stack2_.
+ for (int i = 0; i < 30; ++i)
+ table.Add(stack0_);
+ for (int i = 0; i < 60; ++i)
+ table.Add(stack2_);
+ table.UpdateLastDropInfo(300);
+
+ table.GetLastUptrendInfo(stack0_, 300, &timestamp_delta, &count_delta);
+ EXPECT_EQ(100U, timestamp_delta);
+ EXPECT_EQ(30U, count_delta);
+
+ table.GetLastUptrendInfo(stack2_, 300, &timestamp_delta, &count_delta);
+ EXPECT_EQ(0U, timestamp_delta);
+ EXPECT_EQ(0U, count_delta);
+
+ // Introduce more variation between updates. Decrease stack2_ to 0.
+ // All the history for stack2_ should be forgotten.
Simon Que 2016/10/11 01:11:06 Can you test that |stack2_| has been forgotten?
mwlodar 2016/10/11 07:13:24 If it was not forgotten and the rest of the algori
Simon Que 2016/10/11 08:14:03 That's true, but what happens when you call GetLas
mwlodar 2016/10/11 20:24:03 This is an invalid call and just (timestamp, 0) is
+ for (int i = 0; i < 30; ++i)
+ table.Add(stack0_);
+ for (int i = 0; i < 40; ++i)
+ table.Remove(stack0_);
+ for (int i = 0; i < 40; ++i)
+ table.Add(stack1_);
+ for (int i = 0; i < 30; ++i)
+ table.Remove(stack1_);
+ for (int i = 0; i < 30; ++i)
+ table.Remove(stack2_);
+ for (int i = 0; i < 30; ++i)
+ table.Remove(stack2_);
+ table.UpdateLastDropInfo(400);
+
+ table.GetLastUptrendInfo(stack0_, 400, &timestamp_delta, &count_delta);
+ EXPECT_EQ(0U, timestamp_delta);
+ EXPECT_EQ(0U, count_delta);
+
+ table.GetLastUptrendInfo(stack1_, 400, &timestamp_delta, &count_delta);
+ EXPECT_EQ(300U, timestamp_delta);
+ EXPECT_EQ(40U, count_delta);
+
+ // Make a 0-sum sequence for stack0_. Introduce stack2_ again.
+ for (int i = 0; i < 30; ++i)
+ table.Add(stack0_);
+ for (int i = 0; i < 30; ++i)
+ table.Remove(stack0_);
+ for (int i = 0; i < 40; ++i)
+ table.Add(stack2_);
+ for (int i = 0; i < 30; ++i)
+ table.Remove(stack2_);
+ table.UpdateLastDropInfo(500);
+
+ table.GetLastUptrendInfo(stack0_, 500, &timestamp_delta, &count_delta);
+ EXPECT_EQ(100U, timestamp_delta);
+ EXPECT_EQ(0U, count_delta);
+
+ table.GetLastUptrendInfo(stack2_, 500, &timestamp_delta, &count_delta);
+ EXPECT_EQ(0U, timestamp_delta);
+ EXPECT_EQ(0U, count_delta);
+}
+
} // namespace leak_detector
} // namespace metrics

Powered by Google App Engine
This is Rietveld 408576698