home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 8 Other
/
08-Other.zip
/
SWPTST.ZIP
/
SWAPTST1.C
< prev
next >
Wrap
Text File
|
1993-02-15
|
6KB
|
150 lines
/*
Swap Test 1 repeats the following in a loop:
1. Allocate a 256KB block of memory.
2. Do an update in every 4KB page in the block.
3. Measure the time this takes.
4. Query the available memory.
5. Query the size of SWAPPER.DAT.
6. Display values for this pass thru the loop.
7. Break out of the loop if the time for this pass thru the loop exceeds
a limiting value, or if the swap file grows.
Parameters:
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.)
szSwapper: The path to the swap file. Defaults to
C:\OS2\SYSTEM\SWAPPER.DAT.
There's little or no error checking on the 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>
USHORT APIENTRY16 Dos16MemAvail( PULONG );
#define IFERR( f ) if ( lRC = (LONG) ( f ) ) \
{ printf( "Stopping at source line %d due to API error code %ld.\n", \
__LINE__, lRC ); exit( lRC ); }
#define BLKMAX 2048 // BLKMAX*cbBlk should be > max possible RAM
PCHAR apBlk[BLKMAX]; // array of ptrs to memory blocks, [0] not used
int main( USHORT argc, PCHAR argv[] )
{
ULONG lParm = 0; // workarea for input parameter
ULONG cbTotPhysMem; // total physical memory via DosQuerySysInfo()
ULONG cMemAvail; // available memory via DosMemAvail()
ULONG cTime1, cTime2; // ms times via DosQuerySysInfo()
ULONG cTimeLim = 200; // time limit in ms to get/update memory block
ULONG cBlk; // count of memory blocks
ULONG cbBlk = 256*1024; // Size in bytes of each memory block
ULONG flAllocation = PAG_WRITE | PAG_READ | PAG_COMMIT;
PUCHAR pszSwapper = "C:\\OS2\\SYSTEM\\SWAPPER.DAT"; // default path
ULONG ulSwapperPathInfo = FIL_STANDARD; // for DosQueryPathInfo()
FILESTATUS3 fs3SwapperInfoBuf; // for DosQueryPathInfo() of SWAPPER.DAT
ULONG cbFileAlloc1; // initial size of SWAPPER.DAT
ULONG i; // index
APIRET lRC; // return code
// If there are input argument(s), convert and put in variables.
if ( argc > 1 ) {
lParm = atol( argv[1] ); // convert
if ( lParm ) // copy parm to variable if result non-0.
cTimeLim = lParm;
if ( argc > 2 )
pszSwapper = argv[2]; // save pointer
}
printf( "\nSwap Test 1:\n\n" );
// Get 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 );
printf( "Memory will be allocated/updated in %ldKB blocks.\n",
cbBlk/1024 );
printf( "Time limit to allocate/update one block is %ld ms.\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( Dos16MemAvail( &cMemAvail ) ); // initial value
printf( " --MemAlloc-- MemAvail time Swap\n" ); // header 1
printf( " N MB + KB MB + KB (ms) (KB)\n" ); // header 2
printf( "%4lu%4lu +%4lu%4lu +%4lu%6lu%6lu\n", // initial conditions
0, 0, 0,
cMemAvail/(1024*1024), ( cMemAvail%(1024*1024) )/1024,
0, fs3SwapperInfoBuf.cbFileAlloc/1024 );
for ( cBlk = 1; cBlk <= BLKMAX; ++cBlk ) {
// Get millisecond count before memory allocation and update.
IFERR( DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT,
&cTime1, sizeof( cTime1 ) ) );
IFERR( DosAllocMem( (PPVOID) &apBlk[cBlk], cbBlk, flAllocation ) );
for ( i = 0; i < cbBlk; i += 4096 ) // go to every 4K page
*(apBlk[cBlk]+i) = 'X'; // and update a byte
// Get millisecond count after.
IFERR( DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT,
&cTime2, sizeof( cTime2 ) ) );
IFERR( Dos16MemAvail( &cMemAvail ) ); // find out memory left
// Find out how big SWAPPER.DAT is.
IFERR( DosQueryPathInfo( pszSwapper, FIL_STANDARD, &fs3SwapperInfoBuf,
sizeof(fs3SwapperInfoBuf) ) );
printf( "%4lu%4lu +%4lu%4lu +%4lu%6lu%6lu\n",
cBlk, cBlk*cbBlk/(1024*1024), ( cBlk*cbBlk%(1024*1024) )/1024,
cMemAvail/(1024*1024), ( cMemAvail%(1024*1024) )/1024,
cTime2 - cTime1, fs3SwapperInfoBuf.cbFileAlloc/1024 );
if ( cTime2 - cTime1 > cTimeLim ) {
printf( "\nTime for 1 memory block (%ld ms) exceeded limit "
"(%ld ms), stopping.\n", cTime2 - cTime1, cTimeLim );
break;
}
if ( fs3SwapperInfoBuf.cbFileAlloc > cbFileAlloc1 ) {
printf( "\nThe swap file grew from %ldKB to %ldKB, stopping.\n",
cbFileAlloc1/1024, fs3SwapperInfoBuf.cbFileAlloc/1024 );
break;
}
} // for ( cBlk = 0; ... )
} // main()