Changeset 45012 in vbox for trunk/src/VBox/Main
- Timestamp:
- Mar 13, 2013 7:57:24 AM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 84246
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/testcase/tstCollector.cpp
r44529 r45012 224 224 uint64_t diskMsStop, totalMsStop; 225 225 226 std::list<RTCString>disks;226 pm::DiskList disks; 227 227 int rc = collector->getDiskListByFs(FSNAME, disks); 228 228 if (RT_FAILURE(rc)) … … 237 237 } 238 238 239 uint64_t diskSize = 0; 240 rc = collector->getHostDiskSize(disks.front().c_str(), &diskSize); 241 RTPrintf("tstCollector: TESTING - Disk size (%s) = %llu\n", disks.front().c_str(), diskSize); 242 if (RT_FAILURE(rc)) 243 { 244 RTPrintf("tstCollector: getHostDiskSize() -> %Rrc\n", rc); 245 return 1; 246 } 247 248 RTPrintf("tstCollector: TESTING - Disk utilization (%s), sleeping for 5 sec...\n", disks.front().c_str()); 249 250 hints.collectHostCpuLoad(); 251 rc = collector->preCollect(hints, 0); 252 if (RT_FAILURE(rc)) 253 { 254 RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc); 255 return 1; 256 } 257 rc = collector->getRawHostDiskLoad(disks.front().c_str(), &diskMsStart, &totalMsStart); 258 if (RT_FAILURE(rc)) 259 { 260 RTPrintf("tstCollector: getRawHostDiskLoad() -> %Rrc\n", rc); 261 return 1; 262 } 263 264 RTThreadSleep(5000); // Sleep for five seconds 265 266 rc = collector->preCollect(hints, 0); 267 if (RT_FAILURE(rc)) 268 { 269 RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc); 270 return 1; 271 } 272 rc = collector->getRawHostDiskLoad(disks.front().c_str(), &diskMsStop, &totalMsStop); 273 if (RT_FAILURE(rc)) 274 { 275 RTPrintf("tstCollector: getRawHostDiskLoad() -> %Rrc\n", rc); 276 return 1; 277 } 278 RTPrintf("tstCollector: host disk util = %llu msec (%u.%u %%), total = %llu msec\n\n", 279 (diskMsStop - diskMsStart), 280 (unsigned)((diskMsStop - diskMsStart) * 100 / (totalMsStop - totalMsStart)), 281 (unsigned)((diskMsStop - diskMsStart) * 10000 / (totalMsStop - totalMsStart) % 100), 282 totalMsStop - totalMsStart); 239 pm::DiskList::iterator it; 240 for (it = disks.begin(); it != disks.end(); ++it) 241 { 242 uint64_t diskSize = 0; 243 rc = collector->getHostDiskSize(disks.front().c_str(), &diskSize); 244 RTPrintf("tstCollector: TESTING - Disk size (%s) = %llu\n", disks.front().c_str(), diskSize); 245 if (RT_FAILURE(rc)) 246 { 247 RTPrintf("tstCollector: getHostDiskSize() -> %Rrc\n", rc); 248 return 1; 249 } 250 251 RTPrintf("tstCollector: TESTING - Disk utilization (%s), sleeping for 5 sec...\n", disks.front().c_str()); 252 253 hints.collectHostCpuLoad(); 254 rc = collector->preCollect(hints, 0); 255 if (RT_FAILURE(rc)) 256 { 257 RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc); 258 return 1; 259 } 260 rc = collector->getRawHostDiskLoad(disks.front().c_str(), &diskMsStart, &totalMsStart); 261 if (RT_FAILURE(rc)) 262 { 263 RTPrintf("tstCollector: getRawHostDiskLoad() -> %Rrc\n", rc); 264 return 1; 265 } 266 267 RTThreadSleep(5000); // Sleep for five seconds 268 269 rc = collector->preCollect(hints, 0); 270 if (RT_FAILURE(rc)) 271 { 272 RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc); 273 return 1; 274 } 275 rc = collector->getRawHostDiskLoad(disks.front().c_str(), &diskMsStop, &totalMsStop); 276 if (RT_FAILURE(rc)) 277 { 278 RTPrintf("tstCollector: getRawHostDiskLoad() -> %Rrc\n", rc); 279 return 1; 280 } 281 RTPrintf("tstCollector: host disk util = %llu msec (%u.%u %%), total = %llu msec\n\n", 282 (diskMsStop - diskMsStart), 283 (unsigned)((diskMsStop - diskMsStart) * 100 / (totalMsStop - totalMsStart)), 284 (unsigned)((diskMsStop - diskMsStart) * 10000 / (totalMsStop - totalMsStart) % 100), 285 totalMsStop - totalMsStart); 286 } 283 287 284 288 return 0; … … 289 293 int main(int argc, char *argv[]) 290 294 { 295 bool cpuTest, ramTest, netTest, diskTest, fsTest, perfTest; 296 cpuTest = ramTest = netTest = diskTest = fsTest = perfTest = false; 291 297 /* 292 298 * Initialize the VBox runtime without loading … … 299 305 return 1; 300 306 } 301 if (argc > 1 && !strcmp(argv[1], "-child")) 302 { 303 /* We have spawned ourselves as a child process -- scratch the leg */ 304 RTThreadSleep(1000000); 305 return 1; 306 } 307 if (argc > 1) 308 { 309 if (!strcmp(argv[1], "-child")) 310 { 311 /* We have spawned ourselves as a child process -- scratch the leg */ 312 RTThreadSleep(1000000); 313 return 1; 314 } 315 for (int i = 1; i < argc; i++) 316 { 317 if (!strcmp(argv[i], "-cpu")) 318 cpuTest = true; 319 else if (!strcmp(argv[i], "-ram")) 320 ramTest = true; 321 else if (!strcmp(argv[i], "-net")) 322 netTest = true; 323 else if (!strcmp(argv[i], "-disk")) 324 diskTest = true; 325 else if (!strcmp(argv[i], "-fs")) 326 fsTest = true; 327 else if (!strcmp(argv[i], "-perf")) 328 perfTest = true; 329 else 330 { 331 RTPrintf("tstCollector: Unknown option: %s\n", argv[i]); 332 return 2; 333 } 334 } 335 } 336 else 337 cpuTest = ramTest = netTest = diskTest = fsTest = perfTest = true; 338 307 339 #ifdef RT_OS_WINDOWS 308 340 HRESULT hRes = CoInitialize(NULL); … … 326 358 return 1; 327 359 } 328 #if 1 360 329 361 pm::CollectorHints hints; 330 hints.collectHostCpuLoad(); 331 hints.collectHostRamUsage(); 332 hints.collectProcessCpuLoad(RTProcSelf()); 333 hints.collectProcessRamUsage(RTProcSelf()); 362 if (cpuTest) 363 { 364 hints.collectHostCpuLoad(); 365 hints.collectProcessCpuLoad(RTProcSelf()); 366 } 367 if (ramTest) 368 { 369 hints.collectHostRamUsage(); 370 hints.collectProcessRamUsage(RTProcSelf()); 371 } 334 372 335 373 uint64_t start; … … 341 379 uint64_t processUserStop, processKernelStop, processTotalStop; 342 380 343 RTPrintf("tstCollector: TESTING - CPU load, sleeping for 5 sec\n");344 345 381 rc = collector->preCollect(hints, 0); 346 382 if (RT_FAILURE(rc)) … … 349 385 return 1; 350 386 } 351 rc = collector->getRawHostCpuLoad(&hostUserStart, &hostKernelStart, &hostIdleStart); 352 if (RT_FAILURE(rc)) 353 { 354 RTPrintf("tstCollector: getRawHostCpuLoad() -> %Rrc\n", rc); 355 return 1; 356 } 357 rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStart, &processKernelStart, &processTotalStart); 358 if (RT_FAILURE(rc)) 359 { 360 RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Rrc\n", rc); 361 return 1; 362 } 363 364 RTThreadSleep(5000); // Sleep for 5 seconds 365 366 rc = collector->preCollect(hints, 0); 367 if (RT_FAILURE(rc)) 368 { 369 RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc); 370 return 1; 371 } 372 rc = collector->getRawHostCpuLoad(&hostUserStop, &hostKernelStop, &hostIdleStop); 373 if (RT_FAILURE(rc)) 374 { 375 RTPrintf("tstCollector: getRawHostCpuLoad() -> %Rrc\n", rc); 376 return 1; 377 } 378 rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStop, &processKernelStop, &processTotalStop); 379 if (RT_FAILURE(rc)) 380 { 381 RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Rrc\n", rc); 382 return 1; 383 } 384 hostTotal = hostUserStop - hostUserStart 385 + hostKernelStop - hostKernelStart 386 + hostIdleStop - hostIdleStart; 387 /*printf("tstCollector: host cpu user = %f sec\n", (hostUserStop - hostUserStart) / 10000000.); 388 printf("tstCollector: host cpu kernel = %f sec\n", (hostKernelStop - hostKernelStart) / 10000000.); 389 printf("tstCollector: host cpu idle = %f sec\n", (hostIdleStop - hostIdleStart) / 10000000.); 390 printf("tstCollector: host cpu total = %f sec\n", hostTotal / 10000000.);*/ 391 RTPrintf("tstCollector: host cpu user = %u.%u %%\n", 392 (unsigned)((hostUserStop - hostUserStart) * 100 / hostTotal), 393 (unsigned)((hostUserStop - hostUserStart) * 10000 / hostTotal % 100)); 394 RTPrintf("tstCollector: host cpu kernel = %u.%u %%\n", 395 (unsigned)((hostKernelStop - hostKernelStart) * 100 / hostTotal), 396 (unsigned)((hostKernelStop - hostKernelStart) * 10000 / hostTotal % 100)); 397 RTPrintf("tstCollector: host cpu idle = %u.%u %%\n", 398 (unsigned)((hostIdleStop - hostIdleStart) * 100 / hostTotal), 399 (unsigned)((hostIdleStop - hostIdleStart) * 10000 / hostTotal % 100)); 400 RTPrintf("tstCollector: process cpu user = %u.%u %%\n", 401 (unsigned)((processUserStop - processUserStart) * 100 / (processTotalStop - processTotalStart)), 402 (unsigned)((processUserStop - processUserStart) * 10000 / (processTotalStop - processTotalStart) % 100)); 403 RTPrintf("tstCollector: process cpu kernel = %u.%u %%\n\n", 404 (unsigned)((processKernelStop - processKernelStart) * 100 / (processTotalStop - processTotalStart)), 405 (unsigned)((processKernelStop - processKernelStart) * 10000 / (processTotalStop - processTotalStart) % 100)); 406 407 RTPrintf("tstCollector: TESTING - CPU load, looping for 5 sec\n"); 408 rc = collector->preCollect(hints, 0); 409 if (RT_FAILURE(rc)) 410 { 411 RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc); 412 return 1; 413 } 414 rc = collector->getRawHostCpuLoad(&hostUserStart, &hostKernelStart, &hostIdleStart); 415 if (RT_FAILURE(rc)) 416 { 417 RTPrintf("tstCollector: getRawHostCpuLoad() -> %Rrc\n", rc); 418 return 1; 419 } 420 rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStart, &processKernelStart, &processTotalStart); 421 if (RT_FAILURE(rc)) 422 { 423 RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Rrc\n", rc); 424 return 1; 425 } 426 start = RTTimeMilliTS(); 427 while(RTTimeMilliTS() - start < 5000) 428 ; // Loop for 5 seconds 429 rc = collector->preCollect(hints, 0); 430 if (RT_FAILURE(rc)) 431 { 432 RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc); 433 return 1; 434 } 435 rc = collector->getRawHostCpuLoad(&hostUserStop, &hostKernelStop, &hostIdleStop); 436 if (RT_FAILURE(rc)) 437 { 438 RTPrintf("tstCollector: getRawHostCpuLoad() -> %Rrc\n", rc); 439 return 1; 440 } 441 rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStop, &processKernelStop, &processTotalStop); 442 if (RT_FAILURE(rc)) 443 { 444 RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Rrc\n", rc); 445 return 1; 446 } 447 hostTotal = hostUserStop - hostUserStart 448 + hostKernelStop - hostKernelStart 449 + hostIdleStop - hostIdleStart; 450 RTPrintf("tstCollector: host cpu user = %u.%u %%\n", 451 (unsigned)((hostUserStop - hostUserStart) * 100 / hostTotal), 452 (unsigned)((hostUserStop - hostUserStart) * 10000 / hostTotal % 100)); 453 RTPrintf("tstCollector: host cpu kernel = %u.%u %%\n", 454 (unsigned)((hostKernelStop - hostKernelStart) * 100 / hostTotal), 455 (unsigned)((hostKernelStop - hostKernelStart) * 10000 / hostTotal % 100)); 456 RTPrintf("tstCollector: host cpu idle = %u.%u %%\n", 457 (unsigned)((hostIdleStop - hostIdleStart) * 100 / hostTotal), 458 (unsigned)((hostIdleStop - hostIdleStart) * 10000 / hostTotal % 100)); 459 RTPrintf("tstCollector: process cpu user = %u.%u %%\n", 460 (unsigned)((processUserStop - processUserStart) * 100 / (processTotalStop - processTotalStart)), 461 (unsigned)((processUserStop - processUserStart) * 10000 / (processTotalStop - processTotalStart) % 100)); 462 RTPrintf("tstCollector: process cpu kernel = %u.%u %%\n\n", 463 (unsigned)((processKernelStop - processKernelStart) * 100 / (processTotalStop - processTotalStart)), 464 (unsigned)((processKernelStop - processKernelStart) * 10000 / (processTotalStop - processTotalStart) % 100)); 465 466 RTPrintf("tstCollector: TESTING - Memory usage\n"); 467 468 ULONG total, used, available, processUsed; 469 470 rc = collector->getHostMemoryUsage(&total, &used, &available); 471 if (RT_FAILURE(rc)) 472 { 473 RTPrintf("tstCollector: getHostMemoryUsage() -> %Rrc\n", rc); 474 return 1; 475 } 476 rc = collector->getProcessMemoryUsage(RTProcSelf(), &processUsed); 477 if (RT_FAILURE(rc)) 478 { 479 RTPrintf("tstCollector: getProcessMemoryUsage() -> %Rrc\n", rc); 480 return 1; 481 } 482 RTPrintf("tstCollector: host mem total = %lu kB\n", total); 483 RTPrintf("tstCollector: host mem used = %lu kB\n", used); 484 RTPrintf("tstCollector: host mem available = %lu kB\n", available); 485 RTPrintf("tstCollector: process mem used = %lu kB\n\n", processUsed); 486 #endif 487 #if 1 488 rc = testNetwork(collector); 489 #endif 490 #if 1 387 if (cpuTest) 388 { 389 RTPrintf("tstCollector: TESTING - CPU load, sleeping for 5 sec\n"); 390 391 rc = collector->getRawHostCpuLoad(&hostUserStart, &hostKernelStart, &hostIdleStart); 392 if (RT_FAILURE(rc)) 393 { 394 RTPrintf("tstCollector: getRawHostCpuLoad() -> %Rrc\n", rc); 395 return 1; 396 } 397 rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStart, &processKernelStart, &processTotalStart); 398 if (RT_FAILURE(rc)) 399 { 400 RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Rrc\n", rc); 401 return 1; 402 } 403 404 RTThreadSleep(5000); // Sleep for 5 seconds 405 406 rc = collector->preCollect(hints, 0); 407 if (RT_FAILURE(rc)) 408 { 409 RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc); 410 return 1; 411 } 412 rc = collector->getRawHostCpuLoad(&hostUserStop, &hostKernelStop, &hostIdleStop); 413 if (RT_FAILURE(rc)) 414 { 415 RTPrintf("tstCollector: getRawHostCpuLoad() -> %Rrc\n", rc); 416 return 1; 417 } 418 rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStop, &processKernelStop, &processTotalStop); 419 if (RT_FAILURE(rc)) 420 { 421 RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Rrc\n", rc); 422 return 1; 423 } 424 hostTotal = hostUserStop - hostUserStart 425 + hostKernelStop - hostKernelStart 426 + hostIdleStop - hostIdleStart; 427 RTPrintf("tstCollector: host cpu user = %u.%u %%\n", 428 (unsigned)((hostUserStop - hostUserStart) * 100 / hostTotal), 429 (unsigned)((hostUserStop - hostUserStart) * 10000 / hostTotal % 100)); 430 RTPrintf("tstCollector: host cpu kernel = %u.%u %%\n", 431 (unsigned)((hostKernelStop - hostKernelStart) * 100 / hostTotal), 432 (unsigned)((hostKernelStop - hostKernelStart) * 10000 / hostTotal % 100)); 433 RTPrintf("tstCollector: host cpu idle = %u.%u %%\n", 434 (unsigned)((hostIdleStop - hostIdleStart) * 100 / hostTotal), 435 (unsigned)((hostIdleStop - hostIdleStart) * 10000 / hostTotal % 100)); 436 RTPrintf("tstCollector: process cpu user = %u.%u %%\n", 437 (unsigned)((processUserStop - processUserStart) * 100 / (processTotalStop - processTotalStart)), 438 (unsigned)((processUserStop - processUserStart) * 10000 / (processTotalStop - processTotalStart) % 100)); 439 RTPrintf("tstCollector: process cpu kernel = %u.%u %%\n\n", 440 (unsigned)((processKernelStop - processKernelStart) * 100 / (processTotalStop - processTotalStart)), 441 (unsigned)((processKernelStop - processKernelStart) * 10000 / (processTotalStop - processTotalStart) % 100)); 442 443 RTPrintf("tstCollector: TESTING - CPU load, looping for 5 sec\n"); 444 rc = collector->preCollect(hints, 0); 445 if (RT_FAILURE(rc)) 446 { 447 RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc); 448 return 1; 449 } 450 rc = collector->getRawHostCpuLoad(&hostUserStart, &hostKernelStart, &hostIdleStart); 451 if (RT_FAILURE(rc)) 452 { 453 RTPrintf("tstCollector: getRawHostCpuLoad() -> %Rrc\n", rc); 454 return 1; 455 } 456 rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStart, &processKernelStart, &processTotalStart); 457 if (RT_FAILURE(rc)) 458 { 459 RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Rrc\n", rc); 460 return 1; 461 } 462 start = RTTimeMilliTS(); 463 while(RTTimeMilliTS() - start < 5000) 464 ; // Loop for 5 seconds 465 rc = collector->preCollect(hints, 0); 466 if (RT_FAILURE(rc)) 467 { 468 RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc); 469 return 1; 470 } 471 rc = collector->getRawHostCpuLoad(&hostUserStop, &hostKernelStop, &hostIdleStop); 472 if (RT_FAILURE(rc)) 473 { 474 RTPrintf("tstCollector: getRawHostCpuLoad() -> %Rrc\n", rc); 475 return 1; 476 } 477 rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStop, &processKernelStop, &processTotalStop); 478 if (RT_FAILURE(rc)) 479 { 480 RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Rrc\n", rc); 481 return 1; 482 } 483 hostTotal = hostUserStop - hostUserStart 484 + hostKernelStop - hostKernelStart 485 + hostIdleStop - hostIdleStart; 486 RTPrintf("tstCollector: host cpu user = %u.%u %%\n", 487 (unsigned)((hostUserStop - hostUserStart) * 100 / hostTotal), 488 (unsigned)((hostUserStop - hostUserStart) * 10000 / hostTotal % 100)); 489 RTPrintf("tstCollector: host cpu kernel = %u.%u %%\n", 490 (unsigned)((hostKernelStop - hostKernelStart) * 100 / hostTotal), 491 (unsigned)((hostKernelStop - hostKernelStart) * 10000 / hostTotal % 100)); 492 RTPrintf("tstCollector: host cpu idle = %u.%u %%\n", 493 (unsigned)((hostIdleStop - hostIdleStart) * 100 / hostTotal), 494 (unsigned)((hostIdleStop - hostIdleStart) * 10000 / hostTotal % 100)); 495 RTPrintf("tstCollector: process cpu user = %u.%u %%\n", 496 (unsigned)((processUserStop - processUserStart) * 100 / (processTotalStop - processTotalStart)), 497 (unsigned)((processUserStop - processUserStart) * 10000 / (processTotalStop - processTotalStart) % 100)); 498 RTPrintf("tstCollector: process cpu kernel = %u.%u %%\n\n", 499 (unsigned)((processKernelStop - processKernelStart) * 100 / (processTotalStop - processTotalStart)), 500 (unsigned)((processKernelStop - processKernelStart) * 10000 / (processTotalStop - processTotalStart) % 100)); 501 } 502 503 if (ramTest) 504 { 505 RTPrintf("tstCollector: TESTING - Memory usage\n"); 506 507 ULONG total, used, available, processUsed; 508 509 rc = collector->getHostMemoryUsage(&total, &used, &available); 510 if (RT_FAILURE(rc)) 511 { 512 RTPrintf("tstCollector: getHostMemoryUsage() -> %Rrc\n", rc); 513 return 1; 514 } 515 rc = collector->getProcessMemoryUsage(RTProcSelf(), &processUsed); 516 if (RT_FAILURE(rc)) 517 { 518 RTPrintf("tstCollector: getProcessMemoryUsage() -> %Rrc\n", rc); 519 return 1; 520 } 521 RTPrintf("tstCollector: host mem total = %lu kB\n", total); 522 RTPrintf("tstCollector: host mem used = %lu kB\n", used); 523 RTPrintf("tstCollector: host mem available = %lu kB\n", available); 524 RTPrintf("tstCollector: process mem used = %lu kB\n\n", processUsed); 525 } 526 527 if (netTest) 528 rc = testNetwork(collector); 529 if (fsTest) 491 530 rc = testFsUsage(collector); 492 #endif 493 #if 1 494 rc = testDisk(collector); 495 #endif 496 #if 1 497 RTPrintf("tstCollector: TESTING - Performance\n\n"); 498 499 measurePerformance(collector, argv[0], 100); 500 #endif 531 if (diskTest) 532 rc = testDisk(collector); 533 if (perfTest) 534 { 535 RTPrintf("tstCollector: TESTING - Performance\n\n"); 536 537 measurePerformance(collector, argv[0], 100); 538 } 501 539 502 540 delete collector;
Note:
See TracChangeset
for help on using the changeset viewer.