home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************/
- /* Copyright (C) 1986-1990 Phar Lap Software, Inc. */
- /* Unpublished - rights reserved under the Copyright Laws of the */
- /* United States. Use, duplication, or disclosure by the */
- /* Government is subject to restrictions as set forth in */
- /* subparagraph (c)(1)(ii) of the Rights in Technical Data and */
- /* Computer Software clause at 252.227-7013. */
- /* Phar Lap Software, Inc., 60 Aberdeen Ave., Cambridge, MA 02138 */
- /************************************************************************/
- /*
- * This program reads a page log file created by using the -PAGELOG switch
- * with 386|VMM.
- *
- * It doesn't do anything very useful with the data, it just prints it
- * out in human-readable form.
- *
- * To run:
- * readlog logfilename
- *
- * The output is written to standard output, and can be redirected to
- * a file with the DOS > redirection option.
- */
-
- #include <stdefs.h>
- #include <stdio.h>
- #include <pharlap.h>
-
- main(int argc, char** argv)
- {
- FILE *fiop; /* page log file */
- int eof; /* T ==> at end of file */
- UCHAR buf[512]; /* buffers data from file */
- int nch; /* number of characters read */
- int recnum; /* current record number */
- int nbytes; /* number of characters requested */
- int i; /* loop counter */
- unsigned short ushort1; /* temp variables */
- unsigned long ulong1;
-
- /*
- * Open the file for binary access.
- */
- if (argc < 2)
- {
- printf("Usage: readlog filename\n");
- goto ERR_EXIT;
- }
- fiop = fopen(*(argv + 1), "rb");
- if (fiop == NULL)
- {
- printf("Can't open file: %s\n", *(argv + 1));
- goto ERR_EXIT;
- }
-
- /*
- * Scan thru the file processing the data
- */
- eof = FALSE;
- while (!eof)
- {
- /*
- * Get next record number, quit loop if end of file.
- */
- nch = fread(buf, 1, 1, fiop);
- if (nch != 1)
- break;
- recnum = (int) (buf[0]);
-
- /*
- * Process this record.
- */
- switch(recnum)
- {
- case PREC_BASE: /* segment base changed */
- nch = fread(buf, 1, 6, fiop);
- if (nch != 6)
- {
- eof = TRUE;
- break;
- }
- ushort1 = *((short *) (&buf[0]));
- ulong1 = *((long *) (&buf[2]));
- printf("New base of segment %04Xh = %08Xh\n", ushort1,
- ulong1);
- break;
-
- case PREC_LIMIT: /* segment limit changed */
- nch = fread(buf, 1, 6, fiop);
- if (nch != 6)
- {
- eof = TRUE;
- break;
- }
- ushort1 = *((short *) (&buf[0]));
- ulong1 = *((long *) (&buf[2]));
- printf("New limit of segment %04Xh = %08Xh bytes\n",
- ushort1, ulong1);
- break;
-
- case PREC_PGFLT: /* page fault */
- nch = fread(buf, 1, 5, fiop);
- if (nch != 5)
- {
- eof = TRUE;
- break;
- }
- ulong1 = *((long *) (&buf[1]));
- printf("Page fault at lin addr: %08Xh", ulong1);
- if (buf[0] & PLOG_DSKRD)
- {
- if (buf[0] & PLOG_SWAPRD)
- printf(", page read from swap file");
- else
- printf(", page read from EXP file");
- }
- else
- printf(", page zeroed");
- if (buf[0] & PLOG_THRASH)
- printf(", in memory before\n");
- else
- printf(", 1st time in memory\n");
- if (buf[0] & PLOG_REPLCD)
- {
- nch = fread(&buf[1], 1, 4, fiop);
- if (nch != 4)
- {
- eof = TRUE;
- break;
- }
- ulong1 = *((long *) (&buf[1]));
- printf(" Replaced page at lin addr %08Xh",
- ulong1);
- if (buf[0] & PLOG_SWAPWR)
- printf(", wrote repl page to disk\n");
- else
- printf(", discarded repl page\n");
- }
- break;
-
- case PREC_SWAPSIZ: /* swap file size increased */
- nch = fread(buf, 1, 4, fiop);
- if (nch != 4)
- {
- eof = TRUE;
- break;
- }
- ulong1 = *((long *) (&buf[0]));
- printf("Swap file increased to %08Xh bytes\n", ulong1);
- break;
-
- default: /* appl record or unknown record */
- /*
- * NOTE we ASSUME here that an appl record is an ASCII string terminated
- * by a zero byte!!
- */
- nch = fread(buf, 1, 2, fiop);
- if (nch != 2)
- {
- eof = TRUE;
- break;
- }
- ushort1 = *((short *) (&buf[0]));
- if (recnum == PREC_APPL)
- printf("Appl record: ");
- else
- printf("Unknown record %d of len %d bytes\n",
- recnum, (int) ushort1);
- for (i = 0; i < (int) ushort1; i += nbytes)
- {
- nbytes = sizeof(buf) - 1;
- if (nbytes > (int) ushort1 - i)
- nbytes = (int) ushort1 - i;
- nch = fread(buf, 1, nbytes, fiop);
- if (recnum == PREC_APPL)
- {
- buf[nch] = 0;
- printf("%s", buf);
- }
- if (nch != nbytes)
- {
- eof = TRUE;
- break;
- }
- }
- if (recnum == PREC_APPL)
- printf("\n");
- break;
- }
- }
-
- /*
- * Close the file and exit
- */
- if (fclose(fiop) != 0)
- {
- printf("Error closing file.\n");
- goto ERR_EXIT;
- }
-
- return 0; /* success exit */
-
- ERR_EXIT:
- return 1; /* error exit */
- }
-