home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pctech / hlsrc / hltimes.c < prev    next >
C/C++ Source or Header  |  1988-09-09  |  2KB  |  99 lines

  1. /*+
  2.     Name:       HLTIMES.C
  3.     Author:     Kent J. Quirk
  4.         (c) Copyright 1988 Ziff Communications Co.
  5.     Date:       April 1988
  6.     Abstract:   This file contains routines to save benchmark timings.
  7.         Each program using this file has particular set of records
  8.         to fill, each with a timing description.  Each record is
  9.         64 bytes, and each program can report up to 8 timings.
  10.         The first (zero) timing record is always reserved (by
  11.         convention) for the total benchmark time.
  12.         An item with a time of -1 is considered the last for
  13.         that program.
  14.     History:    09-Sep-88   kjq     Version 1.00
  15. -*/
  16.  
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include "hltimes.h"
  20.  
  21. #define NRECS 8
  22. #define NPROGS 8
  23.  
  24. FILE *timefile;
  25.  
  26. TIME_REC blankrec = { -1L, "" };
  27. TIME_REC hldesc[] = { 
  28.     { -1L, "     System:" },
  29.     { -1L, "        CPU:" },
  30.     { -1L, "Coprocessor:" },
  31.     { -1L, "     Memory:" },
  32.     { -1L, "      Video:" },
  33.     { -1L, "       Disk:" },
  34.     { -1L, "   Software:" },
  35.     { -1L, "      Other:" },
  36. };
  37.  
  38. void savetime(programid, record, timerec)
  39. int programid, record;
  40. TIME_REC *timerec;
  41. {
  42.     long fp;
  43.  
  44.     fp = (long)(((long)programid * NRECS + (long)record)
  45.         * (long)sizeof(TIME_REC));
  46.  
  47.     fseek(timefile, fp, SEEK_SET);
  48.     fwrite(timerec, sizeof(TIME_REC), 1, timefile);
  49.     return;
  50. }
  51.  
  52. TIME_REC *readtime(programid, record)
  53. {
  54.     static TIME_REC timerec;
  55.  
  56.     if ((programid >= NPROGS) || (record >= NRECS))
  57.     return(NULL);
  58.     fseek(timefile, (long)(((long)programid * NRECS + (long)record)
  59.     * (long)sizeof(TIME_REC)), SEEK_SET);
  60.     fread(&timerec, sizeof(TIME_REC), 1, timefile);
  61.     return(&timerec);
  62. }
  63.  
  64. int opentime(name)
  65. char *name;
  66. {
  67.     int i, j;
  68.     char fname[32];
  69.  
  70.     strcpy(fname, name);
  71.     if (strchr(fname, '.') != NULL)    /* if it has extension */
  72.     *(strchr(fname, '.')) = 0;    /* replace it */
  73.     strcat(fname, ".tim");
  74.  
  75.     if ((timefile = fopen(fname, "r+b")) == NULL)
  76.     {     
  77.     if ((timefile = fopen(fname, "w+b")) == NULL)
  78.         return(0);
  79.     else
  80.     {
  81.         /* creating new file, zero it all out */
  82.         for (j=0; j<NRECS; j++)
  83.         savetime(0, j, &(hldesc[j]));
  84.         
  85.         for (i=1; i<NPROGS; i++)
  86.         for (j=0; j<NRECS; j++)
  87.             savetime(i, j, &blankrec);
  88.         return(-1);
  89.     }
  90.     }
  91.     else
  92.     return(-1);
  93. }
  94.  
  95. void closetime()
  96. {
  97.     fclose(timefile);
  98. }
  99.