Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/metrics/leak_detector/call_stack_table.h" | 5 #include "components/metrics/leak_detector/call_stack_table.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 table.GetTopCallStacks(&top_two); | 353 table.GetTopCallStacks(&top_two); |
| 354 ASSERT_EQ(2U, top_two.size()); | 354 ASSERT_EQ(2U, top_two.size()); |
| 355 iter = top_two.begin(); | 355 iter = top_two.begin(); |
| 356 EXPECT_EQ(72, iter->count); | 356 EXPECT_EQ(72, iter->count); |
| 357 EXPECT_EQ(stack3_, iter->value.call_stack()); | 357 EXPECT_EQ(stack3_, iter->value.call_stack()); |
| 358 ++iter; | 358 ++iter; |
| 359 EXPECT_EQ(64, iter->count); | 359 EXPECT_EQ(64, iter->count); |
| 360 EXPECT_EQ(stack2_, iter->value.call_stack()); | 360 EXPECT_EQ(stack2_, iter->value.call_stack()); |
| 361 } | 361 } |
| 362 | 362 |
| 363 TEST_F(CallStackTableTest, GetLastUptrendInfo) { | |
| 364 CallStackTable table(kDefaultLeakThreshold); | |
| 365 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.
| |
| 366 uint32_t count_delta; | |
| 367 | |
| 368 // Add some stack0_ and stack1_. | |
| 369 for (int i = 0; i < 60; ++i) | |
| 370 table.Add(stack0_); | |
| 371 for (int i = 0; i < 60; ++i) | |
| 372 table.Add(stack1_); | |
| 373 table.UpdateLastDropInfo(100); | |
| 374 | |
| 375 table.GetLastUptrendInfo(stack0_, 100, ×tamp_delta, &count_delta); | |
| 376 EXPECT_EQ(0U, timestamp_delta); | |
| 377 EXPECT_EQ(0U, count_delta); | |
| 378 | |
| 379 // 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.
| |
| 380 for (int i = 0; i < 30; ++i) | |
| 381 table.Remove(stack0_); | |
|
Simon Que
2016/10/11 01:11:06
Nit: fix indendation.
mwlodar
2016/10/11 07:13:24
Done.
| |
| 382 for (int i = 0; i < 30; ++i) | |
| 383 table.Add(stack1_); | |
| 384 table.UpdateLastDropInfo(200); | |
| 385 | |
| 386 table.GetLastUptrendInfo(stack0_, 200, ×tamp_delta, &count_delta); | |
| 387 EXPECT_EQ(0U, timestamp_delta); | |
| 388 EXPECT_EQ(0U, count_delta); | |
| 389 | |
| 390 table.GetLastUptrendInfo(stack1_, 200, ×tamp_delta, &count_delta); | |
| 391 EXPECT_EQ(100U, timestamp_delta); | |
| 392 EXPECT_EQ(30U, count_delta); | |
| 393 | |
| 394 // Check if previous drop of stack0_ was recorded and introduce stack2_. | |
| 395 for (int i = 0; i < 30; ++i) | |
| 396 table.Add(stack0_); | |
| 397 for (int i = 0; i < 60; ++i) | |
| 398 table.Add(stack2_); | |
| 399 table.UpdateLastDropInfo(300); | |
| 400 | |
| 401 table.GetLastUptrendInfo(stack0_, 300, ×tamp_delta, &count_delta); | |
| 402 EXPECT_EQ(100U, timestamp_delta); | |
| 403 EXPECT_EQ(30U, count_delta); | |
| 404 | |
| 405 table.GetLastUptrendInfo(stack2_, 300, ×tamp_delta, &count_delta); | |
| 406 EXPECT_EQ(0U, timestamp_delta); | |
| 407 EXPECT_EQ(0U, count_delta); | |
| 408 | |
| 409 // Introduce more variation between updates. Decrease stack2_ to 0. | |
| 410 // 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
| |
| 411 for (int i = 0; i < 30; ++i) | |
| 412 table.Add(stack0_); | |
| 413 for (int i = 0; i < 40; ++i) | |
| 414 table.Remove(stack0_); | |
| 415 for (int i = 0; i < 40; ++i) | |
| 416 table.Add(stack1_); | |
| 417 for (int i = 0; i < 30; ++i) | |
| 418 table.Remove(stack1_); | |
| 419 for (int i = 0; i < 30; ++i) | |
| 420 table.Remove(stack2_); | |
| 421 for (int i = 0; i < 30; ++i) | |
| 422 table.Remove(stack2_); | |
| 423 table.UpdateLastDropInfo(400); | |
| 424 | |
| 425 table.GetLastUptrendInfo(stack0_, 400, ×tamp_delta, &count_delta); | |
| 426 EXPECT_EQ(0U, timestamp_delta); | |
| 427 EXPECT_EQ(0U, count_delta); | |
| 428 | |
| 429 table.GetLastUptrendInfo(stack1_, 400, ×tamp_delta, &count_delta); | |
| 430 EXPECT_EQ(300U, timestamp_delta); | |
| 431 EXPECT_EQ(40U, count_delta); | |
| 432 | |
| 433 // Make a 0-sum sequence for stack0_. Introduce stack2_ again. | |
| 434 for (int i = 0; i < 30; ++i) | |
| 435 table.Add(stack0_); | |
| 436 for (int i = 0; i < 30; ++i) | |
| 437 table.Remove(stack0_); | |
| 438 for (int i = 0; i < 40; ++i) | |
| 439 table.Add(stack2_); | |
| 440 for (int i = 0; i < 30; ++i) | |
| 441 table.Remove(stack2_); | |
| 442 table.UpdateLastDropInfo(500); | |
| 443 | |
| 444 table.GetLastUptrendInfo(stack0_, 500, ×tamp_delta, &count_delta); | |
| 445 EXPECT_EQ(100U, timestamp_delta); | |
| 446 EXPECT_EQ(0U, count_delta); | |
| 447 | |
| 448 table.GetLastUptrendInfo(stack2_, 500, ×tamp_delta, &count_delta); | |
| 449 EXPECT_EQ(0U, timestamp_delta); | |
| 450 EXPECT_EQ(0U, count_delta); | |
| 451 } | |
| 452 | |
| 363 } // namespace leak_detector | 453 } // namespace leak_detector |
| 364 } // namespace metrics | 454 } // namespace metrics |
| OLD | NEW |