forked from paravmellanox/rtool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathts.h
More file actions
81 lines (67 loc) · 1.59 KB
/
Copy pathts.h
File metadata and controls
81 lines (67 loc) · 1.59 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
76
77
78
79
80
81
#ifndef RDMAIO_TS_H
#define RDMAIO_TS_H
#include <time.h>
#include <sys/time.h>
struct ts_time {
long long start, end, latency;
};
struct time_stats {
struct ts_time total;
long long min, max, avg;
long long total_latency;
long long count;
};
static inline void ts_log_start_time(struct ts_time *s)
{
s->start = current_time();
}
static inline void ts_log_end_time(struct ts_time *s)
{
s->end = current_time();
s->latency = s->end - s->start;
}
static inline void
update_min(const struct ts_time *stat, struct time_stats *t)
{
if (stat->latency < t->min)
t->min = stat->latency;
}
static inline void
update_max(const struct ts_time *stat, struct time_stats *t)
{
if (stat->latency > t->max)
t->max = stat->latency;
}
static inline void
update_avg(const struct ts_time *stat, struct time_stats *t)
{
long long avg = t->avg;
long long old_sum = avg * t->count;
long long new_avg = (old_sum + stat->latency) / (t->count + 1);
t->avg = new_avg;
}
static inline void
ts_update_time_stats(const struct ts_time *stat, struct time_stats *t)
{
update_min(stat, t);
update_max(stat, t);
update_avg(stat, t);
t->total_latency += stat->latency;
t->count++;
}
static inline void ts_print_lat_stats(const struct time_stats *s, char *str)
{
printf("%s lat: ", str);
printf(" min="); print_time(s->min); printf(",");
printf(" max="); print_time(s->max); printf(",");
printf(" avg="); print_time(s->avg); printf(",");
printf(" tot="); print_time(s->total_latency);
printf("\n");
}
static inline void ts_init(struct time_stats *t)
{
t->min = LLONG_MAX;
t->max = LLONG_MIN;
t->count = 0;
}
#endif