-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuiltin-stats.c
98 lines (89 loc) · 3.07 KB
/
builtin-stats.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
/*
Copyright (C) 2013
Baptiste Lepers <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "parse.h"
#include "builtin-stats.h"
/*
* Show number of accesses per tid on all cpu to all nodes
* x = cpu, y = node
*/
static rbtree rbtree_stats;
typedef struct tid_stat {
int *samples_per_cpu;
int *remote_samples_per_cpu;
char *app;
int pid;
int last_cpu;
int nb_cpus;
} tid_stat_t;
void stats_init() {
rbtree_stats = rbtree_create();
}
static int stat_tid_cmp(void *a, void *b) {
return ((long)a)-((long)b);
}
void stats_parse(struct s* s) {
tid_stat_t* value = rbtree_lookup(rbtree_stats, (void*)(long)get_tid(s), stat_tid_cmp);
if(!value) {
value = calloc(1, sizeof(*value));
value->app = strdup(get_app(s));
value->pid = get_pid(s);
rbtree_insert(rbtree_stats, (void*)(long)get_tid(s), value, stat_tid_cmp);
value->last_cpu = s->cpu;
value->nb_cpus = 1;
value->remote_samples_per_cpu = calloc(1, sizeof(*value->remote_samples_per_cpu)*max_node*max_cpu);
value->samples_per_cpu = calloc(1, sizeof(*value->samples_per_cpu)*max_cpu + 1);
}
assert(s->cpu < max_cpu);
value->samples_per_cpu[s->cpu]++;
value->samples_per_cpu[max_cpu]++;
if(s->ibs_dc_phys != 0) {
value->remote_samples_per_cpu[phys_to_node(s->ibs_dc_phys)*max_cpu + s->cpu]++;
}
if(value->last_cpu != s->cpu) {
value->last_cpu = s->cpu;
value->nb_cpus++;
}
}
static int stat_tid_print(void *key, void* value) {
int i, j;
tid_stat_t *v = value;
printf("%ld: %5d\t[", (long)key, v->samples_per_cpu[max_cpu]);
for(i = 0; i < max_cpu; i++)
printf("%4d ", v->samples_per_cpu[i]);
printf("]\n");
for(i = 0; i < max_real_node; i++) {
if(i == 0)
printf("%8.8s\t[", v->app);
else if(i == 1)
printf("%8d\t[", v->pid);
else
printf("\t\t[");
for(j = 0; j < max_cpu; j++) {
if(cpu_to_node(j) != i && v->remote_samples_per_cpu[i*max_cpu + j]) {
printf(RED "%4d " RESET, v->remote_samples_per_cpu[i*max_cpu + j]);
} else if(cpu_to_node(j) == i && v->remote_samples_per_cpu[i*max_cpu + j]) {
printf(GREEN "%4d " RESET, v->remote_samples_per_cpu[i*max_cpu + j]);
} else {
printf("%4d ", v->remote_samples_per_cpu[i*max_cpu + j]);
}
}
printf("\n");
}
return 0;
}
void stats_show() {
printf("Different TIDs: %d\n", rbtree_stats->nb_elements);
rbtree_print(rbtree_stats, stat_tid_print);
}