home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / SWPTST.ZIP / SWAPTST2.C < prev    next >
Text File  |  1993-02-15  |  7KB  |  151 lines

  1. /*
  2.     Swap Test 2
  3.  
  4.     1.  Allocate a block of memory of one or more MB.
  5.     2.  Update each 4K page in one or more 256KB blocks a specified number
  6.         of times; measure the time this takes.  Display the results along with
  7.         the current size of the swap file.
  8.     3.  Repeat the previous step, each time extending the updates by one more
  9.         over the range of 256KB blocks.  Stop if the time is greater than the 
  10.         limit or if the swap file grows.
  11.  
  12.     Parameters:
  13.  
  14.         cmbMemBlk:  The size of the memory block in MB.  It should be large
  15.                     enough to cause a little swapping on your OS/2 system.
  16.                     Default is 6MB.
  17.         cUpdates:   The number of updates to each page each pass of the loop.
  18.                     Default is 1.
  19.         cTimeLim:   If one pass through the loop exceeds this time limit (ms),
  20.                     the loop breaks out.  Default is 200 ms (safe on most
  21.                     systems??).  (You can also stop it with Ctrl-C.)
  22.         pszSwapper: The path to the swap file.  The default is
  23.                     C:\OS2\SYSTEM\SWAPPER.DAT.
  24.  
  25.     There's little or no error checking on input parameter values.
  26.  
  27.     Output is via printf() to stdout.  It's useful to redirect it to a file for
  28.     later review.
  29.  
  30.     This program is in the public domain.  Anyone using it assumes all
  31.     responsibility for consequences; the author will not be liable for
  32.     anything.  (Don't run it on a system where the response time of other
  33.     applications is important!!)
  34.  
  35.     Author: Bill Lee, Edmonton, Alberta, Canada; CompuServe 70441,2372.
  36. */
  37.  
  38.  
  39. #define INCL_DOSFILEMGR         // File Manager values
  40. #define INCL_DOSMEMMGR          // Memory Manager values
  41. #define INCL_DOSMISC            // QSV_MAX_.... values
  42. #include <os2.h>
  43. #include <stdio.h>
  44.  
  45. #define IFERR( f ) if ( lRC = ( f ) ) \
  46.     { printf( "Stopping at source line %d due to API error code %ld.\n", \
  47.     __LINE__, lRC ); exit( lRC ); }
  48.  
  49. int main( USHORT argc, PCHAR argv[] )
  50. {
  51.  
  52.     ULONG cmbMemBlk = 6;                // input parameter with default
  53.     ULONG cUpdates = 1;                 // input parameter with default
  54.     ULONG cTimeLim = 200;               // time limit (ms), 1 pass thru loop
  55.     #define MAXPARM 3                   // max number of parms
  56.     ULONG alParm[MAXPARM] = { 0,0,0 };  // work area for input parameters
  57.     ULONG cbTotPhysMem;                 // total physical memory
  58.     ULONG cTime1, cTime2;
  59.     PULONG pBlk;                        // ptr to block
  60.     ULONG flAllocation = PAG_WRITE | PAG_READ | PAG_COMMIT;
  61.     ULONG i, j, k;                      // indexes
  62.     APIRET lRC;                         // return code
  63.     PUCHAR pszSwapper = "C:\\OS2\\SYSTEM\\SWAPPER.DAT";
  64.     ULONG ulSwapperPathInfo = FIL_STANDARD;
  65.     FILESTATUS3 fs3SwapperInfoBuf;      // for DosQueryPathInfo of SWAPPER.DAT
  66.     ULONG cbFileAlloc1;                 // initial size of SWAPPER.DAT
  67.  
  68.     printf( "\nSwap Test 2:\n\n" );
  69.  
  70.     //  Get and display total physical memeory.
  71.     IFERR( DosQuerySysInfo( QSV_TOTPHYSMEM, QSV_TOTPHYSMEM,
  72.                                        &cbTotPhysMem, sizeof(cbTotPhysMem) ) );
  73.     printf( "Total physical memory is %ld bytes (%ldMB + %ldKB).\n\n",
  74.             cbTotPhysMem, cbTotPhysMem/(1024*1024),
  75.             cbTotPhysMem%(1024*1024)/1024 );
  76.  
  77.     // scan all the input parameters and save values into array.
  78.     for ( i = 1; i < argc && i <= MAXPARM; ++i ) {
  79.         alParm[i-1] = atol( argv[i] );
  80.     }
  81.     if ( argc > 4 )
  82.         pszSwapper = argv[4];
  83.  
  84.     // copy parms from array to variables if non-0.
  85.     if ( alParm[0] )
  86.         cmbMemBlk = alParm[0];
  87.     if ( alParm[1] )
  88.         cUpdates = alParm[1];
  89.     if ( alParm[2] )
  90.         cTimeLim = alParm[2];
  91.  
  92.     //  Display input parameters, specified or defaulted.
  93.     printf( "The memory block allocated for this test will be %ldMB.\n\n",
  94.             cmbMemBlk );
  95.     printf( "Each 4KB page in some multiple of 256KB of this block is "
  96.             "updated %ld times\non each pass; it starts with 256KB and "
  97.             "adds 256KB on each pass.\n\n", cUpdates );
  98.     printf( "It ends early if a pass takes longer than %ld ms "
  99.             "or if the swap file grows.\n\n", cTimeLim );
  100.  
  101.     printf( "Swap file path is \"%s\".\n\n", pszSwapper );
  102.  
  103.     //  Get initial size of SWAPPER.DAT and save it.
  104.     IFERR( DosQueryPathInfo( pszSwapper, FIL_STANDARD, &fs3SwapperInfoBuf,
  105.                                                  sizeof(fs3SwapperInfoBuf) ) );
  106.     cbFileAlloc1 = fs3SwapperInfoBuf.cbFileAlloc;       // save initial size
  107.  
  108.     IFERR( DosAllocMem( (PPVOID) &pBlk, cmbMemBlk*1024*1024, flAllocation ) );
  109.  
  110.     printf( "----updated area-----  time  Swap\n" );    // header 1
  111.     printf( "pass  MB +  KB  updts  (ms)  (KB)\n" );    // header 2
  112.  
  113.     for ( i = 1; i <= cmbMemBlk*4; ++i ) {              // no. of 256KB passes
  114.  
  115.         //  Millisecond count at start of inner loop.
  116.         IFERR( DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT,
  117.                                                  &cTime1, sizeof(&cTime1) ) );
  118.  
  119.         for ( j = 0; j < cUpdates; ++j )                // all the run-throughs
  120.             for ( k = 0; k < i*256*1024/4; k += 1024 )  // each 4K page
  121.                 *( pBlk + k ) = k;                      // update the 4K page
  122.  
  123.         //  Find out how long this loop took.
  124.         IFERR( DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT,
  125.                                                   &cTime2, sizeof(&cTime2) ) );
  126.         cTime2 -= cTime1;
  127.  
  128.         //  Find out how big SWAPPER.DAT is.
  129.         IFERR( DosQueryPathInfo( pszSwapper, FIL_STANDARD, &fs3SwapperInfoBuf,
  130.                                                  sizeof(fs3SwapperInfoBuf) ) );
  131.  
  132.         printf( "%4ld%4ld + %3ld%7ld%6ld%6ld\n",
  133.                 i, i/4, i%4*256, i*256/4*cUpdates,
  134.                 cTime2, fs3SwapperInfoBuf.cbFileAlloc/1024 );
  135.  
  136.         if ( cTime2 > cTimeLim ) {
  137.             printf( "\nPass time (%ld ms) exceeds limit (%ld ms), stopping.\n",
  138.                                                             cTime2, cTimeLim );
  139.             break;
  140.         }
  141.  
  142.         if ( fs3SwapperInfoBuf.cbFileAlloc > cbFileAlloc1 ) {
  143.             printf( "\nThe swap file grew from %ldKB to %ldKB, stopping.\n",
  144.                     cbFileAlloc1, fs3SwapperInfoBuf.cbFileAlloc );
  145.             break;
  146.         }
  147.  
  148.     }   //  for ( i = 1; ... )
  149.  
  150. }   //  main()
  151.