| Index: chrome/browser/task_manager/sampling/shared_sampler_unittest_win.cc
|
| diff --git a/chrome/browser/task_manager/sampling/shared_sampler_unittest_win.cc b/chrome/browser/task_manager/sampling/shared_sampler_unittest_win.cc
|
| index 760e9dfd69785bc1875c5e3a2660591a411946b8..ed6af71d79df952fa271fdb7d2aba31d8351354f 100644
|
| --- a/chrome/browser/task_manager/sampling/shared_sampler_unittest_win.cc
|
| +++ b/chrome/browser/task_manager/sampling/shared_sampler_unittest_win.cc
|
| @@ -13,6 +13,7 @@
|
| #include "base/memory/ref_counted.h"
|
| #include "base/run_loop.h"
|
| #include "base/sequenced_task_runner.h"
|
| +#include "base/time/time.h"
|
| #include "chrome/browser/task_manager/task_manager_observer.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/test/test_browser_thread_bundle.h"
|
| @@ -32,6 +33,10 @@ class SharedSamplerTest : public testing::Test {
|
| base::Bind(&SharedSamplerTest::OnIdleWakeupsRefreshDone,
|
| base::Unretained(this)),
|
| base::Bind(&SharedSamplerTest::OnPhysicalMemoryUsageRefreshDone,
|
| + base::Unretained(this)),
|
| + base::Bind(&SharedSamplerTest::OnStartTimeRefreshDone,
|
| + base::Unretained(this)),
|
| + base::Bind(&SharedSamplerTest::OnCpuTimeRefreshDone,
|
| base::Unretained(this)));
|
| }
|
|
|
| @@ -40,6 +45,10 @@ class SharedSamplerTest : public testing::Test {
|
| protected:
|
| int64_t physical_bytes() const { return physical_bytes_; }
|
|
|
| + base::Time start_time() const { return start_time_; }
|
| +
|
| + base::TimeDelta cpu_time() const { return cpu_time_; }
|
| +
|
| int idle_wakeups_per_second() const { return idle_wakeups_per_second_; }
|
|
|
| int64_t finished_refresh_type() const { return finished_refresh_type_; }
|
| @@ -81,12 +90,24 @@ class SharedSamplerTest : public testing::Test {
|
| OnRefreshTypeFinished(REFRESH_TYPE_IDLE_WAKEUPS);
|
| }
|
|
|
| + void OnStartTimeRefreshDone(base::Time start_time) {
|
| + start_time_ = start_time;
|
| + OnRefreshTypeFinished(REFRESH_TYPE_START_TIME);
|
| + }
|
| +
|
| + void OnCpuTimeRefreshDone(base::TimeDelta cpu_time) {
|
| + cpu_time_ = cpu_time;
|
| + OnRefreshTypeFinished(REFRESH_TYPE_CPU_TIME);
|
| + }
|
| +
|
| int64_t expected_refresh_type_ = 0;
|
| int64_t finished_refresh_type_ = 0;
|
| base::Closure quit_closure_;
|
|
|
| int64_t physical_bytes_ = 0;
|
| int idle_wakeups_per_second_ = -1;
|
| + base::Time start_time_;
|
| + base::TimeDelta cpu_time_;
|
|
|
| content::TestBrowserThreadBundle thread_bundle_;
|
| scoped_refptr<base::SequencedTaskRunner> blocking_pool_runner_;
|
| @@ -136,11 +157,47 @@ TEST_F(SharedSamplerTest, PhysicalMemory) {
|
| EXPECT_GE(physical_bytes(), initial_value + allocated_size);
|
| }
|
|
|
| +// Tests that process start time can be obtained from SharedSampler.
|
| +TEST_F(SharedSamplerTest, StartTime) {
|
| + StartRefresh(REFRESH_TYPE_START_TIME);
|
| + WaitUntilRefreshDone();
|
| + EXPECT_EQ(REFRESH_TYPE_START_TIME, finished_refresh_type());
|
| +
|
| + // Should get a greater than zero now.
|
| + base::Time start_time_prev = start_time();
|
| + EXPECT_GT(start_time_prev, base::Time());
|
| +
|
| + // Do a refresh.
|
| + StartRefresh(REFRESH_TYPE_START_TIME);
|
| + WaitUntilRefreshDone();
|
| +
|
| + // Start time should not change.
|
| + EXPECT_EQ(start_time(), start_time_prev);
|
| +}
|
| +
|
| +// Tests that CPU time can be obtained from SharedSampler.
|
| +TEST_F(SharedSamplerTest, CpuTime) {
|
| + StartRefresh(REFRESH_TYPE_CPU_TIME);
|
| + WaitUntilRefreshDone();
|
| + EXPECT_EQ(REFRESH_TYPE_CPU_TIME, finished_refresh_type());
|
| +
|
| + base::TimeDelta cpu_time_prev = cpu_time();
|
| +
|
| + // Do a refresh.
|
| + StartRefresh(REFRESH_TYPE_CPU_TIME);
|
| + WaitUntilRefreshDone();
|
| +
|
| + // CPU time should not decrease.
|
| + EXPECT_GE(cpu_time(), cpu_time_prev);
|
| +}
|
| +
|
| // Verifies that multiple refresh types can be refreshed at the same time.
|
| TEST_F(SharedSamplerTest, MultipleRefreshTypes) {
|
| - StartRefresh(REFRESH_TYPE_IDLE_WAKEUPS | REFRESH_TYPE_PHYSICAL_MEMORY);
|
| + StartRefresh(REFRESH_TYPE_IDLE_WAKEUPS | REFRESH_TYPE_PHYSICAL_MEMORY |
|
| + REFRESH_TYPE_START_TIME | REFRESH_TYPE_CPU_TIME);
|
| WaitUntilRefreshDone();
|
| - EXPECT_EQ(REFRESH_TYPE_IDLE_WAKEUPS | REFRESH_TYPE_PHYSICAL_MEMORY,
|
| + EXPECT_EQ(REFRESH_TYPE_IDLE_WAKEUPS | REFRESH_TYPE_PHYSICAL_MEMORY |
|
| + REFRESH_TYPE_START_TIME | REFRESH_TYPE_CPU_TIME,
|
| finished_refresh_type());
|
| }
|
|
|
|
|