-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharc_snapshot.c
110 lines (100 loc) · 2.81 KB
/
arc_snapshot.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
#include <assert.h>
#include <fcntl.h>
#include <linux/fs.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <regex.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
typedef struct {
int hits;
int misses;
int demand_data_hits;
int demand_data_misses;
int demand_metadata_hits;
int demand_metadata_misses;
int prefetch_data_hits;
int prefetch_data_misses;
int prefetch_metadata_hits;
int prefetch_metadata_misses;
int mru_hits;
int mru_ghost_hits;
int mfu_hits;
int mfu_ghost_hits;
int deleted;
int mutex_miss;
int access_skip;
int evict_skip;
int evict_not_enough;
int evict_l2_cached;
int evict_l2_eligible;
int evict_l2_eligible_mfu;
int evict_l2_eligible_mru;
int evict_l2_ineligible;
int evict_l2_skip;
int hash_elements;
int hash_elements_max;
int hash_collisions;
int hash_chains;
int hash_chain_max;
int p;
int c;
int c_min;
int c_max;
} arc_snapshot;
arc_snapshot *get_kstat_snapshot() {
int type;
int value;
char property[100] = {0};
arc_snapshot *stats = (arc_snapshot *)malloc(sizeof(arc_snapshot));
if (stats == NULL){
perror("couldnt allocate memory: ");
exit(1);
}
arc_value *values[150] = {NULL};
FILE *arcstat_endpoint = fopen("/proc/spl/kstat/zfs/arcstats", "r");
if (arcstat_endpoint == NULL) {
perror("Could not open /proc/spl/kstat/zfs/arcstats arcstat: ");
exit(1);
}
int index = 0;
// skip thei first two trash lines
fscanf(arcstat_endpoint, "%*[^\n]\n");
fscanf(arcstat_endpoint, "%*[^\n]\n");
while (EOF !=
fscanf(arcstat_endpoint, "%s %d %d", &property, &type, &value)) {
values[index] = (arc_value *)malloc(sizeof(arc_value));
if (values[index] == NULL){
perror("couldnt allocate memory: ");
exit(1);
}
values[index]->value = value;
strcpy(values[index]->name, property);
index++;
}
stats->c = get_list_value("c", values);
stats->hits = get_list_value("hits", values);
stats->misses = get_list_value("misses", values);
stats->demand_data_hits = get_list_value("demand_data_hits", values);
stats->demand_data_misses = get_list_value("demand_data_misses", values);
stats->demand_metadata_hits = get_list_value("demand_metadata_hits", values);
stats->demand_metadata_misses =
get_list_value("demand_metadata_misses", values);
stats->prefetch_data_hits = get_list_value("prefetch_data_hits", values);
stats->prefetch_data_misses = get_list_value("prefetch_data_misses", values);
// stats->miss_p= get_list_value();
// stats->dhit= get_list_value();
// stats->dmis= get_list_value();
fclose(arcstat_endpoint);
return stats;
}