File: timers.c

package info (click to toggle)
smlnj-runtime 110.44-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,968 kB
  • ctags: 5,368
  • sloc: ansic: 24,674; asm: 4,195; makefile: 1,353; sh: 91
file content (77 lines) | stat: -rw-r--r-- 1,540 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* timers.c
 *
 * COPYRIGHT (c) 1995 by AT&T Bell Laboratories.
 *
 * OS independent timer routines; these rely on a OS dependent implementation
 * of the following function:
 *
 *	void GetCPUTime (Time_t *user_t, Time_t *sys_t);
 */

#include "ml-base.h"
#include "vproc-state.h"
#include "ml-timer.h"


/* ResetTimers:
 *
 * Clear the GC timers.
 */
void ResetTimers (vproc_state_t *vsp)
{
    vsp->vp_gcTime->seconds = 0;
    vsp->vp_gcTime->uSeconds = 0;

} /* end of ResetTimers. */


/* StartGCTimer:
 */
void StartGCTimer (vproc_state_t *vsp)
{
    GetCPUTime (vsp->vp_gcTime0, NIL(Time_t *));

} /* end of StartGCTimer */


/* StopGCTimer:
 *
 * Stop the garbage collection timer and update the cumulative garbage collection
 * time.  If time is not NIL, then return the time (in ms.) spent since
 * the start of the GC.
 */
void StopGCTimer (vproc_state_t *vsp, long *time)
{
    int			sec, usec;
    Time_t		t1;
    Time_t		*gt0 = vsp->vp_gcTime0;
    Time_t		*gt = vsp->vp_gcTime;

    GetCPUTime (&t1, NIL(Time_t *));

    sec = t1.seconds - gt0->seconds;
    usec = t1.uSeconds - gt0->uSeconds;

    if (time != NIL(long *)) {
	if (usec < 0) {
	    sec--; usec += 1000000;
	}
	else if (usec > 1000000) {
	    sec++; usec -= 1000000;
	}
	*time = (usec/1000 + sec*1000);
    }

    sec = gt->seconds + sec;
    usec = gt->uSeconds + usec;
    if (usec < 0) {
	sec--; usec += 1000000;
    }
    else if (usec > 1000000) {
	sec++; usec -= 1000000;
    }
    gt->seconds = sec;
    gt->uSeconds = usec;

} /* end of StopGCTimer */