home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 8 Other
/
08-Other.zip
/
SWPTST.ZIP
/
SWAPTST2.C
< prev
next >
Wrap
Text File
|
1993-02-15
|
7KB
|
151 lines
/*
Swap Test 2
1. Allocate a block of memory of one or more MB.
2. Update each 4K page in one or more 256KB blocks a specified number
of times; measure the time this takes. Display the results along with
the current size of the swap file.
3. Repeat the previous step, each time extending the updates by one more
over the range of 256KB blocks. Stop if the time is greater than the
limit or if the swap file grows.
Parameters:
cmbMemBlk: The size of the memory block in MB. It should be large
enough to cause a little swapping on your OS/2 system.
Default is 6MB.
cUpdates: The number of updates to each page each pass of the loop.
Default is 1.
cTimeLim: If one pass through the loop exceeds this time limit (ms),
the loop breaks out. Default is 200 ms (safe on most
systems??). (You can also stop it with Ctrl-C.)
pszSwapper: The path to the swap file. The default is
C:\OS2\SYSTEM\SWAPPER.DAT.
There's little or no error checking on input parameter values.
Output is via printf() to stdout. It's useful to redirect it to a file for
later review.
This program is in the public domain. Anyone using it assumes all
responsibility for consequences; the author will not be liable for
anything. (Don't run it on a system where the response time of other
applications is important!!)
Author: Bill Lee, Edmonton, Alberta, Canada; CompuServe 70441,2372.
*/
#define INCL_DOSFILEMGR // File Manager values
#define INCL_DOSMEMMGR // Memory Manager values
#define INCL_DOSMISC // QSV_MAX_.... values
#include <os2.h>
#include <stdio.h>
#define IFERR( f ) if ( lRC = ( f ) ) \
{ printf( "Stopping at source line %d due to API error code %ld.\n", \
__LINE__, lRC ); exit( lRC ); }
int main( USHORT argc, PCHAR argv[] )
{
ULONG cmbMemBlk = 6; // input parameter with default
ULONG cUpdates = 1; // input parameter with default
ULONG cTimeLim = 200; // time limit (ms), 1 pass thru loop
#define MAXPARM 3 // max number of parms
ULONG alParm[MAXPARM] = { 0,0,0 }; // work area for input parameters
ULONG cbTotPhysMem; // total physical memory
ULONG cTime1, cTime2;
PULONG pBlk; // ptr to block
ULONG flAllocation = PAG_WRITE | PAG_READ | PAG_COMMIT;
ULONG i, j, k; // indexes
APIRET lRC; // return code
PUCHAR pszSwapper = "C:\\OS2\\SYSTEM\\SWAPPER.DAT";
ULONG ulSwapperPathInfo = FIL_STANDARD;
FILESTATUS3 fs3SwapperInfoBuf; // for DosQueryPathInfo of SWAPPER.DAT
ULONG cbFileAlloc1; // initial size of SWAPPER.DAT
printf( "\nSwap Test 2:\n\n" );
// Get and display total physical memeory.
IFERR( DosQuerySysInfo( QSV_TOTPHYSMEM, QSV_TOTPHYSMEM,
&cbTotPhysMem, sizeof(cbTotPhysMem) ) );
printf( "Total physical memory is %ld bytes (%ldMB + %ldKB).\n\n",
cbTotPhysMem, cbTotPhysMem/(1024*1024),
cbTotPhysMem%(1024*1024)/1024 );
// scan all the input parameters and save values into array.
for ( i = 1; i < argc && i <= MAXPARM; ++i ) {
alParm[i-1] = atol( argv[i] );
}
if ( argc > 4 )
pszSwapper = argv[4];
// copy parms from array to variables if non-0.
if ( alParm[0] )
cmbMemBlk = alParm[0];
if ( alParm[1] )
cUpdates = alParm[1];
if ( alParm[2] )
cTimeLim = alParm[2];
// Display input parameters, specified or defaulted.
printf( "The memory block allocated for this test will be %ldMB.\n\n",
cmbMemBlk );
printf( "Each 4KB page in some multiple of 256KB of this block is "
"updated %ld times\non each pass; it starts with 256KB and "
"adds 256KB on each pass.\n\n", cUpdates );
printf( "It ends early if a pass takes longer than %ld ms "
"or if the swap file grows.\n\n", cTimeLim );
printf( "Swap file path is \"%s\".\n\n", pszSwapper );
// Get initial size of SWAPPER.DAT and save it.
IFERR( DosQueryPathInfo( pszSwapper, FIL_STANDARD, &fs3SwapperInfoBuf,
sizeof(fs3SwapperInfoBuf) ) );
cbFileAlloc1 = fs3SwapperInfoBuf.cbFileAlloc; // save initial size
IFERR( DosAllocMem( (PPVOID) &pBlk, cmbMemBlk*1024*1024, flAllocation ) );
printf( "----updated area----- time Swap\n" ); // header 1
printf( "pass MB + KB updts (ms) (KB)\n" ); // header 2
for ( i = 1; i <= cmbMemBlk*4; ++i ) { // no. of 256KB passes
// Millisecond count at start of inner loop.
IFERR( DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT,
&cTime1, sizeof(&cTime1) ) );
for ( j = 0; j < cUpdates; ++j ) // all the run-throughs
for ( k = 0; k < i*256*1024/4; k += 1024 ) // each 4K page
*( pBlk + k ) = k; // update the 4K page
// Find out how long this loop took.
IFERR( DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT,
&cTime2, sizeof(&cTime2) ) );
cTime2 -= cTime1;
// Find out how big SWAPPER.DAT is.
IFERR( DosQueryPathInfo( pszSwapper, FIL_STANDARD, &fs3SwapperInfoBuf,
sizeof(fs3SwapperInfoBuf) ) );
printf( "%4ld%4ld + %3ld%7ld%6ld%6ld\n",
i, i/4, i%4*256, i*256/4*cUpdates,
cTime2, fs3SwapperInfoBuf.cbFileAlloc/1024 );
if ( cTime2 > cTimeLim ) {
printf( "\nPass time (%ld ms) exceeds limit (%ld ms), stopping.\n",
cTime2, cTimeLim );
break;
}
if ( fs3SwapperInfoBuf.cbFileAlloc > cbFileAlloc1 ) {
printf( "\nThe swap file grew from %ldKB to %ldKB, stopping.\n",
cbFileAlloc1, fs3SwapperInfoBuf.cbFileAlloc );
break;
}
} // for ( i = 1; ... )
} // main()