home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pctech / hlsrc / hlanalyz.c < prev    next >
Text File  |  1988-09-09  |  12KB  |  537 lines

  1. /*+
  2.     Name:        HLANALYZ.C
  3.     Author:     Kent J. Quirk
  4.             (c) Copyright 1988 Ziff Communications Co.
  5.     Date:       April 1988
  6.     Abstract:   The program to analyze & compare benchmark data.
  7.     History:    09-Sep-88    kjq    Version 1.00
  8. -*/
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <graph.h>
  14. #include <dos.h>
  15. #include <conio.h>
  16. #include <time.h>
  17.  
  18. #include "hl.h"
  19. #include "hltimes.h"
  20. #include "winmenu.h"
  21.  
  22. char *menu[] = {
  23.     "Select a different reference machine",
  24.     "Display data for the reference machine",
  25.     "Select a machine to compare to the reference           ",
  26.     "Display data for comparison machine",
  27.     "Text comparison of both machines",
  28.     "Graphical comparison of major features",
  29.     "Printed comparison in detail", 
  30.     "Return to main menu",
  31.     NULL
  32. };
  33.  
  34. char *horizline = "────────────────────────────────────";
  35. WINDOW *w;
  36.  
  37. #define MAXLINES 10
  38. char text[MAXLINES][80];
  39. char *tmenu[MAXLINES];
  40.  
  41. /**** c e n t e r ****
  42.     Abstract:    Given a buffer and its width, this centers a string 
  43.         in the buffer.
  44.     Parameters: char *dest - a buffer pointer
  45.         int width - the desired width of the buffer
  46.         char *str - a string shorter than dest
  47.     Returns:    nothing
  48. ****************************/
  49. void center(char *dest, int width, char *str)
  50. {
  51.     memset(dest, ' ', width);        /* pad with spaces */
  52.     dest[width] = 0;            /* trailing trim */
  53.     memcpy(dest+((width-strlen(str))/2), str, strlen(str));
  54. }
  55.  
  56. /**** p r i n t _ c o m p a r e ****
  57.     Abstract:    Prints a comparison of the data to a file or device, as set by 
  58.         SET PRINTER=filename from DOS.
  59.     Parameters: The names of the two .TIM files to compare.
  60.     Returns:    Nothing
  61. ****************************/
  62. void print_compare(char *f1, char *f2)
  63. {
  64.     int i, j;
  65.     TIME_REC tr, *trp;
  66.     char *fname, *fmt;
  67.     FILE *pf;
  68.     int done = 0;
  69.     time_t ltime;
  70.     
  71.     
  72.     
  73.     if ((fname = getenv("PRINTER")) == NULL)
  74.     fname = "LPT1";
  75.     if ((pf = fopen(fname, "a")) == NULL)
  76.     {
  77.     char buf[80];
  78.     sprintf(buf, "Printer/file %s not accessible!\a", fname);
  79.     pop_error(buf);
  80.     return;
  81.     }
  82.     
  83.     /*
  84.     printf("Printing on %s...", fname);
  85.     */
  86.     
  87.     time(<ime);
  88.     fmt = ctime(<ime);
  89.     fmt[11] = 0;
  90.     
  91.     fprintf(pf, "PC Tech Journal System Benchmarks, version 1.00         ");
  92.     fprintf(pf, "Printed %s%s", fmt, fmt+20);
  93.     fprintf(pf, "\nReference Machine\n");
  94.     opentime(f1);                /* print F1 header */
  95.     for (j=0; ;j++)
  96.     {
  97.     trp = readtime(0, j);
  98.     if (trp == NULL)
  99.         break;
  100.     fprintf(pf, "    %-64.64s\n", trp->desc);
  101.     }
  102.     closetime();
  103.  
  104.     fprintf(pf, "Tested Machine\n");
  105.     opentime(f2);                /* print F2 header */
  106.     for (j=0; ;j++)
  107.     {
  108.     trp = readtime(0, j);
  109.     if (trp == NULL)
  110.         break;
  111.     fprintf(pf, "    %-64.64s\n", trp->desc);
  112.     }
  113.     closetime();
  114.  
  115.     fprintf(pf, "%-40.40s  %8.8s  %8.8s  %8s\n", 
  116.         "\nDescription", f1, f2, "% of Ref.");
  117.     for (i=1; !done ;i++)
  118.     {
  119.     for (j=1; ;)
  120.     {
  121.         opentime(f1);
  122.         trp = readtime(i, j);
  123.         closetime();
  124.         if (trp == NULL)
  125.         if (j == 0)
  126.         {
  127.             done = 1;        /* we tried to read i, 0 and it failed */
  128.             break;        /* so we're done with everything */
  129.         }
  130.         else
  131.         {
  132.             j = 0;        /* we must be done with this i */
  133.             continue;        /* read title line and finish */
  134.         }
  135.         tr = *trp;
  136.         opentime(f2);
  137.         trp = readtime(i, j);
  138.         closetime();
  139.         
  140.         if (tr.ticks == -1)
  141.         if (trp->ticks == -1)
  142.         {
  143.             if (j == 0)     /* another place to be done */
  144.             break;
  145.             j++;
  146.             continue;
  147.         }
  148.         else
  149.         strcpy(tr.desc, trp->desc);   /* use second desc */
  150.         
  151.         if (j == 0)
  152.         fmt = "%40.40s  %8.8s  %8.8s  %8s\n\n";
  153.         else
  154.         fmt = "%40.40s  %8.8s  %8.8s  %8s\n";
  155.         
  156.         fprintf(pf, fmt, tr.desc, time_secs(tr.ticks),
  157.         time_secs(trp->ticks), time_pct(trp->ticks, tr.ticks));
  158.         
  159.         if (j == 0)     /* are we done with this i? */
  160.         break;        /* yes, quit */
  161.         else
  162.         j++;        /* no, increment j and do it again */
  163.     }
  164.     }
  165.     fprintf(pf, "\x0C");    /* print form feed */
  166.     fclose(pf);
  167.     /*
  168.     printf("Done.\n");
  169.     */
  170. }
  171.  
  172. /**** c o m p a r e _ t i m e s ****
  173.     Abstract:    Compares times for two files, either on a summary or
  174.         detail level. If prog==-1, does a summary.  If prog is a
  175.         number, does details for that number.
  176.     Parameters: char *f1, *f2 -- the names of the two files
  177.         int prog - the "program" number to compare in detail, or -1
  178.                 to compare summary numbers
  179.         int offset - the offset within a given program to compare
  180.         char *title - the title of the comparison menu
  181.     Returns:    The number selected, if prog was -1, else -1.
  182.     Comments:    This is pretty ugly.
  183. ****************************/
  184. int compare_times(f1, f2, prog, offset, title)
  185. char *f1, *f2;
  186. int prog, offset;
  187. char *title;
  188. {
  189.     int i, j;
  190.     TIME_REC tr, *trp;
  191.     long rel;
  192.     char buf[65];
  193.     int original[MAXLINES];
  194.     int done = 0;
  195.  
  196.     j = 0;
  197.     for (i=1; !done; i++)
  198.     {
  199.     opentime(f1);
  200.     if (prog == -1)
  201.         trp = readtime(i, offset);        /* summary level */
  202.     else
  203.     {
  204.         if (i==0)
  205.         ++i;
  206.         trp = readtime(prog, i);
  207.         if (trp == NULL)
  208.         {
  209.         trp = readtime(prog, 0);
  210.         done = 1;
  211.         i = 0;
  212.         }
  213.     }
  214.     closetime();
  215.     if (trp == NULL)
  216.         break;
  217.     tr = *trp;
  218.  
  219.     if (f2 != NULL)
  220.     {
  221.         opentime(f2);
  222.         if (prog == -1)
  223.         trp = readtime(i, offset);
  224.         else
  225.         trp = readtime(prog, i);
  226.         closetime();
  227.     }
  228.     else
  229.         trp->ticks = -1;
  230.  
  231.     if (tr.ticks == -1)
  232.         if (trp->ticks == -1)
  233.         continue;
  234.     else
  235.         strcpy(tr.desc, trp->desc);   /* use second desc */
  236.  
  237.     if (prog == 0)
  238.         sprintf(text[j], "%-63.63s", tr.desc);
  239.     else
  240.         sprintf(text[j], "%32.32s:  %8.8s  %8.8s  %8s", tr.desc,
  241.         time_secs(tr.ticks), time_secs(trp->ticks),
  242.         time_pct(trp->ticks, tr.ticks));
  243.     tmenu[j] = text[j];
  244.     original[j] = i;
  245.     j++;
  246.     }
  247.  
  248.     if (j == 0)
  249.     {
  250.     pop_error("There is no data in the file yet.  Run some tests first.");
  251.     return(-1);
  252.     }
  253.     
  254.     tmenu[j] = NULL;
  255.     if (f2 == NULL)
  256.     f2 = " N/A  ";
  257.  
  258.     if (prog == 0)
  259.     sprintf(buf, "%-32.32s%23.23s%8s", horizline, " ", f1);
  260.     else
  261.     sprintf(buf, "%-32.32s   %8.8s  %8.8s  %8s", horizline,
  262.         f1, f2, "% of Ref");
  263.  
  264.     if ((i = do_menu(tmenu, buf, title, (prog == -1) ? 0 : -1)) < 0)
  265.     return(i);
  266.     else
  267.     return(original[i]);
  268. }
  269.  
  270. /**** t e x t _ c o m p a r e ****
  271.     Abstract:    Performs a text-based file comparison; calls 
  272.         compare_times appropriately.
  273.     Parameters: The two filenames to compare
  274.     Returns:    Nothing.
  275. ****************************/
  276. void text_compare(f1, f2)
  277. char *f1, *f2;
  278. {
  279.     int select;
  280.  
  281.     while ((select = compare_times(f1, f2, -1, 0,
  282.         "Press Enter for detail, ESC to return.")) >= 0)
  283.     {
  284.     compare_times(f1, f2, select, -1, "Press ESC to exit");
  285.     }
  286. }
  287.  
  288. /**** o n e _ t e s t _ d e t a i l ****
  289.     Abstract:    Compares details for a specific test; used by 
  290.         HLBENCH after running a specific test; lets the 
  291.         user see the results immediately.
  292.     Parameters: The test number to compare
  293.     Returns:    Nothing
  294. ****************************/
  295. void one_test_detail(f1, f2, test)
  296. char *f1, *f2;
  297. int test;
  298. {
  299.     compare_times(f1, f2, test, -1, "Press ESC to exit");
  300. }
  301.  
  302. /**** g r a p h _ c o m p a r e ****
  303.     Abstract:    Compares two summary files graphically.
  304.     Parameters: The two files to compare
  305.     Returns:    Nothing
  306. ****************************/
  307. void graph_compare(f1, f2)
  308. char *f1, *f2;
  309. {
  310.     int i, j;
  311.     TIME_REC tr, *trp;
  312.     char buf[80];
  313.     long times1[MAXLINES];
  314.     long times2[MAXLINES];
  315.     long tmin = 9999L, tmax = -1;
  316.     int nitems = 0;
  317.     WINDOW *w;
  318.  
  319.     j=0;
  320.     for (i=0; ; i++)
  321.     {
  322.     opentime(f1);
  323.     trp = readtime(i, 0);
  324.     closetime();
  325.     if (trp == NULL)
  326.         break;
  327.     tr = *trp;
  328.  
  329.     opentime(f2);
  330.     trp = readtime(i, 0);
  331.     closetime();
  332.  
  333.     times1[j] = tr.ticks;
  334.     times2[j] = trp->ticks;
  335.     if (tr.ticks <= 0)
  336.         if (trp->ticks <= 0)
  337.         continue;
  338.         else        
  339.         strcpy(tr.desc, trp->desc);   /* use second desc */
  340.  
  341.     sprintf(text[j], "%d) %-32.32s   ~%8.8s  ~%8.8s  ~%8s", j+1, tr.desc+7,
  342.         time_secs(tr.ticks), time_secs(trp->ticks),
  343.         time_pct(trp->ticks, tr.ticks));
  344.     ++j;
  345.     }
  346.  
  347.     w = open_window(1, 1, 25, 80, 7);
  348.     draw_times(times1, times2, text, j, f1, f2);
  349.     close_window(w);
  350. }
  351.  
  352. /**** a n a l y z _ m e n u _ i n i t ****
  353.  **** a n a l y z _ m e n u _ l i n e ****
  354.  **** a n a l y z _ m e n u _ e x i t ****
  355.     Abstract:    These functions are called by scroll_menu during the
  356.         file select function; they display the data corresponding
  357.         to a selected file in a separate window.
  358.     Parameters: As defined in scroll_menu.
  359.     Returns:    Nothing
  360.     Comments:    The menu size and position are hard coded (ugly).
  361. ****************************/
  362. void analyz_menu_init()
  363. {
  364.     w = open_window(5, 18, 12, 77, 0);
  365. }
  366.  
  367. void analyz_menu_line(char *text, int item)
  368. {
  369.     char buf[80];
  370.     TIME_REC *trp;
  371.     int i;
  372.     
  373.     strcpy(buf, text);
  374.     *strchr(buf, '.') = 0;
  375.     if (kbhit())
  376.     return;
  377.     opentime(buf);
  378.     for (i=0; i<8; i++)
  379.     {
  380.     if (kbhit())
  381.     {
  382.         closetime();
  383.         return;
  384.     }
  385.     trp = readtime(0,i);
  386.     _settextposition(i+5,18);
  387.     sprintf(buf, "%-60.60s", trp->desc);
  388.     _outtext(buf);
  389.     }
  390.     closetime();
  391. }
  392. void analyz_menu_exit()
  393. {
  394.     close_window(w);
  395. }
  396.  
  397. /**** u s a g e ****
  398.     Abstract:    Prints user instructions and exits.
  399.     Parameters: None
  400.     Returns:    Never returns.
  401. ****************************/
  402. void usage()
  403. {
  404.     printf("Usage:  HLANALYZ [-pprog -ffile] [-sstandard]\n");
  405.     printf("   Without prog specified, allows comparison of benchmark\n");
  406.     printf("   results.  With it, prog is the program number assigned by\n");
  407.     printf("   HLBENCH, and file and standard are the filenames for the\n");
  408.     printf("   files.  With prog specified, file must be included.\n");
  409.     exit(1);
  410. }
  411.  
  412. /**** m a i n ****
  413. ****************************/
  414. int main(argc, argv)
  415. int argc;
  416. char *argv[];
  417. {
  418.     char *ff = NULL, *fs = NULL, *t;
  419.     int ch = 5;
  420.     char *buf[200];
  421.     char title[50];
  422.     int i;
  423.     int prog = -1;
  424.  
  425.     for (i=1; i<argc; i++)
  426.     {
  427.     if (argv[i][0] != '-')
  428.         usage();
  429.  
  430.     switch(tolower(argv[i][1])) {
  431.     case 'p':
  432.         prog = atoi(argv[i]+2);
  433.         break;
  434.     case 'f':
  435.         if (argv[i][2] != 0)
  436.         ff = strdup(argv[i]+2);
  437.         else
  438.         ff = NULL;
  439.         break;
  440.     case 's':
  441.         if (argv[i][2] != 0)
  442.         fs = strdup(argv[i]+2);
  443.         else
  444.         fs = NULL;
  445.         break;
  446.     case 'a':            /* ignore "batch" & "bench" modes */
  447.     case 'b':
  448.         break;
  449.     default:
  450.         printf("Invalid argument '%s'\n", argv[i]);
  451.     case '?':
  452.         usage();
  453.     }
  454.     }
  455.  
  456.     if (prog >= 0)                /* program number specified */
  457.     {
  458.     if (ff == NULL)
  459.         usage();                /* being used wrong */
  460.     one_test_detail(fs, ff, prog);        /* show results of one test */
  461.     exit(0);
  462.     }
  463.  
  464.     menu_init = analyz_menu_init;        /* set up menu user exits */
  465.     menu_line = analyz_menu_line;
  466.     menu_exit = analyz_menu_exit;
  467.     
  468.     for(;;)
  469.     {
  470.     sprintf(title, " Display and compare %s and %s ",
  471.         (fs == NULL ? "(none)" : fs), (ff == NULL ? "(none)" : ff));
  472.     if ((ch = do_menu(menu, title, 
  473.             "Press Enter to select, ESC to return", ch)) == -1)
  474.         return(0);
  475.     else
  476.     {
  477.         switch (ch) {
  478.         case 0:
  479.         if ((t = select_1_file("*.tim")) != NULL)
  480.         {
  481.             if (fs != NULL)
  482.             free(fs);
  483.             fs = t;
  484.         }
  485.         break;
  486.         case 1:
  487.         if (fs != NULL)
  488.             text_compare(fs, NULL);
  489.         else
  490.         {
  491.             pop_error("You must select a machine first!");
  492.             ch = 0;
  493.         }
  494.         break;
  495.         case 2:
  496.         if ((t = select_1_file("*.tim")) != NULL)
  497.         {    
  498.             if (ff != NULL)
  499.             free(ff);
  500.             ff = t;
  501.         }
  502.         break;
  503.         case 3:
  504.         if (ff != NULL)
  505.             text_compare(ff, NULL);
  506.         else
  507.         {
  508.             pop_error("You must select a machine first!");
  509.             ch = 0;
  510.         }
  511.         break;
  512.         case 4:
  513.         case 5:
  514.         case 6:
  515.         if ((fs == NULL) || (ff == NULL))
  516.         {
  517.             pop_error("You must specify both machines first!");
  518.             if (fs == NULL)
  519.             ch = 0;
  520.             else
  521.             ch = 2;
  522.         }
  523.         else if (ch == 4)
  524.             text_compare(fs, ff);
  525.         else if (ch == 5)
  526.             graph_compare(fs, ff);
  527.         else if (ch == 6)
  528.             print_compare(fs, ff);
  529.         break;
  530.         case 7:
  531.         return(0);
  532.         }
  533.     }
  534.     }
  535. }
  536. 
  537.