allow closing per core files; disable by default per core stats on systems with more than 50 cores
Costa Tsaousis (ktsaou) committed
Sep 9, 2017 at 20:55 UTC
3af5020a038456aaf3bc1f2682aafd2419a66bae
1 file changed
+44
-14
src/proc_stat.c
+44
-14
@@ -31,6 +31,7 @@ struct cpu_chart {
31
struct per_core_single_number_file files[PER_CORE_FILES];
32
};
33
34
+static int keep_per_core_fds_open = CONFIG_BOOLEAN_YES;
35
36
static int read_per_core_files(struct cpu_chart *all_cpu_charts, size_t len, size_t index) {
37
char buf[50 + 1];
@@ -53,17 +54,28 @@ static int read_per_core_files(struct cpu_chart *all_cpu_charts, size_t len, siz
54
55
ssize_t ret = read(f->fd, buf, 50);
56
if(unlikely(ret == -1)) {
57
+ // cannot read that file
58
+
59
error("Cannot read file '%s'", f->filename);
60
close(f->fd);
61
f->fd = -1;
62
continue;
63
}
61
- buf[ret] = '\0';
64
+ else {
65
+ // successful read
66
63
- if(lseek(f->fd, 0, SEEK_SET) == -1) {
64
- error("Cannot seek in file '%s'", f->filename);
65
- close(f->fd);
66
- f->fd = -1;
67
+ // terminate the buffer
68
+ buf[ret] = '\0';
69
+
70
+ if(unlikely(keep_per_core_fds_open != CONFIG_BOOLEAN_YES)) {
71
+ close(f->fd);
72
+ f->fd = -1;
73
+ }
74
+ else if(lseek(f->fd, 0, SEEK_SET) == -1) {
75
+ error("Cannot seek in file '%s'", f->filename);
76
+ close(f->fd);
77
+ f->fd = -1;
78
+ }
79
}
80
81
files_read++;
@@ -110,15 +122,33 @@ int do_proc_stat(int update_every, usec_t dt) {
122
static char *core_throttle_count_filename = NULL, *package_throttle_count_filename = NULL, *scaling_cur_freq_filename = NULL;
123
124
if(unlikely(do_cpu == -1)) {
113
- do_cpu = config_get_boolean("plugin:proc:/proc/stat", "cpu utilization", 1);
114
- do_cpu_cores = config_get_boolean("plugin:proc:/proc/stat", "per cpu core utilization", 1);
115
- do_interrupts = config_get_boolean("plugin:proc:/proc/stat", "cpu interrupts", 1);
116
- do_context = config_get_boolean("plugin:proc:/proc/stat", "context switches", 1);
117
- do_forks = config_get_boolean("plugin:proc:/proc/stat", "processes started", 1);
118
- do_processes = config_get_boolean("plugin:proc:/proc/stat", "processes running", 1);
119
- do_core_throttle_count = config_get_boolean_ondemand("plugin:proc:/proc/stat", "core_throttle_count", CONFIG_BOOLEAN_AUTO);
120
- do_package_throttle_count = config_get_boolean_ondemand("plugin:proc:/proc/stat", "package_throttle_count", CONFIG_BOOLEAN_NO);
121
- do_scaling_cur_freq = config_get_boolean_ondemand("plugin:proc:/proc/stat", "scaling_cur_freq", CONFIG_BOOLEAN_NO);
125
+ do_cpu = config_get_boolean("plugin:proc:/proc/stat", "cpu utilization", CONFIG_BOOLEAN_YES);
126
+ do_cpu_cores = config_get_boolean("plugin:proc:/proc/stat", "per cpu core utilization", CONFIG_BOOLEAN_YES);
127
+ do_interrupts = config_get_boolean("plugin:proc:/proc/stat", "cpu interrupts", CONFIG_BOOLEAN_YES);
128
+ do_context = config_get_boolean("plugin:proc:/proc/stat", "context switches", CONFIG_BOOLEAN_YES);
129
+ do_forks = config_get_boolean("plugin:proc:/proc/stat", "processes started", CONFIG_BOOLEAN_YES);
130
+ do_processes = config_get_boolean("plugin:proc:/proc/stat", "processes running", CONFIG_BOOLEAN_YES);
131
+
132
+ // give sane defaults based on the number of processors
133
+ if(processors > 50) {
134
+ // the system has too many processors
135
+ keep_per_core_fds_open = CONFIG_BOOLEAN_NO;
136
+ do_core_throttle_count = CONFIG_BOOLEAN_NO;
137
+ do_package_throttle_count = CONFIG_BOOLEAN_NO;
138
+ do_scaling_cur_freq = CONFIG_BOOLEAN_NO;
139
+ }
140
+ else {
141
+ // the system has a reasonable number of processors
142
+ keep_per_core_fds_open = CONFIG_BOOLEAN_YES;
143
+ do_core_throttle_count = CONFIG_BOOLEAN_AUTO;
144
+ do_package_throttle_count = CONFIG_BOOLEAN_NO;
145
+ do_scaling_cur_freq = CONFIG_BOOLEAN_NO;
146
+ }
147
+
148
+ keep_per_core_fds_open = config_get_boolean("plugin:proc:/proc/stat", "keep per core files open", keep_per_core_fds_open);
149
+ do_core_throttle_count = config_get_boolean_ondemand("plugin:proc:/proc/stat", "core_throttle_count", do_core_throttle_count);
150
+ do_package_throttle_count = config_get_boolean_ondemand("plugin:proc:/proc/stat", "package_throttle_count", do_package_throttle_count);
151
+ do_scaling_cur_freq = config_get_boolean_ondemand("plugin:proc:/proc/stat", "scaling_cur_freq", do_scaling_cur_freq);
152
153
hash_intr = simple_hash("intr");
154
hash_ctxt = simple_hash("ctxt");