-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclocks.c
127 lines (104 loc) · 2.04 KB
/
clocks.c
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "Header.h"
#include "Clocks.h"
struct clock Clocks[MAX_CLOCKS];
/*************
*
* init_clocks() - Initialize all clocks.
*
*************/
void init_clocks(void)
{
int i;
for (i = 0; i < MAX_CLOCKS; i++)
clock_reset(i);
} /* init_clocks */
/*************
*
* long clock_val(clock_num) - Returns accumulated time in milliseconds.
*
* Clock need not be stopped.
*
*************/
long clock_val(int c)
{
long msec, i, j;
i = Clocks[c].accum_msec;
if (Clocks[c].level == 0)
return(i);
else {
CPU_TIME(msec)
j = msec - Clocks[c].curr_msec;
return(i+j);
}
} /* clock_val */
/*************
*
* clock_reset(clock_num) - Clocks must be reset before being used.
*
*************/
void clock_reset(int c)
{
Clocks[c].accum_msec = 0;
Clocks[c].level = 0;
} /* clock_reset */
/*************
*
* char *get_time() - get a string representation of current date and time
*
*************/
char *get_time(void)
{
long i;
i = time((long *) NULL);
return(asctime(localtime(&i)));
} /* get_time */
/*************
*
* long system_time() - Return system time in milliseconds.
*
*************/
long system_time(void)
{
#ifdef TP_RUSAGE
struct rusage r;
long sec, usec;
getrusage(RUSAGE_SELF, &r);
sec = r.ru_stime.tv_sec;
usec = r.ru_stime.tv_usec;
return((sec * 1000) + (usec / 1000));
#else
return(0);
#endif
} /* system_time */
/*************
*
* long run_time() - Return run time in milliseconds.
*
* This is used instead of the normal clock routines in case
* progam is complied with NO_CLOCK.
*
*************/
long run_time(void)
{
#ifdef TP_RUSAGE
struct rusage r;
long sec, usec;
getrusage(RUSAGE_SELF, &r);
sec = r.ru_utime.tv_sec;
usec = r.ru_utime.tv_usec;
return((sec * 1000) + (usec / 1000));
#else
return(0);
#endif
} /* run_time */
/*************
*
* wall_seconds()
*
*************/
long wall_seconds(void)
{
long i;
i = time((long *) NULL);
return(i);
} /* wall_seconds */