Changeset 40709 in vbox
- Timestamp:
- Mar 29, 2012 2:16:21 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/testcase/tstVDIo.cpp
r40628 r40709 53 53 /** Flag whether the file is write locked. */ 54 54 bool fWriteLock; 55 /** Statistics: Number of reads. */ 56 unsigned cReads; 57 /** Statistics: Number of writes. */ 58 unsigned cWrites; 59 /** Statistics: Number of flushes. */ 60 unsigned cFlushes; 61 /** Statistics: Number of async reads. */ 62 unsigned cAsyncReads; 63 /** Statistics: Number of async writes. */ 64 unsigned cAsyncWrites; 65 /** Statistics: Number of async flushes. */ 66 unsigned cAsyncFlushes; 55 67 } VDFILE, *PVDFILE; 56 68 … … 315 327 static DECLCALLBACK(int) vdScriptHandlerDumpDiskInfo(PVDTESTGLOB pGlob, PVDSCRIPTARG paScriptArgs, unsigned cScriptArgs); 316 328 static DECLCALLBACK(int) vdScriptHandlerPrintMsg(PVDTESTGLOB pGlob, PVDSCRIPTARG paScriptArgs, unsigned cScriptArgs); 329 static DECLCALLBACK(int) vdScriptHandlerShowStatistics(PVDTESTGLOB pGlob, PVDSCRIPTARG paScriptArgs, unsigned cScriptArgs); 330 static DECLCALLBACK(int) vdScriptHandlerResetStatistics(PVDTESTGLOB pGlob, PVDSCRIPTARG paScriptArgs, unsigned cScriptArgs); 317 331 318 332 /* create action */ … … 320 334 { 321 335 /* pcszName chId enmType fFlags */ 322 {"disk", 'd', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 323 {"mode", 'm', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 324 {"name", 'n', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 325 {"type", 't', VDSCRIPTARGTYPE_STRING, 0}, 326 {"backend", 'b', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 327 {"size", 's', VDSCRIPTARGTYPE_UNSIGNED_NUMBER, VDSCRIPTARGDESC_FLAG_MANDATORY | VDSCRIPTARGDESC_FLAG_SIZE_SUFFIX} 336 {"disk", 'd', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 337 {"mode", 'm', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 338 {"name", 'n', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 339 {"type", 't', VDSCRIPTARGTYPE_STRING, 0}, 340 {"backend", 'b', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 341 {"size", 's', VDSCRIPTARGTYPE_UNSIGNED_NUMBER, VDSCRIPTARGDESC_FLAG_MANDATORY | VDSCRIPTARGDESC_FLAG_SIZE_SUFFIX}, 342 {"ignoreflush", 'f', VDSCRIPTARGTYPE_BOOL, 0} 328 343 }; 329 344 … … 332 347 { 333 348 /* pcszName chId enmType fFlags */ 334 {"disk", 'd', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 335 {"name", 'n', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 336 {"backend", 'b', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 337 {"async", 'a', VDSCRIPTARGTYPE_BOOL, 0}, 338 {"shareable", 's', VDSCRIPTARGTYPE_BOOL, 0}, 339 {"readonly", 'r', VDSCRIPTARGTYPE_BOOL, 0}, 340 {"discard", 'i', VDSCRIPTARGTYPE_BOOL, 0}, 349 {"disk", 'd', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 350 {"name", 'n', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 351 {"backend", 'b', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 352 {"async", 'a', VDSCRIPTARGTYPE_BOOL, 0}, 353 {"shareable", 's', VDSCRIPTARGTYPE_BOOL, 0}, 354 {"readonly", 'r', VDSCRIPTARGTYPE_BOOL, 0}, 355 {"discard", 'i', VDSCRIPTARGTYPE_BOOL, 0}, 356 {"ignoreflush", 'f', VDSCRIPTARGTYPE_BOOL, 0}, 341 357 }; 342 358 … … 513 529 /* pcszName chId enmType fFlags */ 514 530 {"msg", 'm', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 531 }; 532 533 /* Show statistics */ 534 const VDSCRIPTARGDESC g_aArgShowStatistics[] = 535 { 536 /* pcszName chId enmType fFlags */ 537 {"file", 'f', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 538 }; 539 540 /* Reset statistics */ 541 const VDSCRIPTARGDESC g_aArgResetStatistics[] = 542 { 543 /* pcszName chId enmType fFlags */ 544 {"file", 'f', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 515 545 }; 516 546 … … 540 570 {"comparedisks", g_aArgCompareDisks, RT_ELEMENTS(g_aArgCompareDisks), vdScriptHandlerCompareDisks}, 541 571 {"dumpdiskinfo", g_aArgDumpDiskInfo, RT_ELEMENTS(g_aArgDumpDiskInfo), vdScriptHandlerDumpDiskInfo}, 542 {"print", g_aArgPrintMsg, RT_ELEMENTS(g_aArgPrintMsg), vdScriptHandlerPrintMsg} 572 {"print", g_aArgPrintMsg, RT_ELEMENTS(g_aArgPrintMsg), vdScriptHandlerPrintMsg}, 573 {"showstatistics", g_aArgShowStatistics, RT_ELEMENTS(g_aArgShowStatistics), vdScriptHandlerShowStatistics}, 574 {"resetstatistics", g_aArgResetStatistics, RT_ELEMENTS(g_aArgResetStatistics), vdScriptHandlerResetStatistics} 543 575 }; 544 576 … … 584 616 bool fBase = false; 585 617 bool fDynamic = true; 618 bool fIgnoreFlush = false; 586 619 587 620 for (unsigned i = 0; i < cScriptArgs; i++) … … 635 668 break; 636 669 } 670 case 'f': 671 { 672 fIgnoreFlush = true; 673 break; 674 } 637 675 default: 638 676 AssertMsgFailed(("Invalid argument given!\n")); … … 648 686 if (pDisk) 649 687 { 688 unsigned fOpenFlags = VD_OPEN_FLAGS_ASYNC_IO; 650 689 unsigned fImageFlags = VD_IMAGE_FLAGS_NONE; 651 690 652 691 if (!fDynamic) 653 692 fImageFlags |= VD_IMAGE_FLAGS_FIXED; 693 694 if (fIgnoreFlush) 695 fOpenFlags |= VD_OPEN_FLAGS_IGNORE_FLUSH; 654 696 655 697 if (fBase) 656 698 rc = VDCreateBase(pDisk->pVD, pcszBackend, pcszImage, cbSize, fImageFlags, NULL, 657 699 &pDisk->PhysGeom, &pDisk->LogicalGeom, 658 NULL, VD_OPEN_FLAGS_ASYNC_IO, pGlob->pInterfacesImages, NULL);700 NULL, fOpenFlags, pGlob->pInterfacesImages, NULL); 659 701 else 660 702 rc = VDCreateDiff(pDisk->pVD, pcszBackend, pcszImage, fImageFlags, NULL, NULL, NULL, VD_OPEN_FLAGS_ASYNC_IO, … … 679 721 bool fAsyncIo = true; 680 722 bool fDiscard = false; 723 bool fIgnoreFlush = false; 681 724 682 725 for (unsigned i = 0; i < cScriptArgs; i++) … … 742 785 if (fDiscard) 743 786 fOpenFlags |= VD_OPEN_FLAGS_DISCARD; 787 if (fIgnoreFlush) 788 fOpenFlags |= VD_OPEN_FLAGS_IGNORE_FLUSH; 744 789 745 790 rc = VDOpen(pDisk->pVD, pcszBackend, pcszImage, fOpenFlags, pGlob->pInterfacesImages); … … 2412 2457 } 2413 2458 2459 static DECLCALLBACK(int) vdScriptHandlerShowStatistics(PVDTESTGLOB pGlob, PVDSCRIPTARG paScriptArgs, unsigned cScriptArgs) 2460 { 2461 int rc = VINF_SUCCESS; 2462 const char *pcszFile = NULL; 2463 2464 for (unsigned i = 0; i < cScriptArgs; i++) 2465 { 2466 switch (paScriptArgs[i].chId) 2467 { 2468 case 'f': 2469 { 2470 pcszFile = paScriptArgs[i].u.pcszString; 2471 break; 2472 } 2473 default: 2474 AssertMsgFailed(("Invalid argument given!\n")); 2475 } 2476 } 2477 2478 /* Check for the file. */ 2479 PVDFILE pIt = NULL; 2480 bool fFound = false; 2481 RTListForEach(&pGlob->ListFiles, pIt, VDFILE, Node) 2482 { 2483 if (!RTStrCmp(pIt->pszName, pcszFile)) 2484 { 2485 fFound = true; 2486 break; 2487 } 2488 } 2489 2490 if (fFound) 2491 { 2492 RTPrintf("Statistics %s: \n" 2493 " sync reads=%u writes=%u flushes=%u\n" 2494 " async reads=%u writes=%u flushes=%u\n", 2495 pcszFile, 2496 pIt->cReads, pIt->cWrites, pIt->cFlushes, 2497 pIt->cAsyncReads, pIt->cAsyncWrites, pIt->cAsyncFlushes); 2498 } 2499 else 2500 rc = VERR_FILE_NOT_FOUND; 2501 2502 return rc; 2503 } 2504 2505 static DECLCALLBACK(int) vdScriptHandlerResetStatistics(PVDTESTGLOB pGlob, PVDSCRIPTARG paScriptArgs, unsigned cScriptArgs) 2506 { 2507 int rc = VINF_SUCCESS; 2508 const char *pcszFile = NULL; 2509 2510 for (unsigned i = 0; i < cScriptArgs; i++) 2511 { 2512 switch (paScriptArgs[i].chId) 2513 { 2514 case 'f': 2515 { 2516 pcszFile = paScriptArgs[i].u.pcszString; 2517 break; 2518 } 2519 default: 2520 AssertMsgFailed(("Invalid argument given!\n")); 2521 } 2522 } 2523 2524 /* Check for the file. */ 2525 PVDFILE pIt = NULL; 2526 bool fFound = false; 2527 RTListForEach(&pGlob->ListFiles, pIt, VDFILE, Node) 2528 { 2529 if (!RTStrCmp(pIt->pszName, pcszFile)) 2530 { 2531 fFound = true; 2532 break; 2533 } 2534 } 2535 2536 if (fFound) 2537 { 2538 pIt->cReads = 0; 2539 pIt->cWrites = 0; 2540 pIt->cFlushes = 0; 2541 2542 pIt->cAsyncReads = 0; 2543 pIt->cAsyncWrites = 0; 2544 pIt->cAsyncFlushes = 0; 2545 } 2546 else 2547 rc = VERR_FILE_NOT_FOUND; 2548 2549 return rc; 2550 } 2551 2414 2552 static DECLCALLBACK(int) tstVDIoFileOpen(void *pvUser, const char *pszLocation, 2415 2553 uint32_t fOpen, … … 2624 2762 rc = VDMemDiskWrite(pIoStorage->pFile->pMemDisk, uOffset, cbBuffer, &SgBuf); 2625 2763 if (RT_SUCCESS(rc) && pcbWritten) 2764 { 2765 pIoStorage->pFile->cWrites++; 2626 2766 *pcbWritten = cbBuffer; 2767 } 2627 2768 2628 2769 return rc; … … 2643 2784 rc = VDMemDiskRead(pIoStorage->pFile->pMemDisk, uOffset, cbBuffer, &SgBuf); 2644 2785 if (RT_SUCCESS(rc) && pcbRead) 2786 { 2787 pIoStorage->pFile->cReads++; 2645 2788 *pcbRead = cbBuffer; 2789 } 2646 2790 2647 2791 return rc; … … 2650 2794 static DECLCALLBACK(int) tstVDIoFileFlushSync(void *pvUser, void *pStorage) 2651 2795 { 2652 /* nothing to do. */ 2796 PVDSTORAGE pIoStorage = (PVDSTORAGE)pStorage; 2797 pIoStorage->pFile->cFlushes++; 2653 2798 return VINF_SUCCESS; 2654 2799 } … … 2666 2811 cbRead, paSegments, cSegments, pIoStorage->pfnComplete, pvCompletion); 2667 2812 if (RT_SUCCESS(rc)) 2813 { 2814 pIoStorage->pFile->cAsyncReads++; 2668 2815 rc = VERR_VD_ASYNC_IO_IN_PROGRESS; 2816 } 2669 2817 2670 2818 return rc; … … 2683 2831 cbWrite, paSegments, cSegments, pIoStorage->pfnComplete, pvCompletion); 2684 2832 if (RT_SUCCESS(rc)) 2833 { 2834 pIoStorage->pFile->cAsyncWrites++; 2685 2835 rc = VERR_VD_ASYNC_IO_IN_PROGRESS; 2836 } 2686 2837 2687 2838 return rc; … … 2698 2849 0, NULL, 0, pIoStorage->pfnComplete, pvCompletion); 2699 2850 if (RT_SUCCESS(rc)) 2851 { 2852 pIoStorage->pFile->cAsyncFlushes++; 2700 2853 rc = VERR_VD_ASYNC_IO_IN_PROGRESS; 2854 } 2701 2855 2702 2856 return rc; … … 2826 2980 2827 2981 Assert(idx != -1); 2828 pIoReq->off = idx * pIoTest->cbBlkIo;2982 pIoReq->off = (uint64_t)idx * pIoTest->cbBlkIo; 2829 2983 pIoTest->u.Rnd.cBlocksLeft--; 2830 2984 if (!pIoTest->u.Rnd.cBlocksLeft)
Note:
See TracChangeset
for help on using the changeset viewer.