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

Side by Side Diff: chrome/browser/task_manager/sampling/shared_sampler_unittest_win.cc

Issue 2573183002: Add process start time and CPU time columns to task manager (Closed)
Patch Set: Fix nits Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/task_manager/sampling/shared_sampler.h" 5 #include "chrome/browser/task_manager/sampling/shared_sampler.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 14 matching lines...) Expand all
25 class SharedSamplerTest : public testing::Test { 25 class SharedSamplerTest : public testing::Test {
26 public: 26 public:
27 SharedSamplerTest() 27 SharedSamplerTest()
28 : blocking_pool_runner_(GetBlockingPoolRunner()), 28 : blocking_pool_runner_(GetBlockingPoolRunner()),
29 shared_sampler_(new SharedSampler(blocking_pool_runner_)) { 29 shared_sampler_(new SharedSampler(blocking_pool_runner_)) {
30 shared_sampler_->RegisterCallbacks( 30 shared_sampler_->RegisterCallbacks(
31 base::GetCurrentProcId(), 31 base::GetCurrentProcId(),
32 base::Bind(&SharedSamplerTest::OnIdleWakeupsRefreshDone, 32 base::Bind(&SharedSamplerTest::OnIdleWakeupsRefreshDone,
33 base::Unretained(this)), 33 base::Unretained(this)),
34 base::Bind(&SharedSamplerTest::OnPhysicalMemoryUsageRefreshDone, 34 base::Bind(&SharedSamplerTest::OnPhysicalMemoryUsageRefreshDone,
35 base::Unretained(this)),
36 base::Bind(&SharedSamplerTest::OnStartTimeRefreshDone,
37 base::Unretained(this)),
38 base::Bind(&SharedSamplerTest::OnCpuTimeRefreshDone,
35 base::Unretained(this))); 39 base::Unretained(this)));
36 } 40 }
37 41
38 ~SharedSamplerTest() override {} 42 ~SharedSamplerTest() override {}
39 43
40 protected: 44 protected:
41 int64_t physical_bytes() const { return physical_bytes_; } 45 int64_t physical_bytes() const { return physical_bytes_; }
42 46
47 int64_t start_time() const { return start_time_; }
48
49 int64_t cpu_time() const { return cpu_time_; }
50
43 int idle_wakeups_per_second() const { return idle_wakeups_per_second_; } 51 int idle_wakeups_per_second() const { return idle_wakeups_per_second_; }
44 52
45 int64_t finished_refresh_type() const { return finished_refresh_type_; } 53 int64_t finished_refresh_type() const { return finished_refresh_type_; }
46 54
47 void StartRefresh(int64_t refresh_flags) { 55 void StartRefresh(int64_t refresh_flags) {
48 finished_refresh_type_ = 0; 56 finished_refresh_type_ = 0;
49 expected_refresh_type_ = refresh_flags; 57 expected_refresh_type_ = refresh_flags;
50 shared_sampler_->Refresh(base::GetCurrentProcId(), refresh_flags); 58 shared_sampler_->Refresh(base::GetCurrentProcId(), refresh_flags);
51 } 59 }
52 60
(...skipping 21 matching lines...) Expand all
74 void OnPhysicalMemoryUsageRefreshDone(int64_t physical_bytes) { 82 void OnPhysicalMemoryUsageRefreshDone(int64_t physical_bytes) {
75 physical_bytes_ = physical_bytes; 83 physical_bytes_ = physical_bytes;
76 OnRefreshTypeFinished(REFRESH_TYPE_PHYSICAL_MEMORY); 84 OnRefreshTypeFinished(REFRESH_TYPE_PHYSICAL_MEMORY);
77 } 85 }
78 86
79 void OnIdleWakeupsRefreshDone(int idle_wakeups_per_second) { 87 void OnIdleWakeupsRefreshDone(int idle_wakeups_per_second) {
80 idle_wakeups_per_second_ = idle_wakeups_per_second; 88 idle_wakeups_per_second_ = idle_wakeups_per_second;
81 OnRefreshTypeFinished(REFRESH_TYPE_IDLE_WAKEUPS); 89 OnRefreshTypeFinished(REFRESH_TYPE_IDLE_WAKEUPS);
82 } 90 }
83 91
92 void OnStartTimeRefreshDone(int64_t start_time) {
93 start_time_ = start_time;
94 OnRefreshTypeFinished(REFRESH_TYPE_START_TIME);
95 }
96
97 void OnCpuTimeRefreshDone(int64_t cpu_time) {
98 cpu_time_ = cpu_time;
99 OnRefreshTypeFinished(REFRESH_TYPE_CPU_TIME);
100 }
101
84 int64_t expected_refresh_type_ = 0; 102 int64_t expected_refresh_type_ = 0;
85 int64_t finished_refresh_type_ = 0; 103 int64_t finished_refresh_type_ = 0;
86 base::Closure quit_closure_; 104 base::Closure quit_closure_;
87 105
88 int64_t physical_bytes_ = 0; 106 int64_t physical_bytes_ = 0;
89 int idle_wakeups_per_second_ = -1; 107 int idle_wakeups_per_second_ = -1;
108 int64_t start_time_ = -1;
109 int64_t cpu_time_ = -1;
90 110
91 content::TestBrowserThreadBundle thread_bundle_; 111 content::TestBrowserThreadBundle thread_bundle_;
92 scoped_refptr<base::SequencedTaskRunner> blocking_pool_runner_; 112 scoped_refptr<base::SequencedTaskRunner> blocking_pool_runner_;
93 scoped_refptr<SharedSampler> shared_sampler_; 113 scoped_refptr<SharedSampler> shared_sampler_;
94 114
95 DISALLOW_COPY_AND_ASSIGN(SharedSamplerTest); 115 DISALLOW_COPY_AND_ASSIGN(SharedSamplerTest);
96 }; 116 };
97 117
98 // Tests that Idle Wakeups per second value can be obtained from SharedSampler. 118 // Tests that Idle Wakeups per second value can be obtained from SharedSampler.
99 TEST_F(SharedSamplerTest, IdleWakeups) { 119 TEST_F(SharedSamplerTest, IdleWakeups) {
(...skipping 29 matching lines...) Expand all
129 const int allocated_size = 4 * 1024 * 1024; 149 const int allocated_size = 4 * 1024 * 1024;
130 std::vector<uint8_t> memory_block(allocated_size); 150 std::vector<uint8_t> memory_block(allocated_size);
131 151
132 StartRefresh(REFRESH_TYPE_PHYSICAL_MEMORY); 152 StartRefresh(REFRESH_TYPE_PHYSICAL_MEMORY);
133 WaitUntilRefreshDone(); 153 WaitUntilRefreshDone();
134 154
135 // Verify that physical bytes has increased accordingly. 155 // Verify that physical bytes has increased accordingly.
136 EXPECT_GE(physical_bytes(), initial_value + allocated_size); 156 EXPECT_GE(physical_bytes(), initial_value + allocated_size);
137 } 157 }
138 158
159 // Tests that process start time can be obtained from SharedSampler.
160 TEST_F(SharedSamplerTest, StartTime) {
161 StartRefresh(REFRESH_TYPE_START_TIME);
162 WaitUntilRefreshDone();
163 EXPECT_EQ(REFRESH_TYPE_START_TIME, finished_refresh_type());
164
165 // Should get a greater than zero now.
166 int64_t start_time_prev = start_time();
167 EXPECT_GT(start_time_prev, 0);
168
169 // Do a refresh.
170 StartRefresh(REFRESH_TYPE_START_TIME);
171 WaitUntilRefreshDone();
172
173 // Start time should not change.
174 EXPECT_EQ(start_time(), start_time_prev);
175 }
176
177 // Tests that CPU time can be obtained from SharedSampler.
178 TEST_F(SharedSamplerTest, CpuTime) {
179 StartRefresh(REFRESH_TYPE_CPU_TIME);
180 WaitUntilRefreshDone();
181 EXPECT_EQ(REFRESH_TYPE_CPU_TIME, finished_refresh_type());
182
183 // Should get a greater than or equal to zero now.
184 int64_t cpu_time_prev = cpu_time();
185 EXPECT_GE(cpu_time_prev, 0);
186
187 // Do a refresh.
188 StartRefresh(REFRESH_TYPE_CPU_TIME);
189 WaitUntilRefreshDone();
190
191 // CPU time should not decrease.
192 EXPECT_GE(cpu_time(), cpu_time_prev);
193 }
194
195
139 // Verifies that multiple refresh types can be refreshed at the same time. 196 // Verifies that multiple refresh types can be refreshed at the same time.
140 TEST_F(SharedSamplerTest, MultipleRefreshTypes) { 197 TEST_F(SharedSamplerTest, MultipleRefreshTypes) {
141 StartRefresh(REFRESH_TYPE_IDLE_WAKEUPS | REFRESH_TYPE_PHYSICAL_MEMORY); 198 StartRefresh(REFRESH_TYPE_IDLE_WAKEUPS | REFRESH_TYPE_PHYSICAL_MEMORY |
199 REFRESH_TYPE_START_TIME | REFRESH_TYPE_CPU_TIME);
142 WaitUntilRefreshDone(); 200 WaitUntilRefreshDone();
143 EXPECT_EQ(REFRESH_TYPE_IDLE_WAKEUPS | REFRESH_TYPE_PHYSICAL_MEMORY, 201 EXPECT_EQ(REFRESH_TYPE_IDLE_WAKEUPS | REFRESH_TYPE_PHYSICAL_MEMORY |
202 REFRESH_TYPE_START_TIME | REFRESH_TYPE_CPU_TIME,
144 finished_refresh_type()); 203 finished_refresh_type());
145 } 204 }
146 205
147 } // namespace task_manager 206 } // namespace task_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698