1: # include   <useful.h>
   2: # include   <opsys.h>
   3: # include   <pmon.h>
   4: # include   <sccs.h>
   5: 
   6: SCCSID(@(#)monitor.c	8.1	12/31/84)
   7: 
   8: /*
   9: **  MARKPERF -- mark the performance info in a monitor struct
  10: **
  11: **	At any point, there is a monitor struct representing the
  12: **	current object running.  This is stored in the static
  13: **	variable "curmon".  This call essentially does a "context
  14: **	switch" to the structure passed as the argument.
  15: **
  16: **	Parameters:
  17: **		mbuf -- a pointer to a monitor struct.
  18: **
  19: **	Returns:
  20: **		a pointer to the previous monitor struct.
  21: **
  22: **	Side Effects:
  23: **		none
  24: */
  25: 
  26: # define    HZ  60  /* speed of clock in ticks/second */
  27: 
  28: struct tbuffer
  29: {
  30: # ifdef xV7_UNIX
  31:     long    tms_utime;
  32:     long    tms_stime;
  33: # else
  34:     short   tms_utime;
  35:     short   tms_stime;
  36: # endif
  37:     long    tms_cutime;
  38:     long    tms_cstime;
  39: };
  40: 
  41: struct monitor *
  42: markperf(mbuf)
  43: register struct monitor *mbuf;
  44: {
  45:     struct tbuffer      tbuf;
  46:     register long       ut;
  47:     register long       st;
  48:     static struct tbuffer   baset;
  49:     static struct monitor   *curmon;
  50:     register struct monitor *oldmon;
  51: 
  52:     times(&tbuf);
  53: 
  54:     ut = tbuf.tms_utime + tbuf.tms_cutime - baset.tms_utime - baset.tms_cutime;
  55:     st = tbuf.tms_stime + tbuf.tms_cstime - baset.tms_stime - baset.tms_cstime;
  56:     oldmon = curmon;
  57:     if (oldmon != NULL)
  58:     {
  59:         oldmon->mon_utime += ut;
  60:         oldmon->mon_stime += st;
  61:     }
  62:     curmon = mbuf;
  63:     bmove(&tbuf, &baset, sizeof baset);
  64:     return (oldmon);
  65: }
  66: /*
  67: **  ADD_MON -- "add" two monitor structs
  68: **
  69: **	The logical sum of two monitor structs is created
  70: **
  71: **	Parameters:
  72: **		a -- the first monitor struct
  73: **		b -- the second monitor struct; gets the result.
  74: **
  75: **	Returns:
  76: **		none (value is returned through b)
  77: **
  78: **	Side Effects:
  79: **		none.
  80: */
  81: 
  82: add_mon(a, b)
  83: register struct monitor *a;
  84: register struct monitor *b;
  85: {
  86:     b->mon_utime += a->mon_utime;
  87:     b->mon_stime += a->mon_stime;
  88: }
  89: /*
  90: **  CVT_TIME -- convert time for output
  91: **
  92: **	Converts a time in ticks to a string (in seconds) for
  93: **	printing.
  94: **
  95: **	Parameters:
  96: **		t -- time in ticks
  97: **
  98: **	Returns:
  99: **		pointer to string suitable for printing or framing.
 100: **
 101: **	Side Effects:
 102: **		previous return value is clobbered.
 103: */
 104: 
 105: char *
 106: cvt_time(t)
 107: long    t;
 108: {
 109:     static char buf[30];
 110: 
 111:     sprintf(buf, "%.3f", ((float) t) / ((float) HZ));
 112:     return (buf);
 113: }

Defined functions

add_mon defined in line 82; used 2 times
cvt_time defined in line 105; used 2 times

Defined struct's

tbuffer defined in line 28; used 4 times

Defined macros

HZ defined in line 26; used 1 times
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 815
Valid CSS Valid XHTML 1.0 Strict