home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l331 / 1.ddi / EXAMPLES / 386VMM / READLOG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-16  |  4.7 KB  |  205 lines

  1. /************************************************************************/
  2. /*    Copyright (C) 1986-1990 Phar Lap Software, Inc.            */
  3. /*    Unpublished - rights reserved under the Copyright Laws of the    */
  4. /*    United States.  Use, duplication, or disclosure by the         */
  5. /*    Government is subject to restrictions as set forth in         */
  6. /*    subparagraph (c)(1)(ii) of the Rights in Technical Data and     */
  7. /*    Computer Software clause at 252.227-7013.            */
  8. /*    Phar Lap Software, Inc., 60 Aberdeen Ave., Cambridge, MA 02138    */
  9. /************************************************************************/
  10. /*
  11.  * This program reads a page log file created by using the -PAGELOG switch
  12.  * with 386|VMM.
  13.  *
  14.  * It doesn't do anything very useful with the data, it just prints it
  15.  * out in human-readable form.
  16.  *
  17.  * To run:
  18.  *    readlog logfilename
  19.  *
  20.  * The output is written to standard output, and can be redirected to 
  21.  * a file with the DOS > redirection option.
  22.  */
  23.  
  24. #include <stdefs.h>
  25. #include <stdio.h>
  26. #include <pharlap.h>
  27.  
  28. main(int argc, char** argv) 
  29. {
  30.     FILE    *fiop;        /* page log file */
  31.     int    eof;        /* T ==> at end of file */
  32.     UCHAR    buf[512];    /* buffers data from file */
  33.     int    nch;        /* number of characters read */
  34.     int    recnum;        /* current record number */
  35.     int    nbytes;        /* number of characters requested */
  36.     int    i;        /* loop counter */
  37.     unsigned short ushort1;    /* temp variables */
  38.     unsigned long ulong1;
  39.  
  40. /*
  41.  * Open the file for binary access.
  42.  */
  43.      if (argc < 2)
  44.     {
  45.         printf("Usage:  readlog filename\n");
  46.         goto ERR_EXIT;
  47.     }
  48.     fiop = fopen(*(argv + 1), "rb");
  49.     if (fiop == NULL)
  50.     {
  51.         printf("Can't open file: %s\n",  *(argv + 1));
  52.         goto ERR_EXIT;
  53.     }
  54.  
  55. /*
  56.  * Scan thru the file processing the data
  57.  */
  58.     eof = FALSE;
  59.     while (!eof)
  60.     {
  61. /*
  62.  * Get next record number, quit loop if end of file.
  63.  */
  64.          nch = fread(buf, 1, 1, fiop);
  65.         if (nch != 1)
  66.             break;    
  67.         recnum = (int) (buf[0]);
  68.  
  69. /*
  70.  * Process this record.
  71.  */
  72.         switch(recnum)
  73.         {
  74. case PREC_BASE:        /* segment base changed */
  75.              nch = fread(buf, 1, 6, fiop);
  76.             if (nch != 6)
  77.             {
  78.                 eof = TRUE;
  79.                 break;
  80.             }
  81.             ushort1 = *((short *) (&buf[0]));
  82.             ulong1 = *((long *) (&buf[2]));
  83.             printf("New base of segment %04Xh = %08Xh\n", ushort1,
  84.                                 ulong1);
  85.             break;
  86.  
  87. case PREC_LIMIT:    /* segment limit changed */
  88.              nch = fread(buf, 1, 6, fiop);
  89.             if (nch != 6)
  90.             {
  91.                 eof = TRUE;
  92.                 break;
  93.             }
  94.             ushort1 = *((short *) (&buf[0]));
  95.             ulong1 = *((long *) (&buf[2]));
  96.             printf("New limit of segment %04Xh = %08Xh bytes\n", 
  97.                             ushort1, ulong1);
  98.             break;
  99.  
  100. case PREC_PGFLT:    /* page fault */
  101.              nch = fread(buf, 1, 5, fiop);
  102.             if (nch != 5)
  103.             {
  104.                 eof = TRUE;
  105.                 break;
  106.             }
  107.             ulong1 = *((long *) (&buf[1]));
  108.             printf("Page fault at lin addr: %08Xh", ulong1);
  109.             if (buf[0] & PLOG_DSKRD)
  110.             {
  111.                 if (buf[0] & PLOG_SWAPRD)
  112.                     printf(", page read from swap file");
  113.                 else
  114.                     printf(", page read from EXP file");
  115.             }
  116.             else
  117.                 printf(", page zeroed");
  118.             if (buf[0] & PLOG_THRASH)
  119.                 printf(", in memory before\n");
  120.             else
  121.                 printf(", 1st time in memory\n");
  122.             if (buf[0] & PLOG_REPLCD)
  123.             {
  124.                  nch = fread(&buf[1], 1, 4, fiop);
  125.                 if (nch != 4)
  126.                 {
  127.                     eof = TRUE;
  128.                     break;
  129.                 }
  130.                 ulong1 = *((long *) (&buf[1]));
  131.                 printf("   Replaced page at lin addr %08Xh",
  132.                                 ulong1);
  133.                 if (buf[0] & PLOG_SWAPWR)
  134.                     printf(", wrote repl page to disk\n");
  135.                 else
  136.                     printf(", discarded repl page\n");
  137.             }
  138.             break;
  139.  
  140. case PREC_SWAPSIZ:    /* swap file size increased */
  141.              nch = fread(buf, 1, 4, fiop);
  142.             if (nch != 4)
  143.             {
  144.                 eof = TRUE;
  145.                 break;
  146.             }
  147.             ulong1 = *((long *) (&buf[0]));
  148.             printf("Swap file increased to %08Xh bytes\n", ulong1);
  149.             break;
  150.  
  151. default:        /* appl record or unknown record */
  152. /*
  153.  * NOTE we ASSUME here that an appl record is an ASCII string terminated
  154.  * by a zero byte!!
  155.  */
  156.              nch = fread(buf, 1, 2, fiop);
  157.             if (nch != 2)
  158.             {
  159.                 eof = TRUE;
  160.                 break;
  161.             }
  162.             ushort1 = *((short *) (&buf[0]));
  163.             if (recnum == PREC_APPL)
  164.                 printf("Appl record: ");
  165.             else
  166.                 printf("Unknown record %d of len %d bytes\n",
  167.                             recnum, (int) ushort1);
  168.             for (i = 0; i < (int) ushort1; i += nbytes)
  169.             {
  170.                 nbytes = sizeof(buf) - 1;
  171.                 if (nbytes > (int) ushort1 - i)
  172.                     nbytes = (int) ushort1 - i;
  173.                 nch = fread(buf, 1, nbytes, fiop);
  174.                 if (recnum == PREC_APPL)
  175.                 {
  176.                     buf[nch] = 0;
  177.                     printf("%s", buf);
  178.                 }
  179.                 if (nch != nbytes)
  180.                 {
  181.                     eof = TRUE;
  182.                     break;
  183.                 }
  184.             }
  185.             if (recnum == PREC_APPL)
  186.                 printf("\n");
  187.             break;
  188.         }
  189.     }
  190.  
  191. /*
  192.  * Close the file and exit
  193.  */
  194.     if (fclose(fiop) != 0)
  195.     {
  196.         printf("Error closing file.\n");
  197.         goto ERR_EXIT;
  198.     }
  199.  
  200.     return 0;    /* success exit */
  201.  
  202. ERR_EXIT:
  203.     return 1;    /* error exit */
  204. }
  205.