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

Side by Side Diff: chrome/test/ui/ui_test.cc

Issue 3137040: GTTF: Extract performance-testing-specific parts of UITestBase to UIPerfTest.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/ui/ui_test.h ('k') | chrome/test/ui/v8_benchmark_uitest.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/test/ui/ui_test.h" 5 #include "chrome/test/ui/ui_test.h"
6 6
7 #if defined(OS_POSIX) 7 #if defined(OS_POSIX)
8 #include <signal.h> 8 #include <signal.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #endif 10 #endif
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 cookie_name.append(test_complete_cookie); 924 cookie_name.append(test_complete_cookie);
925 925
926 scoped_refptr<TabProxy> tab(GetActiveTab()); 926 scoped_refptr<TabProxy> tab(GetActiveTab());
927 ASSERT_TRUE(tab.get()); 927 ASSERT_TRUE(tab.get());
928 std::string cookie_value = WaitUntilCookieNonEmpty(tab.get(), url, 928 std::string cookie_value = WaitUntilCookieNonEmpty(tab.get(), url,
929 cookie_name.c_str(), 929 cookie_name.c_str(),
930 wait_time); 930 wait_time);
931 EXPECT_EQ(expected_cookie_value, cookie_value); 931 EXPECT_EQ(expected_cookie_value, cookie_value);
932 } 932 }
933 933
934 void UITestBase::PrintResult(const std::string& measurement,
935 const std::string& modifier,
936 const std::string& trace,
937 size_t value,
938 const std::string& units,
939 bool important) {
940 PrintResultsImpl(measurement, modifier, trace, base::UintToString(value),
941 "", "", units, important);
942 }
943
944 void UITestBase::PrintResult(const std::string& measurement,
945 const std::string& modifier,
946 const std::string& trace,
947 const std::string& value,
948 const std::string& units,
949 bool important) {
950 PrintResultsImpl(measurement, modifier, trace, value, "", "", units,
951 important);
952 }
953
954 void UITestBase::PrintResultMeanAndError(const std::string& measurement,
955 const std::string& modifier,
956 const std::string& trace,
957 const std::string& mean_and_error,
958 const std::string& units,
959 bool important) {
960 PrintResultsImpl(measurement, modifier, trace, mean_and_error,
961 "{", "}", units, important);
962 }
963
964 void UITestBase::PrintResultList(const std::string& measurement,
965 const std::string& modifier,
966 const std::string& trace,
967 const std::string& values,
968 const std::string& units,
969 bool important) {
970 PrintResultsImpl(measurement, modifier, trace, values,
971 "[", "]", units, important);
972 }
973
974 void UITestBase::PrintResultsImpl(const std::string& measurement,
975 const std::string& modifier,
976 const std::string& trace,
977 const std::string& values,
978 const std::string& prefix,
979 const std::string& suffix,
980 const std::string& units,
981 bool important) {
982 // <*>RESULT <graph_name>: <trace_name>= <value> <units>
983 // <*>RESULT <graph_name>: <trace_name>= {<mean>, <std deviation>} <units>
984 // <*>RESULT <graph_name>: <trace_name>= [<value>,value,value,...,] <units>
985 printf("%sRESULT %s%s: %s= %s%s%s %s\n",
986 important ? "*" : "", measurement.c_str(), modifier.c_str(),
987 trace.c_str(), prefix.c_str(), values.c_str(), suffix.c_str(),
988 units.c_str());
989 }
990
991 bool UITestBase::EvictFileFromSystemCacheWrapper(const FilePath& path) { 934 bool UITestBase::EvictFileFromSystemCacheWrapper(const FilePath& path) {
992 for (int i = 0; i < 10; i++) { 935 for (int i = 0; i < 10; i++) {
993 if (file_util::EvictFileFromSystemCache(path)) 936 if (file_util::EvictFileFromSystemCache(path))
994 return true; 937 return true;
995 PlatformThread::Sleep(sleep_timeout_ms() / 10); 938 PlatformThread::Sleep(sleep_timeout_ms() / 10);
996 } 939 }
997 return false; 940 return false;
998 } 941 }
999 942
1000 // static 943 // static
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 std::string query = StringPrintf( 1193 std::string query = StringPrintf(
1251 "UPDATE segment_usage " 1194 "UPDATE segment_usage "
1252 "SET time_slot = %s " 1195 "SET time_slot = %s "
1253 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);", 1196 "WHERE id IN (SELECT id FROM segment_usage WHERE time_slot > 0);",
1254 yesterday_str.c_str()); 1197 yesterday_str.c_str());
1255 ASSERT_TRUE(db.Execute(query.c_str())); 1198 ASSERT_TRUE(db.Execute(query.c_str()));
1256 db.Close(); 1199 db.Close();
1257 file_util::EvictFileFromSystemCache(history); 1200 file_util::EvictFileFromSystemCache(history);
1258 } 1201 }
1259 1202
1260 void UITestBase::PrintIOPerfInfo(const char* test_name) {
1261 ChromeProcessList chrome_processes(GetRunningChromeProcesses(process_id_));
1262
1263 size_t read_op_b = 0;
1264 size_t read_op_r = 0;
1265 size_t write_op_b = 0;
1266 size_t write_op_r = 0;
1267 size_t other_op_b = 0;
1268 size_t other_op_r = 0;
1269 size_t total_op_b = 0;
1270 size_t total_op_r = 0;
1271
1272 size_t read_byte_b = 0;
1273 size_t read_byte_r = 0;
1274 size_t write_byte_b = 0;
1275 size_t write_byte_r = 0;
1276 size_t other_byte_b = 0;
1277 size_t other_byte_r = 0;
1278 size_t total_byte_b = 0;
1279 size_t total_byte_r = 0;
1280
1281 ChromeProcessList::const_iterator it;
1282 for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) {
1283 base::ProcessHandle process_handle;
1284 if (!base::OpenPrivilegedProcessHandle(*it, &process_handle)) {
1285 NOTREACHED();
1286 return;
1287 }
1288
1289 // TODO(sgk): if/when base::ProcessMetrics returns real stats on mac:
1290 // scoped_ptr<base::ProcessMetrics> process_metrics(
1291 // base::ProcessMetrics::CreateProcessMetrics(process_handle));
1292 scoped_ptr<ChromeTestProcessMetrics> process_metrics(
1293 ChromeTestProcessMetrics::CreateProcessMetrics(process_handle));
1294 base::IoCounters io_counters;
1295 memset(&io_counters, 0, sizeof(io_counters));
1296
1297 if (process_metrics.get()->GetIOCounters(&io_counters)) {
1298 // Print out IO performance. We assume that the values can be
1299 // converted to size_t (they're reported as ULONGLONG, 64-bit numbers).
1300 std::string chrome_name = (*it == browser_process_id()) ? "_b" : "_r";
1301
1302 size_t read_op = static_cast<size_t>(io_counters.ReadOperationCount);
1303 size_t write_op = static_cast<size_t>(io_counters.WriteOperationCount);
1304 size_t other_op = static_cast<size_t>(io_counters.OtherOperationCount);
1305 size_t total_op = static_cast<size_t>(io_counters.ReadOperationCount +
1306 io_counters.WriteOperationCount +
1307 io_counters.OtherOperationCount);
1308
1309 size_t read_byte = static_cast<size_t>(io_counters.ReadTransferCount
1310 / 1024);
1311 size_t write_byte = static_cast<size_t>(io_counters.WriteTransferCount
1312 / 1024);
1313 size_t other_byte = static_cast<size_t>(io_counters.OtherTransferCount
1314 / 1024);
1315 size_t total_byte = static_cast<size_t>((io_counters.ReadTransferCount +
1316 io_counters.WriteTransferCount +
1317 io_counters.OtherTransferCount)
1318 / 1024);
1319
1320 if (*it == browser_process_id()) {
1321 read_op_b = read_op;
1322 write_op_b = write_op;
1323 other_op_b = other_op;
1324 total_op_b = total_op;
1325 read_byte_b = read_byte;
1326 write_byte_b = write_byte;
1327 other_byte_b = other_byte;
1328 total_byte_b = total_byte;
1329 } else {
1330 read_op_r += read_op;
1331 write_op_r += write_op;
1332 other_op_r += other_op;
1333 total_op_r += total_op;
1334 read_byte_r += read_byte;
1335 write_byte_r += write_byte;
1336 other_byte_r += other_byte;
1337 total_byte_r += total_byte;
1338 }
1339 }
1340
1341 base::CloseProcessHandle(process_handle);
1342 }
1343
1344 std::string t_name(test_name);
1345 PrintResult("read_op_b", "", "r_op_b" + t_name, read_op_b, "", false);
1346 PrintResult("write_op_b", "", "w_op_b" + t_name, write_op_b, "", false);
1347 PrintResult("other_op_b", "", "o_op_b" + t_name, other_op_b, "", false);
1348 PrintResult("total_op_b", "", "IO_op_b" + t_name, total_op_b, "", true);
1349
1350 PrintResult("read_byte_b", "", "r_b" + t_name, read_byte_b, "kb", false);
1351 PrintResult("write_byte_b", "", "w_b" + t_name, write_byte_b, "kb", false);
1352 PrintResult("other_byte_b", "", "o_b" + t_name, other_byte_b, "kb", false);
1353 PrintResult("total_byte_b", "", "IO_b" + t_name, total_byte_b, "kb", true);
1354
1355 PrintResult("read_op_r", "", "r_op_r" + t_name, read_op_r, "", false);
1356 PrintResult("write_op_r", "", "w_op_r" + t_name, write_op_r, "", false);
1357 PrintResult("other_op_r", "", "o_op_r" + t_name, other_op_r, "", false);
1358 PrintResult("total_op_r", "", "IO_op_r" + t_name, total_op_r, "", true);
1359
1360 PrintResult("read_byte_r", "", "r_r" + t_name, read_byte_r, "kb", false);
1361 PrintResult("write_byte_r", "", "w_r" + t_name, write_byte_r, "kb", false);
1362 PrintResult("other_byte_r", "", "o_r" + t_name, other_byte_r, "kb", false);
1363 PrintResult("total_byte_r", "", "IO_r" + t_name, total_byte_r, "kb", true);
1364 }
1365
1366 void UITestBase::PrintMemoryUsageInfo(const char* test_name) {
1367 ChromeProcessList chrome_processes(GetRunningChromeProcesses(process_id_));
1368
1369 size_t browser_virtual_size = 0;
1370 size_t browser_working_set_size = 0;
1371 size_t renderer_virtual_size = 0;
1372 size_t renderer_working_set_size = 0;
1373 size_t total_virtual_size = 0;
1374 size_t total_working_set_size = 0;
1375 #if defined(OS_WIN)
1376 size_t browser_peak_virtual_size = 0;
1377 size_t browser_peak_working_set_size = 0;
1378 size_t renderer_total_peak_virtual_size = 0;
1379 size_t renderer_total_peak_working_set_size = 0;
1380 size_t renderer_single_peak_virtual_size = 0;
1381 size_t renderer_single_peak_working_set_size = 0;
1382 #endif
1383
1384 ChromeProcessList::const_iterator it;
1385 for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) {
1386 base::ProcessHandle process_handle;
1387 if (!base::OpenPrivilegedProcessHandle(*it, &process_handle)) {
1388 NOTREACHED();
1389 return;
1390 }
1391
1392 // TODO(sgk): if/when base::ProcessMetrics returns real stats on mac:
1393 // scoped_ptr<base::ProcessMetrics> process_metrics(
1394 // base::ProcessMetrics::CreateProcessMetrics(process_handle));
1395 scoped_ptr<ChromeTestProcessMetrics> process_metrics(
1396 ChromeTestProcessMetrics::CreateProcessMetrics(process_handle));
1397
1398 size_t current_virtual_size = process_metrics->GetPagefileUsage();
1399 size_t current_working_set_size = process_metrics->GetWorkingSetSize();
1400
1401 if (*it == browser_process_id()) {
1402 browser_virtual_size = current_virtual_size;
1403 browser_working_set_size = current_working_set_size;
1404 } else {
1405 renderer_virtual_size += current_virtual_size;
1406 renderer_working_set_size += current_working_set_size;
1407 }
1408 total_virtual_size += current_virtual_size;
1409 total_working_set_size += current_working_set_size;
1410
1411 #if defined(OS_WIN)
1412 size_t peak_virtual_size = process_metrics->GetPeakPagefileUsage();
1413 size_t peak_working_set_size = process_metrics->GetPeakWorkingSetSize();
1414 if (*it == browser_process_id()) {
1415 browser_peak_virtual_size = peak_virtual_size;
1416 browser_peak_working_set_size = peak_working_set_size;
1417 } else {
1418 if (peak_virtual_size > renderer_single_peak_virtual_size) {
1419 renderer_single_peak_virtual_size = peak_virtual_size;
1420 }
1421 if (peak_working_set_size > renderer_single_peak_working_set_size) {
1422 renderer_single_peak_working_set_size = peak_working_set_size;
1423 }
1424 renderer_total_peak_virtual_size += peak_virtual_size;
1425 renderer_total_peak_working_set_size += peak_working_set_size;
1426 }
1427 #endif
1428
1429 base::CloseProcessHandle(process_handle);
1430 }
1431
1432 std::string trace_name(test_name);
1433 #if defined(OS_WIN)
1434 PrintResult("vm_peak_b", "", "vm_pk_b" + trace_name,
1435 browser_peak_virtual_size, "bytes",
1436 true /* important */);
1437 PrintResult("ws_peak_b", "", "ws_pk_b" + trace_name,
1438 browser_peak_working_set_size, "bytes",
1439 true /* important */);
1440 PrintResult("vm_peak_r", "", "vm_pk_r" + trace_name,
1441 renderer_total_peak_virtual_size, "bytes",
1442 true /* important */);
1443 PrintResult("ws_peak_r", "", "ws_pk_r" + trace_name,
1444 renderer_total_peak_working_set_size, "bytes",
1445 true /* important */);
1446 PrintResult("vm_single_peak_r", "", "vm_spk_r" + trace_name,
1447 renderer_single_peak_virtual_size, "bytes",
1448 true /* important */);
1449 PrintResult("ws_single_peak_r", "", "ws_spk_r" + trace_name,
1450 renderer_single_peak_working_set_size, "bytes",
1451 true /* important */);
1452
1453 PrintResult("vm_final_b", "", "vm_f_b" + trace_name,
1454 browser_virtual_size, "bytes",
1455 false /* not important */);
1456 PrintResult("ws_final_b", "", "ws_f_b" + trace_name,
1457 browser_working_set_size, "bytes",
1458 false /* not important */);
1459 PrintResult("vm_final_r", "", "vm_f_r" + trace_name,
1460 renderer_virtual_size, "bytes",
1461 false /* not important */);
1462 PrintResult("ws_final_r", "", "ws_f_r" + trace_name,
1463 renderer_working_set_size, "bytes",
1464 false /* not important */);
1465 PrintResult("vm_final_t", "", "vm_f_t" + trace_name,
1466 total_virtual_size, "bytes",
1467 false /* not important */);
1468 PrintResult("ws_final_t", "", "ws_f_t" + trace_name,
1469 total_working_set_size, "bytes",
1470 false /* not important */);
1471 #elif defined(OS_LINUX) || defined(OS_MACOSX)
1472 PrintResult("vm_size_final_b", "", "vm_size_f_b" + trace_name,
1473 browser_virtual_size, "bytes",
1474 true /* important */);
1475 PrintResult("vm_rss_final_b", "", "vm_rss_f_b" + trace_name,
1476 browser_working_set_size, "bytes",
1477 true /* important */);
1478 PrintResult("vm_size_final_r", "", "vm_size_f_r" + trace_name,
1479 renderer_virtual_size, "bytes",
1480 true /* important */);
1481 PrintResult("vm_rss_final_r", "", "vm_rss_f_r" + trace_name,
1482 renderer_working_set_size, "bytes",
1483 true /* important */);
1484 PrintResult("vm_size_final_t", "", "vm_size_f_t" + trace_name,
1485 total_virtual_size, "bytes",
1486 true /* important */);
1487 PrintResult("vm_rss_final_t", "", "vm_rss_f_t" + trace_name,
1488 total_working_set_size, "bytes",
1489 true /* important */);
1490 #else
1491 NOTIMPLEMENTED();
1492 #endif
1493 PrintResult("processes", "", "proc_" + trace_name,
1494 chrome_processes.size(), "",
1495 false /* not important */);
1496 }
1497
1498 void UITestBase::PrintSystemCommitCharge(const char* test_name,
1499 size_t charge,
1500 bool important) {
1501 std::string trace_name(test_name);
1502 PrintResult("commit_charge", "", "cc" + trace_name, charge, "kb", important);
1503 }
1504
1505 void UITestBase::UseReferenceBuild() {
1506 FilePath dir;
1507 PathService::Get(chrome::DIR_TEST_TOOLS, &dir);
1508 dir = dir.AppendASCII("reference_build");
1509 #if defined(OS_WIN)
1510 dir = dir.AppendASCII("chrome");
1511 #elif defined(OS_LINUX)
1512 dir = dir.AppendASCII("chrome_linux");
1513 #elif defined(OS_MACOSX)
1514 dir = dir.AppendASCII("chrome_mac");
1515 #endif
1516 SetBrowserDirectory(dir);
1517 }
1518
1519 void UITestBase::SetBrowserDirectory(const FilePath& dir) { 1203 void UITestBase::SetBrowserDirectory(const FilePath& dir) {
1520 browser_directory_ = dir; 1204 browser_directory_ = dir;
1521 } 1205 }
1522 1206
1523 // UITest methods 1207 // UITest methods
1524 1208
1525 void UITest::SetUp() { 1209 void UITest::SetUp() {
1526 // Pass the test case name to chrome.exe on the command line to help with 1210 // Pass the test case name to chrome.exe on the command line to help with
1527 // parsing Purify output. 1211 // parsing Purify output.
1528 const testing::TestInfo* const test_info = 1212 const testing::TestInfo* const test_info =
(...skipping 11 matching lines...) Expand all
1540 PlatformTest::TearDown(); 1224 PlatformTest::TearDown();
1541 } 1225 }
1542 1226
1543 AutomationProxy* UITest::CreateAutomationProxy(int execution_timeout) { 1227 AutomationProxy* UITest::CreateAutomationProxy(int execution_timeout) {
1544 // Make the AutomationProxy disconnect the channel on the first error, 1228 // Make the AutomationProxy disconnect the channel on the first error,
1545 // so that we avoid spending a lot of time in timeouts. The browser is likely 1229 // so that we avoid spending a lot of time in timeouts. The browser is likely
1546 // hosed if we hit those errors. 1230 // hosed if we hit those errors.
1547 return new AutomationProxy(execution_timeout, true); 1231 return new AutomationProxy(execution_timeout, true);
1548 } 1232 }
1549 1233
OLDNEW
« no previous file with comments | « chrome/test/ui/ui_test.h ('k') | chrome/test/ui/v8_benchmark_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698