home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / demos / gpc / brf_phead.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-04  |  12.8 KB  |  400 lines

  1. /* $XConsortium: brf_phead.c,v 5.3 91/04/04 13:32:58 gildea Exp $ */
  2. /***********************************************************
  3. Copyright(c) 1989,1990, 1991 by Sun Microsystems, Inc. and the X Consortium at M.I.T.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its
  8. documentation for any purpose and without fee is hereby granted,
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in
  11. supporting documentation, and that the names of Sun Microsystems,
  12. the X Consortium, and MIT not be used in advertising or publicity
  13. pertaining to distribution of the software without specific, written
  14. prior permission.
  15.  
  16. SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  17. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
  18. SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  19. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22. SOFTWARE.
  23.  
  24. ******************************************************************/
  25.  
  26. /*--------------------------------------------------------------------*\
  27. |  Copyright (C) 1989,1990, 1991, National Computer Graphics Association
  28. |
  29. |  Permission is granted to any individual or institution to use, copy, or
  30. |  redistribute this software so long as it is not sold for profit, provided
  31. |  this copyright notice is retained.
  32. |
  33. |                         Developed for the
  34. |                National Computer Graphics Association
  35. |                         2722 Merrilee Drive
  36. |                         Fairfax, VA  22031
  37. |                           (703) 698-9600
  38. |
  39. |                                by
  40. |                 SimGraphics Engineering Corporation
  41. |                    1137 Huntington Drive  Unit A
  42. |                      South Pasadena, CA  91030
  43. |                           (213) 255-0900
  44. |---------------------------------------------------------------------
  45. |
  46. | Author        :    Norman D. Evangelista
  47. |
  48. | File          :    brf_prtheader.c
  49. | Date          :    Mon Jul  3 18:51:18 PDT 1989
  50. | Project       :    BIF Benchmark Reporting Format
  51. | Description   :    File header generation routines
  52. | Status        :    Version 1.0
  53. |
  54. | Revisions     :    
  55. |
  56. \*--------------------------------------------------------------------*/
  57.  
  58. /*--------------------------------------------------------------------*\
  59. |    Table of Contents
  60. |
  61. |    char *BRF_appendToColon( *char, *char )
  62. |        :    Appends a character string after a colon.
  63. |    void BRF_loopTiming( int, float, float, int, *char, *FILE )
  64. |        :    Prints test loop timing information to BRF output.
  65. |    void BRF_printHeader( *FILE )
  66. |        :    Prints the BRF file header to the specified file.
  67. |    char *BRF_getDate( void )
  68. |        :    Gets a day/date string for timestamping.
  69. |    char *BRF_appendEndBar( *char )
  70. |        :    Appends the end bar to the end of a string
  71. |
  72. \*--------------------------------------------------------------------*/
  73.  
  74. #include <X11/Xos.h>
  75. #include <stdio.h>
  76. #include "brf_prt.h"
  77. #include "biftypes.h"
  78. #include "globals.h"
  79. #include "brfexption.h"
  80.  
  81. #ifndef X_NOT_STDC_ENV
  82. #include <time.h>
  83. #else
  84. struct tm *localtime();
  85. #endif
  86.  
  87. #define MAX(a,b) (((a)>(b))?(a):(b))
  88. #define MIN(a,b) (((a)<(b))?(a):(b))
  89.  
  90. char *BRF_appendEndBar();
  91.  
  92.  
  93.  
  94. /*--------------------------------------------------------------------*\
  95. | Procedure     :    char *BRF_appendToColon( *char, *char )
  96. |---------------------------------------------------------------------
  97. | Description   :    Appends a character string after a colon.
  98. |---------------------------------------------------------------------
  99. | Return        :    String 1 with string 2 appended.
  100. \*--------------------------------------------------------------------*/
  101. char *BRF_appendToColon( str1, str2 )
  102. char    *str1;                /* Target string     */
  103. char    *str2;                /* String to append  */
  104.  
  105. {/* BRF_appendToColon */
  106.  
  107.     char        toColon[ 80 ];
  108.     int n_tocolon, sub_length;
  109.     static int total_line_len = 72;
  110.  
  111.     n_tocolon = strcspn (str1,":");
  112.  
  113.     sub_length = strlen( str1 );
  114.     if (n_tocolon == sub_length) 
  115.         n_tocolon = N_TOCOLON;
  116.         else n_tocolon += 4;
  117.     strncpy( toColon, str1, n_tocolon );
  118.     toColon[n_tocolon] = '\0';
  119.  
  120.     strcat( toColon, "   " );
  121.     strcat( toColon, str2 );
  122.     sub_length = strlen( toColon );
  123.     if (sub_length < total_line_len)
  124.         strncat(toColon,
  125. "                                                                        ",
  126.                 (total_line_len-sub_length-1 ));
  127.     strcat(toColon,"|\n");
  128.     strcpy( str1, toColon );
  129.     return( str1 );
  130.  
  131. }/* BRF_appendToColon */
  132.  
  133. /*--------------------------------------------------------------------*\
  134. | Procedure     :    void BRF_loopTiming( int, float, float, int,
  135. |                         *char, *FILE )
  136. |---------------------------------------------------------------------
  137. | Description   :    Prints test loop timing information to BRF output.
  138. |---------------------------------------------------------------------
  139. | Revisions    :    Moved epsilon from brf_stop_stopwatch to here
  140. |             M.F.R. 2/6/90
  141. |
  142. |---------------------------------------------------------------------
  143. | Return :    
  144. \*--------------------------------------------------------------------*/
  145. BRF_loopTiming( nFrames, elapsedTime, xmitDelay,
  146. loopNumber, testName, brfFile )
  147. int    nFrames;            /* Number of frames this loop      */
  148. float    elapsedTime;            /* Duration of this loop      */
  149. float    xmitDelay;            /* System transmission delay      */
  150. int    loopNumber;            /* Number of this test loop      */
  151. char    *testName;            /* Name of this PLB test      */
  152. FILE    *brfFile;            /* BRF output file pointer      */
  153.  
  154. {/* BRF_loopTiming */
  155.  
  156.     int            j = 0,k,i;
  157.     float        framesPerSecond, timePerFrame;
  158.     float        timingAccuracy;
  159.     float        timingAccuracy2;
  160.     char        strQuant[ 32 ], headLine[ 80 ];
  161.     FILE        *brfHedFile;
  162.  
  163.     /*----------------------------------------------------------------*\
  164.     |    Calculate timing stats
  165.     \*----------------------------------------------------------------*/
  166.     if (elapsedTime == 0.0) elapsedTime = 0.0001; 
  167.     framesPerSecond = (float)nFrames / elapsedTime;
  168.     timePerFrame    = elapsedTime / (float)nFrames;
  169. #ifdef EXTERNALNOTE
  170.     /* Old Chinese Proverb goes,"A man with one watch knows what time
  171.     it is. Aman with two watches is never really sure!"
  172.     Here we have two alternative methods of gauging the overall
  173.     accuracy of the PLB run, sort of a benchmark on the benchmark.
  174.     Method 1 is derived from the ratio of total elapsed time to transport
  175.     delay time.
  176.     Method two arbitrarily measures time and iterations against an
  177.     empircal (arbitrary) scale of accuracy.
  178.     */
  179. #endif
  180.  
  181.     timingAccuracy  = 100.0 * (elapsedTime / 
  182.         (elapsedTime + (10 * xmitDelay)));
  183.  
  184.         timingAccuracy2 = ((100 * (elapsedTime / 10) 
  185.     + (float)nFrames / 1100.0)) * .5;
  186.  
  187.     timingAccuracy2 = MIN(100.0,timingAccuracy2);
  188.  
  189.     /*----------------------------------------------------------------*\
  190.     |    Grab lines and pump through to BRF output file
  191.     \*----------------------------------------------------------------*/
  192.     i=0;
  193.     k=0;
  194.     while ( BRF_timeData[i][k] != (char *)NULL )
  195.     {
  196.         strcpy(headLine, BRF_timeData[i][k++]);
  197.  
  198.         switch( ++j )
  199.         {/* Append info to proper lines */
  200.  
  201.             case 1    :
  202.             case 3    :
  203.                 break;
  204.  
  205.             case 2    :
  206.                 fprintf( brfFile, "%s", headLine );
  207.                 sprintf( headLine, 
  208.                 "|   Test Loop of %d frames from File %s\n",
  209.                            loopNumber, testName );
  210.                 BRF_appendEndBar(headLine);
  211.                 break;
  212.  
  213.             case 4    :
  214.                 sprintf( strQuant, "%d", nFrames );
  215.                 BRF_appendToColon( headLine, strQuant );
  216.                 break;
  217.  
  218.             case 5    :
  219.                 sprintf( strQuant, "%6.2f", elapsedTime );
  220.                 BRF_appendToColon( headLine, strQuant );
  221.                 break;
  222.  
  223.             case 6    :
  224.                 sprintf( strQuant, "%6.2f", xmitDelay );
  225.                 BRF_appendToColon( headLine, strQuant );
  226.                 break;
  227.  
  228.             case 7    :
  229.                 sprintf( strQuant, "%6.2f", framesPerSecond );
  230.                 BRF_appendToColon( headLine, strQuant );
  231.                 break;
  232.  
  233.             case 8    :
  234.                 sprintf( strQuant, "%6.2f", timePerFrame );
  235.                 BRF_appendToColon( headLine, strQuant );
  236.                 break;
  237.  
  238.             case 9    :
  239.                 sprintf( strQuant, "%6.2f%%", timingAccuracy );
  240.                 BRF_appendToColon( headLine, strQuant );
  241.                 break;
  242.  
  243.                         case 10  :
  244.                                 sprintf( strQuant, "%6.2f%%", timingAccuracy2 );
  245.                                 BRF_appendToColon( headLine, strQuant );
  246.                                 break;
  247.  
  248.         }/* Append info to proper lines */
  249.  
  250.         fprintf( brfFile, "%s", headLine );
  251.  
  252.     }/* Pipe output through */
  253.  
  254.     /*----------------------------------------------------------------*\
  255.     |    Separate from next header, close current header
  256.     \*----------------------------------------------------------------*/
  257.     fprintf( brfFile, "%s\n",
  258. "------------------------------------------------------------------------\n");
  259.  
  260.  
  261. }/* BRF_loopTiming */
  262.  
  263. /*--------------------------------------------------------------------*\
  264. | Procedure     :    void BRF_printHeader( *FILE )
  265. |---------------------------------------------------------------------
  266. | Description   :    Prints the BRF file header to the specified file.
  267. |---------------------------------------------------------------------
  268. | Return        :    
  269. \*--------------------------------------------------------------------*/
  270. BRF_printHeader( brfFile )
  271. FILE        *brfFile;                /* BRF output file pointer          */
  272.  
  273. {/* BRF_printHeader */
  274.  
  275.     int            i, j, k;
  276.     char        headLine[ 80 ];
  277.     char        *BRF_appendToColon(), *BRF_getDate();
  278.     FILE        *brfHedFile;
  279.  
  280.     for ( i = 0, j = 0; i < N_HEADFILES; i++ )
  281.     {/* Pipe header files through */
  282.  
  283.         /*------------------------------------------------------------*\
  284.         |    Grab lines and pump through to BRF output file
  285.         \*------------------------------------------------------------*/
  286.         k=0;
  287.         while ( BRF_hedrData[i][k] != (char *)NULL )
  288.         {/* Append timestamp to last line of first header */
  289.             strcpy(headLine, BRF_hedrData[i][k++]);
  290.  
  291.             if ( ++j == N_TITLELINES )
  292.                 BRF_appendToColon( headLine, BRF_getDate() );
  293.             fprintf( brfFile, "%s", headLine );
  294.  
  295.         }/* Append timestamp to last line of first header */
  296. #if 0
  297.         /*------------------------------------------------------------*\
  298.         |    Separate from next header, close current header
  299.         \*------------------------------------------------------------*/
  300.         fprintf( brfFile, "\n" );
  301. #endif /* if  0 */
  302.  
  303.     }/* Pipe header files through */
  304.  
  305. }/* BRF_printHeader */
  306.  
  307. /*--------------------------------------------------------------------*\
  308. | Procedure     :    char *BRF_getDate( void )
  309. |---------------------------------------------------------------------
  310. | Description   :    Gets a day/date string for timestamping.
  311. |---------------------------------------------------------------------
  312. | Return        :    Character string of form:
  313. |                    Mon Jul  3 19:46:39 PDT 1989, corrected for
  314. |                    local time zone and prevailing alternate zone.
  315. \*--------------------------------------------------------------------*/
  316. char *BRF_getDate()
  317.  
  318. {/* BRF_getDate */
  319. #ifdef EXTERNALNOTE
  320.  
  321.         ATTENTION END PORT PROGRAMMERS!!!!!!!
  322.  
  323.       The date function used in this block is standard to BSD UNIX
  324.     systems and to most UNIX systems in general. It may NOT be
  325.     supported on some UNIX systems, and will probably not
  326.     exist on non_UNIX C compilers. 
  327. #endif
  328.  
  329.  
  330. #ifndef sgi               /* SGI compiler complains about redeclaration */
  331.     int gettimeofday();
  332. #endif
  333.         struct timeval tval, *tp;
  334.         struct timezone tzone, *tzp;
  335.     struct tm    *calendar;
  336.     char *asctime_pt;
  337.     char *line_ret;
  338.  
  339.     int status;
  340.  
  341.     tp = &tval;
  342.     tzp = &tzone;
  343.  
  344.     tzone.tz_minuteswest = 0; /* Use system default here */
  345.     tzone.tz_dsttime = 0; /* Use system default here */
  346.         status = gettimeofday(tp, tzp);
  347.     if(status == -1)
  348.     {
  349.         fprintf(stderr,"OOPS: Failure on gettimeofday.\n");
  350.         fflush(stderr);
  351.     
  352.     }
  353.     calendar = localtime(&tp->tv_sec);
  354.      asctime_pt = asctime( calendar );  
  355.     /* remove the line return in this string */
  356.     if ( (line_ret = index( asctime_pt, '\n')) != NULL)
  357.         line_ret[0] = ' ';
  358.      return( asctime_pt );  
  359. }/* BRF_getDate */
  360.  
  361.  
  362.  
  363. /*--------------------------------------------------------------------*\
  364. | Procedure     :    char *BRF_appendEndBar( *char )
  365. |---------------------------------------------------------------------
  366. | Description   :    Appends the end bar to the end of a string
  367. |---------------------------------------------------------------------
  368. | Return        :    String with end bar in column 72
  369. \*--------------------------------------------------------------------*/
  370. char *BRF_appendEndBar( str1)
  371. char    *str1;                /* Target string     */
  372. {/* BRF_appendToColon */
  373.  
  374.     char        toColon[ 80 ];
  375.     int         n_tocolon, sub_length;
  376.     char        *line_ret;
  377.     static int     total_line_len = 72;
  378.     
  379.     /* remove any and all line return in this string */
  380.     while ( (line_ret = index( str1, '\n')) != NULL)
  381.         line_ret[0] = ' ';
  382.  
  383.     sub_length = strlen( str1 );
  384.     if (sub_length < total_line_len)
  385.     {
  386.         strncat(str1,
  387. "                                                                        ",
  388.             (total_line_len-sub_length-1 ));
  389.         strcat(str1,"|\n");
  390.     } else
  391.     {
  392.         str1[total_line_len-1] = '|';
  393.         str1[total_line_len  ] = '\n';
  394.         str1[total_line_len+1] = '\0';
  395.     }
  396.     return(str1);
  397.  
  398. }/* BRF_appendToColon */
  399.  
  400.