home *** CD-ROM | disk | FTP | other *** search
- /*
- * Time taking functions for use with the benchmarks.
- *
- * Martin Houston. Apricot Advanced Technology. 9/1/87
- */
-
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/times.h>
- #include "timer.h"
-
- long times();
-
- static struct tms starttime, endtime;
- static long startticks, endticks;
- static int HZ = 50; /* system HZ value */
-
- /*
- * Function to set up the process timer sub-system.
- *
- * HZ value in environment overrides 50 Hz default if present.
- * Assumes that HZ values < 50 are never encountered.
- *
- */
-
- void init_timer()
- {
- int hz;
-
- if((hz = atoi(getenv("HZ="))) > HZ)
- HZ = hz; /* use HZ value from the environment */
- }
-
- /*
- * Function to start time accounting.
- *
- * A return value of -1 indicates that the time operation failed
- * to start. the time is returned for correct operation.
- */
-
- int start_timer()
- {
-
- return(startticks = times(&starttime));
- }
-
- /*
- * Function to stop time accounting and make a report on elapsed time.
- *
- * A return value of -1 indicates that the time operation failed
- * to start. the time is returned for correct operation.
- */
-
- int print_elapsed(message, report_type)
- char *message;
- int report_type;
- {
- long secs, ms, rms;
-
- endticks = times(&endtime);
- if(endticks > 0L) /* timeing whent ok */
- {
- ms = (endticks - startticks) * (1000L / HZ);
- secs = (endticks - startticks) / HZ;
- rms = ms - (secs * 1000);
- if(report_type & REALMS)
- {
- fprintf(stdout,"%s: real %ld ms\n", message, ms);
- }
- if(report_type & REALSEC)
- {
- fprintf(stdout,"%s: real %ld sec %ld ms\n",
- message, secs, rms);
- }
- if(report_type & REALMIN)
- {
- fprintf(stdout,"%s: real %ld min %ld sec %ld ms\n",
- message,
- secs / 60L, secs % 60L, rms);
- }
-
- ms = (endtime.tms_utime - starttime.tms_utime) * (1000L / HZ);
- secs = (endtime.tms_utime - starttime.tms_utime) / HZ;
- rms = ms - (secs * 1000);
-
- if(report_type & USERMS)
- {
- fprintf(stdout,"%s: user %ld ms\n", message, ms);
- }
- if(report_type & USERSEC)
- {
- fprintf(stdout,"%s: user %ld sec %ld ms\n",
- message, secs, rms);
- }
- if(report_type & USERMIN)
- {
- fprintf(stdout,"%s: user %ld min %ld sec %ld ms\n",
- message,
- secs / 60L, secs % 60L, rms);
- }
-
- ms = (endtime.tms_stime - starttime.tms_stime) * (1000L / HZ);
- secs = (endtime.tms_stime - starttime.tms_stime) / HZ;
- rms = ms - (secs * 1000);
-
- if(report_type & SYSTEMMS)
- {
- fprintf(stdout,"%s: system %ld ms\n", message, ms);
- }
- if(report_type & SYSTEMSEC)
- {
- fprintf(stdout,"%s: system %ld sec %ld ms\n",
- message, secs, rms);
- }
- if(report_type & SYSTEMMIN)
- {
- fprintf(stdout,"%s: system %ld min %ld sec %ld ms\n",
- message,
- secs / 60L, secs % 60L, rms);
- }
- }
- else
- fprintf(stdout,"%s: timer failed!\n", message);
- }
-