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

Side by Side Diff: chrome/test/memory_test/memory_test.cc

Issue 402104: Convert memory_test to use the common stats-reporting methods in UITest.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: make the commit_charge unimportant so page load time is displayed on the default overview Created 11 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/test/ui/ui_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 if (url == "<NEWTAB>") { // Special command to create a new tab 152 if (url == "<NEWTAB>") { // Special command to create a new tab
153 if (++counter >= urls_length) 153 if (++counter >= urls_length)
154 continue; // Newtab was specified at end of list. ignore. 154 continue; // Newtab was specified at end of list. ignore.
155 155
156 url = urls[counter]; 156 url = urls[counter];
157 if (GetTabCount() < num_target_tabs) { 157 if (GetTabCount() < num_target_tabs) {
158 EXPECT_TRUE(window->AppendTab(GURL(url))); 158 EXPECT_TRUE(window->AppendTab(GURL(url)));
159 expected_tab_count++; 159 expected_tab_count++;
160 WaitUntilTabCount(expected_tab_count); 160 WaitUntilTabCount(expected_tab_count);
161 tab = window->GetActiveTab(); 161 tab = window->GetActiveTab();
162 EXPECT_NE(tab, static_cast<TabProxy*>(NULL));
162 continue; 163 continue;
163 } 164 }
164 165
165 int tab_index = counter % num_target_tabs; // A pseudo-random tab. 166 int tab_index = counter % num_target_tabs; // A pseudo-random tab.
166 tab = window->GetTab(tab_index); 167 tab = window->GetTab(tab_index);
167 } 168 }
168 169
169 if (url == "<NEXTTAB>") { // Special command to select the next tab. 170 if (url == "<NEXTTAB>") { // Special command to select the next tab.
170 int tab_index, tab_count; 171 int tab_index, tab_count;
171 window->GetActiveTabIndex(&tab_index); 172 window->GetActiveTabIndex(&tab_index);
172 window->GetTabCount(&tab_count); 173 window->GetTabCount(&tab_count);
173 tab_index = (tab_index + 1) % tab_count; 174 tab_index = (tab_index + 1) % tab_count;
174 tab = window->GetTab(tab_index); 175 tab = window->GetTab(tab_index);
176 EXPECT_NE(tab, static_cast<TabProxy*>(NULL));
175 continue; 177 continue;
176 } 178 }
177 179
178 if (url == "<NEWWINDOW>") { // Special command to create a new window. 180 if (url == "<NEWWINDOW>") { // Special command to create a new window.
179 if (counter + 1 >= urls_length) 181 if (counter + 1 >= urls_length)
180 continue; // Newwindows was specified at end of list. ignore. 182 continue; // Newwindows was specified at end of list. ignore.
181 183
182 int window_count; 184 int window_count;
183 EXPECT_TRUE(automation()->GetBrowserWindowCount(&window_count)); 185 EXPECT_TRUE(automation()->GetBrowserWindowCount(&window_count));
184 EXPECT_TRUE(automation()->OpenNewBrowserWindow(Browser::TYPE_NORMAL, 186 EXPECT_TRUE(automation()->OpenNewBrowserWindow(Browser::TYPE_NORMAL,
185 show_window_)); 187 show_window_));
186 int expected_window_count = window_count + 1; 188 int expected_window_count = window_count + 1;
187 automation()->WaitForWindowCountToBecome(expected_window_count, 500); 189 automation()->WaitForWindowCountToBecome(expected_window_count, 500);
188 EXPECT_TRUE(automation()->GetBrowserWindowCount(&window_count)); 190 EXPECT_TRUE(automation()->GetBrowserWindowCount(&window_count));
189 EXPECT_EQ(expected_window_count, window_count); 191 EXPECT_EQ(expected_window_count, window_count);
190 192
191 // A new window will not load a url if requested too soon. The window 193 // A new window will not load a url if requested too soon. The window
192 // stays on the new tab page instead. 194 // stays on the new tab page instead.
193 PlatformThread::Sleep(200); 195 PlatformThread::Sleep(200);
194 196
195 active_window = window_count - 1; 197 active_window = window_count - 1;
196 window = automation()->GetBrowserWindow(active_window); 198 window = automation()->GetBrowserWindow(active_window);
197 tab = window->GetActiveTab(); 199 tab = window->GetActiveTab();
200 EXPECT_NE(tab, static_cast<TabProxy*>(NULL));
198 continue; 201 continue;
199 } 202 }
200 203
201 if (url == "<NEXTWINDOW>") { // Select the next window. 204 if (url == "<NEXTWINDOW>") { // Select the next window.
202 int window_count; 205 int window_count;
203 EXPECT_TRUE(automation()->GetBrowserWindowCount(&window_count)); 206 EXPECT_TRUE(automation()->GetBrowserWindowCount(&window_count));
204 active_window = (active_window + 1) % window_count; 207 active_window = (active_window + 1) % window_count;
205 window = automation()->GetBrowserWindow(active_window); 208 window = automation()->GetBrowserWindow(active_window);
206 tab = window->GetActiveTab(); 209 tab = window->GetActiveTab();
210 EXPECT_NE(tab, static_cast<TabProxy*>(NULL));
207 continue; 211 continue;
208 } 212 }
209 213
210 const int kMaxWaitTime = 5000; 214 const int kMaxWaitTime = 5000;
211 bool timed_out = false; 215 bool timed_out = false;
212 tab->NavigateToURLWithTimeout(GURL(urls[counter]), 1, kMaxWaitTime, 216 tab->NavigateToURLWithTimeout(GURL(urls[counter]), 1, kMaxWaitTime,
213 &timed_out); 217 &timed_out);
214 if (timed_out) 218 if (timed_out)
215 printf("warning: %s timed out!\n", urls[counter].c_str()); 219 printf("warning: %s timed out!\n", urls[counter].c_str());
216 220
217 // TODO(mbelshe): Bug 2953 221 // TODO(mbelshe): Bug 2953
218 // The automation crashes periodically if we cycle too quickly. 222 // The automation crashes periodically if we cycle too quickly.
219 // To make these tests more reliable, slowing them down a bit. 223 // To make these tests more reliable, slowing them down a bit.
220 PlatformThread::Sleep(100); 224 PlatformThread::Sleep(100);
221 } 225 }
222 226
223 size_t stop_size = base::GetSystemCommitCharge(); 227 size_t stop_size = base::GetSystemCommitCharge();
224 PrintResults(test_name, (stop_size - start_size) * 1024); 228 PrintIOPerfInfo(test_name, user_data_dir_);
225 } 229 PrintMemoryUsageInfo(test_name, user_data_dir_);
226 230 PrintSystemCommitCharge(test_name, stop_size - start_size);
227 void PrintResults(const char* test_name, size_t commit_size) {
228 PrintMemoryUsageInfo(test_name);
229 std::string trace_name(test_name);
230 trace_name.append("_cc");
231
232 PrintResult("commit_charge", "", trace_name,
233 commit_size / 1024, "kb", true /* important */);
234 }
235
236 void PrintIOPerfInfo(const char* test_name) {
237 printf("\n");
238
239 int browser_process_pid = ChromeBrowserProcessId(user_data_dir_);
240 ASSERT_NE(browser_process_pid, -1);
241
242 ChromeProcessList chrome_processes(
243 GetRunningChromeProcesses(user_data_dir_));
244
245 ChromeProcessList::const_iterator it;
246 for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) {
247 IoCounters io_counters;
248 base::ProcessHandle process_handle;
249 if (!base::OpenPrivilegedProcessHandle(*it, &process_handle)) {
250 NOTREACHED();
251 }
252
253 // TODO(sgk): if/when base::ProcessMetrics can return real memory
254 // stats on mac, convert to:
255 //
256 // scoped_ptr<base::ProcessMetrics> process_metrics;
257 // process_metrics.reset(
258 // base::ProcessMetrics::CreateProcessMetrics(process_handle));
259 scoped_ptr<ChromeTestProcessMetrics> process_metrics;
260 process_metrics.reset(
261 ChromeTestProcessMetrics::CreateProcessMetrics(process_handle));
262
263 bzero(&io_counters, sizeof(io_counters));
264 if (process_metrics.get()->GetIOCounters(&io_counters)) {
265 std::string chrome_name = (*it == browser_process_pid) ? "_b" : "_r";
266
267 // Print out IO performance. We assume that the values can be
268 // converted to size_t (they're reported as ULONGLONG, 64-bit numbers).
269 PrintResult("read_op", chrome_name, test_name + chrome_name,
270 static_cast<size_t>(io_counters.ReadOperationCount), "",
271 false /* not important */);
272 PrintResult("write_op", chrome_name, test_name + chrome_name,
273 static_cast<size_t>(io_counters.WriteOperationCount), "",
274 false /* not important */);
275 PrintResult("other_op", chrome_name, test_name + chrome_name,
276 static_cast<size_t>(io_counters.OtherOperationCount), "",
277 false /* not important */);
278 PrintResult("read_byte", chrome_name, test_name + chrome_name,
279 static_cast<size_t>(io_counters.ReadTransferCount / 1024),
280 "kb", false /* not important */);
281 PrintResult("write_byte", chrome_name, test_name + chrome_name,
282 static_cast<size_t>(io_counters.WriteTransferCount / 1024),
283 "kb", false /* not important */);
284 PrintResult("other_byte", chrome_name, test_name + chrome_name,
285 static_cast<size_t>(io_counters.OtherTransferCount / 1024),
286 "kb", false /* not important */);
287 }
288
289 base::CloseProcessHandle(process_handle);
290 }
291 }
292
293 void PrintMemoryUsageInfo(const char* test_name) {
294 printf("\n");
295
296 int browser_process_pid = ChromeBrowserProcessId(user_data_dir_);
297 ASSERT_NE(browser_process_pid, -1);
298
299 ChromeProcessList chrome_processes(
300 GetRunningChromeProcesses(user_data_dir_));
301
302 size_t browser_virtual_size = 0;
303 size_t browser_working_set_size = 0;
304 size_t virtual_size = 0;
305 size_t working_set_size = 0;
306 ChromeProcessList::const_iterator it;
307 for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) {
308 base::ProcessHandle process_handle;
309 if (!base::OpenPrivilegedProcessHandle(*it, &process_handle)) {
310 NOTREACHED();
311 }
312
313 // TODO(sgk): if/when base::ProcessMetrics can return real memory
314 // stats on mac, convert to:
315 //
316 // scoped_ptr<base::ProcessMetrics> process_metrics;
317 // process_metrics.reset(
318 // base::ProcessMetrics::CreateProcessMetrics(process_handle));
319 scoped_ptr<ChromeTestProcessMetrics> process_metrics;
320 process_metrics.reset(
321 ChromeTestProcessMetrics::CreateProcessMetrics(process_handle));
322
323 size_t current_virtual_size = process_metrics->GetPagefileUsage();
324 size_t current_working_set_size = process_metrics->GetWorkingSetSize();
325
326 if (*it == browser_process_pid) {
327 browser_virtual_size = current_virtual_size;
328 browser_working_set_size = current_working_set_size;
329 }
330 virtual_size += current_virtual_size;
331 working_set_size += current_working_set_size;
332 }
333
334 std::string trace_name(test_name);
335 PrintResult("vm_final_browser", "", trace_name + "_vm_b",
336 browser_virtual_size / 1024, "kb",
337 false /* not important */);
338 PrintResult("ws_final_browser", "", trace_name + "_ws_b",
339 browser_working_set_size / 1024, "kb",
340 false /* not important */);
341 PrintResult("vm_final_total", "", trace_name + "_vm",
342 virtual_size / 1024, "kb",
343 false /* not important */);
344 PrintResult("ws_final_total", "", trace_name + "_ws",
345 working_set_size / 1024, "kb",
346 true /* important */);
347 PrintResult("processes", "", trace_name + "_proc",
348 chrome_processes.size(), "",
349 false /* not important */);
350 } 231 }
351 232
352 private: 233 private:
353 // Setup a temporary directory to store the profile to use 234 // Setup a temporary directory to store the profile to use
354 // with these tests. 235 // with these tests.
355 // Input: 236 // Input:
356 // src_dir is set to the source directory 237 // src_dir is set to the source directory
357 // Output: 238 // Output:
358 // On success, modifies user_data_dir_ to be a new profile directory 239 // On success, modifies user_data_dir_ to be a new profile directory
359 // sets temp_dir_ to the containing temporary directory, 240 // sets temp_dir_ to the containing temporary directory,
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 "http://bioshock.wikia.com/wiki/Main_Page", 508 "http://bioshock.wikia.com/wiki/Main_Page",
628 "http://www.armchairgm.com/Special:ImageRating", 509 "http://www.armchairgm.com/Special:ImageRating",
629 "http://www.armchairgm.com/Anderson_Continues_to_Thrive_for_Cleveland", 510 "http://www.armchairgm.com/Anderson_Continues_to_Thrive_for_Cleveland",
630 "http://www.armchairgm.com/Main_Page" 511 "http://www.armchairgm.com/Main_Page"
631 }; 512 };
632 513
633 size_t MembusterMemoryTest::urls_length_ = 514 size_t MembusterMemoryTest::urls_length_ =
634 arraysize(MembusterMemoryTest::source_urls_); 515 arraysize(MembusterMemoryTest::source_urls_);
635 516
636 TEST_F(GeneralMixMemoryTest, SingleTabTest) { 517 TEST_F(GeneralMixMemoryTest, SingleTabTest) {
637 RunTest("1t", 1); 518 RunTest("_1t", 1);
638 } 519 }
639 520
640 TEST_F(GeneralMixMemoryTest, FiveTabTest) { 521 TEST_F(GeneralMixMemoryTest, FiveTabTest) {
641 RunTest("5t", 5); 522 RunTest("_5t", 5);
642 } 523 }
643 524
644 TEST_F(GeneralMixMemoryTest, TwelveTabTest) { 525 TEST_F(GeneralMixMemoryTest, TwelveTabTest) {
645 RunTest("12t", 12); 526 RunTest("_12t", 12);
646 } 527 }
647 528
648 // Commented out until the recorded cache data is added. 529 // Commented out until the recorded cache data is added.
649 //TEST_F(MembusterMemoryTest, Windows) { 530 //TEST_F(MembusterMemoryTest, Windows) {
650 // RunTest("membuster", 0); 531 // RunTest("membuster", 0);
651 //} 532 //}
652 533
653 } // namespace 534 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/test/ui/ui_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698