-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrtimer.c
More file actions
executable file
·75 lines (64 loc) · 1.93 KB
/
Copy pathrtimer.c
File metadata and controls
executable file
·75 lines (64 loc) · 1.93 KB
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
/*
Laura Toma
*/
#include <sys/time.h>
#include <sys/resource.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <assert.h>
#include "rtimer.h"
char *
rt_sprint(char *buf, Rtimer rt) {
if(rt_w_useconds(rt) == 0) {
sprintf(buf, "[%4.2fu (%.0f%%) %4.2fs (%.0f%%) %4.2f %.1f%%]",
0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
} else {
sprintf(buf, "[%4.2fu (%.0f%%) %4.2fs (%.0f%%) %4.2f %.1f%%]",
rt_u_useconds(rt)/1000000,
100.0*rt_u_useconds(rt)/rt_w_useconds(rt),
rt_s_useconds(rt)/1000000,
100.0*rt_s_useconds(rt)/rt_w_useconds(rt),
rt_w_useconds(rt)/1000000,
100.0*(rt_u_useconds(rt)+rt_s_useconds(rt)) / rt_w_useconds(rt));
}
return buf;
}
/* prints the timer divided by k --- used when k experiments kept in
the same timer */
char *
rt_sprint_average(char *buf, Rtimer rt, int k) {
assert(k>0);
if(rt_w_useconds(rt) == 0) {
sprintf(buf, "[%4.2fu (%.0f%%) %4.2fs (%.0f%%) %4.2f %.1f%%]",
0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
} else {
sprintf(buf, "[%4.2fu (%.0f%%) %4.2fs (%.0f%%) %4.2f %.1f%%]",
rt_u_useconds(rt)/1000000/k,
100.0*rt_u_useconds(rt)/rt_w_useconds(rt),
rt_s_useconds(rt)/1000000/k,
100.0*rt_s_useconds(rt)/rt_w_useconds(rt),
rt_w_useconds(rt)/1000000/k,
100.0*(rt_u_useconds(rt)+rt_s_useconds(rt)) / rt_w_useconds(rt));
}
return buf;
}
/* to be called after rt_stop_and_accumulate to print the total time */
/* assumes rt.tu_usec, rt.ts_usec, rt.tw_usec have been computed
*/
char *
rt_sprint_total(char *buf, Rtimer rt) {
if(rt.tw_usec == 0) {
sprintf(buf, "[%4.2fu (%.0f%%) %4.2fs (%.0f%%) %4.2f %.1f%%]",
0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
} else {
sprintf(buf, "[%4.2fu (%.0f%%) %4.2fs (%.0f%%) %4.2f %.1f%%]",
rt.tu_usec/1000000,
100.0*rt.tu_usec/rt.tw_usec,
rt.ts_usec/1000000,
100.0*rt.ts_usec/rt.tw_usec,
rt.tw_usec/1000000,
100.0*(rt.tu_usec+rt.ts_usec) / rt.tw_usec);
}
return buf;
}