-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselfish_stat.c
98 lines (76 loc) · 1.77 KB
/
selfish_stat.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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include "selfish_rec.h"
#if 0
static void selfish_rec_output(struct selfish_rec *sr,
const char *prefix, int tno,
uint64_t tickspersec)
{
int i;
FILE *fp;
char fn[BUFSIZ];
if (!sr)
return;
snprintf(fn, BUFSIZ, "%s-t%03d.txt", prefix, tno);
fp = fopen(fn, "w");
if (!fp) {
printf("Failed to write to %s\n", fn);
return;
}
fprintf(fp, "# start[usec] duration[usec]\n");
for (i = 0; i < sr->nrecorded; i++) {
uint64_t s, d;
s = sr->detours[i].start - sr->detours[0].start;
d = sr->detours[i].duration;
fprintf(fp, "%lf %lf\n",
(double)s/((double)tickspersec/1000.0/1000.0),
(double)d/((double)tickspersec/1000.0/1000.0));
}
fclose(fp);
}
#endif
static double ticks2usec(struct selfish_data *sd, uint64_t val)
{
double ret;
ret = (double)val / (double)sd->tickspersec;
ret *= 1e+6;
return ret;
}
static void analyze(struct selfish_data *sd, int threadid)
{
int i, n;
double tmp, tmp2;
struct selfish_rec *sr;
sr = sd->srs[threadid];
n = sr->nrecorded;
tmp = 0.0;
for (i = 0; i < n; i++)
tmp += (double)sr->detours[i].duration;
sr->sum = tmp;
sr->mean = tmp / (double)n;
tmp = 0.0;
for (i = 0; i < n; i++) {
tmp2 = (double)sr->detours[i].duration - sr->mean;
tmp += tmp2 * tmp2;
}
sr->sd = sqrt(tmp / (double)n);
}
void report_simple_stat(struct selfish_data *sd)
{
int i;
struct selfish_rec *sr;
printf("# cpuid detour[%%] mean[usec] niterated nrecorded \n");
for (i = 0; i < sd->nth; i++) {
analyze(sd, i);
sr = sd->srs[i];
printf("%2d %lf %lf %lu %d\n", i,
sr->sum * 100.0 / (double)sr->elapsed,
ticks2usec(sd, sr->mean),
sr->niterated,
sr->nrecorded
);
}
}