code optimizations; added temperature charts.d plugin
Costa Tsaousis (ktsaou) committed
Oct 3, 2015 at 12:56 UTC
71b72e4f59b129ced0a1d15e5ce3b21370edfbbd
29 files changed
+282
-213
charts.d/example.chart.sh
+10
-2
@@ -1,7 +1,13 @@
1
#!/bin/sh
2
3
+# if this chart is called X.chart.sh, then all functions and global variables
4
+# must start with X_
5
+
6
+# _update_every is a special variable - it holds the number of seconds
7
+# between the calls of the _update() function
8
example_update_every=
9
10
+# _check is called once, to find out if this chart should be enabled or not
11
example_check() {
12
# this should return:
13
# - 0 to enable the chart
@@ -10,9 +16,10 @@ example_check() {
16
return 0
17
}
18
19
+# _create is called once, to create the charts
20
example_create() {
14
-# create the chart with 3 dimensions
15
-cat <<EOF
21
+ # create the chart with 3 dimensions
22
+ cat <<EOF
23
CHART example.random '' "Random Numbers Stacked Chart" "% of random numbers" random random stacked 5000 $example_update_every
24
DIMENSION random1 '' percentage-of-absolute-row 1 1
25
DIMENSION random2 '' percentage-of-absolute-row 1 1
@@ -22,6 +29,7 @@ EOF
29
return 0
30
}
31
32
+# _update is called continiously, to collect the values
33
example_update() {
34
# the first argument to this function is the microseconds since last update
35
# pass this parameter to the BEGIN statement (see bellow).
charts.d/pi.chart.sh
-11
@@ -26,17 +26,6 @@ pi_update() {
26
# for each dimension
27
# remember: KEEP IT SIMPLE AND SHORT
28
29
- # 1. wget the counters page from squid
30
- # 2. sed to remove spaces; replace . with _; remove spaces around =; prepend each line with: local squid_
31
- # 3. egrep lines starting with:
32
- # local squid_client_http_ then one or more of these a-z 0-9 _ then = and one of more of 0-9
33
- # local squid_server_all_ then one or more of these a-z 0-9 _ then = and one of more of 0-9
34
- # 4. then execute this as a script with the eval
35
- #
36
- # be very carefull with eval:
37
- # prepare the script and always grep at the end the lines that are usefull, so that
38
- # even if something goes wrong, no other code can be executed
39
-
29
local cpuTemp=$(cat /sys/class/thermal/thermal_zone0/temp)
30
local cpuSpeed=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq)
31
charts.d/squid.chart.sh
+2
-2
@@ -6,7 +6,7 @@ squid_url="cache_object://$squid_host:$squid_port/counters"
6
squid_update_every=5
7
8
squid_get_stats() {
9
-nc $squid_host $squid_port <<EOF
9
+ nc $squid_host $squid_port <<EOF
10
GET $squid_url HTTP/1.0
11
Host: $squid_host:$squid_port
12
Accept: */*
@@ -63,7 +63,7 @@ squid_update() {
63
# for each dimension
64
# remember: KEEP IT SIMPLE AND SHORT
65
66
- # 1. wget the counters page from squid
66
+ # 1. get the counters page from squid
67
# 2. sed to remove spaces; replace . with _; remove spaces around =; prepend each line with: local squid_
68
# 3. egrep lines starting with:
69
# local squid_client_http_ then one or more of these a-z 0-9 _ then = and one of more of 0-9
plugins.d/charts.d.plugin
+43
-10
@@ -45,7 +45,7 @@ do
45
if [ -f "$chartsd/$1.chart.sh" ]
46
then
47
debug=1
48
- chart_only="`echo $1.chart.sh | sed "s/\.chart\.sh$//g"`"
48
+ chart_only="$( echo $1.chart.sh | sed "s/\.chart\.sh$//g" )"
49
shift
50
continue
51
fi
@@ -53,7 +53,7 @@ do
53
if [ -f "$chartsd/$1" ]
54
then
55
debug=1
56
- chart_only="`echo $1 | sed "s/\.chart\.sh$//g"`"
56
+ chart_only="$( echo $1 | sed "s/\.chart\.sh$//g" )"
57
shift
58
continue
59
fi
@@ -61,7 +61,7 @@ do
61
if [ -f "$1" ]
62
then
63
debug=1
64
- chart_only="`basename "$1" | sed "s/\.chart\.sh$//g"`"
64
+ chart_only="$( basename "$1" | sed "s/\.chart\.sh$//g" )"
65
shift
66
continue
67
fi
@@ -127,7 +127,7 @@ loopsleepms() {
127
}
128
# if found and included, this file overwrites loopsleepms()
129
# with a high resolution timer function for precise looping.
130
-. "`dirname $0`/loopsleepms.sh.inc"
130
+. "$( dirname $0 )/loopsleepms.sh.inc"
131
132
133
# -----------------------------------------------------------------------------
@@ -143,7 +143,7 @@ all_enabled_charts() {
143
144
# find all enabled charts
145
146
- for chart in `all_charts`
146
+ for chart in $( all_charts )
147
do
148
eval "enabled=\$$chart"
149
if [ "$enabled" = "yes" ]
@@ -158,21 +158,21 @@ all_enabled_charts() {
158
for chart in $charts
159
do
160
# check the enabled charts
161
- local check="`cat "$chartsd/$chart.chart.sh" | sed "s/^ \+//g" | grep "^$chart$charts_check()"`"
161
+ local check="$( cat "$chartsd/$chart.chart.sh" | sed "s/^ \+//g" | grep "^$chart$charts_check()" )"
162
if [ -z "$check" ]
163
then
164
echo >&2 "charts.d: chart '$chart' does not seem to have a $chart$charts_check() function. Disabling it."
165
continue
166
fi
167
168
- local create="`cat "$chartsd/$chart.chart.sh" | sed "s/^ \+//g" | grep "^$chart$charts_create()"`"
168
+ local create="$( cat "$chartsd/$chart.chart.sh" | sed "s/^ \+//g" | grep "^$chart$charts_create()" )"
169
if [ -z "$create" ]
170
then
171
echo >&2 "charts.d: chart '$chart' does not seem to have a $chart$charts_create() function. Disabling it."
172
continue
173
fi
174
175
- local update="`cat "$chartsd/$chart.chart.sh" | sed "s/^ \+//g" | grep "^$chart$charts_update()"`"
175
+ local update="$( cat "$chartsd/$chart.chart.sh" | sed "s/^ \+//g" | grep "^$chart$charts_update()" )"
176
if [ -z "$update" ]
177
then
178
echo >&2 "charts.d: chart '$chart' does not seem to have a $chart$charts_update() function. Disabling it."
@@ -182,7 +182,7 @@ all_enabled_charts() {
182
# check its config
183
if [ -f "$confd/$chart.conf" ]
184
then
185
- if [ ! -z "`cat "$confd/$chart.conf" | sed "s/^ \+//g" | grep -v "^$" | grep -v "^#" | grep -v "^$chart$charts_undescore"`" ]
185
+ if [ ! -z "$( cat "$confd/$chart.conf" | sed "s/^ \+//g" | grep -v "^$" | grep -v "^#" | grep -v "^$chart$charts_undescore" )" ]
186
then
187
echo >&2 "charts.d: chart's $chart config $confd/$chart.conf should only have lines starting with $chart$charts_undescore . Disabling it."
188
continue
@@ -208,7 +208,7 @@ all_enabled_charts() {
208
209
suffix_update_every="_update_every"
210
active_charts=
211
-for chart in `all_enabled_charts`
211
+for chart in $( all_enabled_charts )
212
do
213
. "$chartsd/$chart.chart.sh"
214
@@ -264,6 +264,39 @@ then
264
exit 0
265
fi
266
267
+# -----------------------------------------------------------------------------
268
+# create temp dir
269
+
270
+TMP_DIR=
271
+chartsd_cleanup() {
272
+ if [ ! -z "$TMP_DIR" -a -d "$TMP_DIR" ]
273
+ then
274
+ echo >&2 "charts.d: cleaning up temporary directory $TMP_DIR ..."
275
+ rm -rf "$TMP_DIR"
276
+ fi
277
+ exit 0
278
+}
279
+trap chartsd_cleanup EXIT
280
+trap chartsd_cleanup SIGHUP
281
+trap chartsd_cleanup INT
282
+
283
+if [ $UID = "0" ]
284
+then
285
+ TMP_DIR="$( mktemp -d /var/run/netdata-charts.d-XXXXXXXXXX )"
286
+else
287
+ TMP_DIR="$( mktemp -d /tmp/.netdata-charts.d-XXXXXXXXXX )"
288
+fi
289
+
290
+# -----------------------------------------------------------------------------
291
+# library functions
292
+
293
+fixid() {
294
+ echo "$*" |\
295
+ tr -c "[A-Z][a-z][0-9]" "_" |\
296
+ sed -e "s|^_\+||g" -e "s|_\+$||g" -e "s|_\+|_|g" |\
297
+ tr "[A-Z]" "[a-z]"
298
+}
299
+
300
301
# -----------------------------------------------------------------------------
302
# create charts
src/common.h
+10
@@ -16,4 +16,14 @@ extern int savememory(const char *filename, void *mem, unsigned long size);
16
17
extern int fd_is_valid(int fd);
18
19
+#ifdef __GNUC__
20
+// gcc branch optimization
21
+// #warning "Using GCC branch optimizations"
22
+#define likely(x) __builtin_expect(!!(x), 1)
23
+#define unlikely(x) __builtin_expect(!!(x), 0)
24
+#else
25
+#define likely(x) (x)
26
+#define unlikely(x) (x)
27
+#endif
28
+
29
#endif /* NETDATA_COMMON_H */
src/config.c
+2
-2
@@ -230,7 +230,7 @@ int load_config(char *filename, int overwrite_used)
230
231
if(!cv) cv = config_value_create(co, name, value);
232
else {
233
- if((cv->flags & CONFIG_VALUE_USED && overwrite_used) || !(cv->flags & CONFIG_VALUE_USED)) {
233
+ if(((cv->flags & CONFIG_VALUE_USED) && overwrite_used) || !(cv->flags & CONFIG_VALUE_USED)) {
234
debug(D_CONFIG, "Overwriting '%s/%s'.", line, co->name, cv->name);
235
free(cv->value);
236
cv->value = strdup(value);
@@ -266,7 +266,7 @@ char *config_get(const char *section, const char *name, const char *default_valu
266
}
267
cv->flags |= CONFIG_VALUE_USED;
268
269
- if(cv->flags & CONFIG_VALUE_LOADED || cv->flags & CONFIG_VALUE_CHANGED) {
269
+ if((cv->flags & CONFIG_VALUE_LOADED) || (cv->flags & CONFIG_VALUE_CHANGED)) {
270
// this is a loaded value from the config file
271
// if it is different that the default, mark it
272
if(!(cv->flags & CONFIG_VALUE_CHECKED)) {
src/global_statistics.c
+1
@@ -1,5 +1,6 @@
1
#include <pthread.h>
2
3
+#include "common.h"
4
#include "global_statistics.h"
5
6
struct global_statistics global_statistics = { 0ULL, 0ULL, 0ULL, 0ULL };
src/log.c
+2
@@ -6,6 +6,8 @@
6
#include <stdlib.h>
7
8
#include "log.h"
9
+#include "common.h"
10
+
11
12
// ----------------------------------------------------------------------------
13
// LOG
src/log.h
+1
-1
@@ -42,7 +42,7 @@ extern int access_log_syslog;
42
extern int error_log_syslog;
43
extern int output_log_syslog;
44
45
-#define debug(type, args...) do { if(!silent && debug_flags & type) debug_int(__FILE__, __FUNCTION__, __LINE__, ##args); } while(0)
45
+#define debug(type, args...) do { if(unlikely(!silent && (debug_flags & type))) debug_int(__FILE__, __FUNCTION__, __LINE__, ##args); } while(0)
46
#define info(args...) info_int(__FILE__, __FUNCTION__, __LINE__, ##args)
47
#define error(args...) error_int(__FILE__, __FUNCTION__, __LINE__, ##args)
48
#define fatal(args...) fatal_int(__FILE__, __FUNCTION__, __LINE__, ##args)
src/main.c
+1
@@ -9,6 +9,7 @@
9
#include <sys/types.h>
10
#include <sys/wait.h>
11
12
+#include "common.h"
13
#include "log.h"
14
#include "daemon.h"
15
#include "web_server.h"
src/plugins_d.c
+76
-76
@@ -37,10 +37,10 @@ static void pluginsd_split_words(char *str, char **words, int max_words) {
37
int i = 0;
38
39
// skip all white space
40
- while(pluginsd_space(*s)) s++;
40
+ while(unlikely(pluginsd_space(*s))) s++;
41
42
// check for quote
43
- if(*s == '\'' || *s == '"') {
43
+ if(unlikely(*s == '\'' || *s == '"')) {
44
quote = *s; // remember the quote
45
s++; // skip the quote
46
}
@@ -49,40 +49,40 @@ static void pluginsd_split_words(char *str, char **words, int max_words) {
49
words[i++] = s;
50
51
// while we have something
52
- while(*s) {
52
+ while(likely(*s)) {
53
// if it is escape
54
- if(*s == '\\' && s[1]) {
54
+ if(unlikely(*s == '\\' && s[1])) {
55
s += 2;
56
continue;
57
}
58
59
// if it is quote
60
- else if(*s == quote) {
60
+ else if(unlikely(*s == quote)) {
61
quote = 0;
62
*s = ' ';
63
continue;
64
}
65
66
// if it is a space
67
- else if(quote == 0 && pluginsd_space(*s)) {
67
+ else if(unlikely(quote == 0 && pluginsd_space(*s))) {
68
69
// terminate the word
70
*s++ = '\0';
71
72
// skip all white space
73
- while(pluginsd_space(*s)) s++;
73
+ while(likely(pluginsd_space(*s))) s++;
74
75
// check for quote
76
- if(*s == '\'' || *s == '"') {
76
+ if(unlikely(*s == '\'' || *s == '"')) {
77
quote = *s; // remember the quote
78
s++; // skip the quote
79
}
80
81
// if we reached the end, stop
82
- if(!*s) break;
82
+ if(unlikely(!*s)) break;
83
84
// store the next word
85
- if(i < max_words) words[i++] = s;
85
+ if(likely(i < max_words)) words[i++] = s;
86
else break;
87
}
88
@@ -91,7 +91,7 @@ static void pluginsd_split_words(char *str, char **words, int max_words) {
91
}
92
93
// terminate the words
94
- while(i < max_words) words[i++] = NULL;
94
+ while(likely(i < max_words)) words[i++] = NULL;
95
}
96
97
@@ -118,9 +118,9 @@ void *pluginsd_worker_thread(void *arg)
118
uint32_t STOPPING_WAKE_ME_UP_PLEASE_HASH = simple_hash("STOPPING_WAKE_ME_UP_PLEASE");
119
#endif
120
121
- while(1) {
121
+ while(likely(1)) {
122
FILE *fp = mypopen(cd->cmd, &cd->pid);
123
- if(!fp) {
123
+ if(unlikely(!fp)) {
124
error("Cannot popen(\"%s\", \"r\").", cd->cmd);
125
break;
126
}
@@ -132,14 +132,14 @@ void *pluginsd_worker_thread(void *arg)
132
char *s;
133
uint32_t hash;
134
135
- while(fgets(line, PLUGINSD_LINE_MAX, fp) != NULL) {
135
+ while(likely(fgets(line, PLUGINSD_LINE_MAX, fp) != NULL)) {
136
line[PLUGINSD_LINE_MAX] = '\0';
137
138
// debug(D_PLUGINSD, "PLUGINSD: %s: %s", cd->filename, line);
139
140
pluginsd_split_words(line, words, MAX_WORDS);
141
s = words[0];
142
- if(!s || !*s) {
142
+ if(unlikely(!s || !*s)) {
143
// debug(D_PLUGINSD, "PLUGINSD: empty line");
144
continue;
145
}
@@ -148,36 +148,36 @@ void *pluginsd_worker_thread(void *arg)
148
149
hash = simple_hash(s);
150
151
- if(hash == SET_HASH && !strcmp(s, "SET")) {
151
+ if(likely(hash == SET_HASH && !strcmp(s, "SET"))) {
152
char *dimension = words[1];
153
char *value = words[2];
154
155
- if(!dimension || !*dimension) {
155
+ if(unlikely(!dimension || !*dimension)) {
156
error("PLUGINSD: '%s' is requesting a SET on chart '%s', like this: 'SET %s = %s'. Disabling it.", cd->fullfilename, st->id, dimension?dimension:"<nothing>", value?value:"<nothing>");
157
cd->enabled = 0;
158
killpid(cd->pid, SIGTERM);
159
break;
160
}
161
162
- if(!value || !*value) value = "0";
162
+ if(unlikely(!value || !*value)) value = "0";
163
164
- if(!st) {
164
+ if(unlikely(!st)) {
165
error("PLUGINSD: '%s' is requesting a SET on dimension %s with value %s, without a BEGIN. Disabling it.", cd->fullfilename, dimension, value);
166
cd->enabled = 0;
167
killpid(cd->pid, SIGTERM);
168
break;
169
}
170
171
- if(st->debug) debug(D_PLUGINSD, "PLUGINSD: '%s' is setting dimension %s/%s to %s", cd->fullfilename, st->id, dimension, value);
171
+ if(unlikely(st->debug)) debug(D_PLUGINSD, "PLUGINSD: '%s' is setting dimension %s/%s to %s", cd->fullfilename, st->id, dimension, value);
172
rrddim_set(st, dimension, atoll(value));
173
174
count++;
175
}
176
- else if(hash == BEGIN_HASH && !strcmp(s, "BEGIN")) {
176
+ else if(likely(hash == BEGIN_HASH && !strcmp(s, "BEGIN"))) {
177
char *id = words[1];
178
char *microseconds_txt = words[2];
179
180
- if(!id) {
180
+ if(unlikely(!id)) {
181
error("PLUGINSD: '%s' is requesting a BEGIN without a chart id. Disabling it.", cd->fullfilename);
182
cd->enabled = 0;
183
killpid(cd->pid, SIGTERM);
@@ -185,45 +185,45 @@ void *pluginsd_worker_thread(void *arg)
185
}
186
187
st = rrdset_find(id);
188
- if(!st) {
188
+ if(unlikely(!st)) {
189
error("PLUGINSD: '%s' is requesting a BEGIN on chart '%s', which does not exist. Disabling it.", cd->fullfilename, id);
190
cd->enabled = 0;
191
killpid(cd->pid, SIGTERM);
192
break;
193
}
194
195
- if(st->counter_done) {
195
+ if(likely(st->counter_done)) {
196
unsigned long long microseconds = 0;
197
if(microseconds_txt && *microseconds_txt) microseconds = strtoull(microseconds_txt, NULL, 10);
198
if(microseconds) rrdset_next_usec(st, microseconds);
199
else rrdset_next_plugins(st);
200
}
201
}
202
- else if(hash == END_HASH && !strcmp(s, "END")) {
203
- if(!st) {
202
+ else if(likely(hash == END_HASH && !strcmp(s, "END"))) {
203
+ if(unlikely(!st)) {
204
error("PLUGINSD: '%s' is requesting an END, without a BEGIN. Disabling it.", cd->fullfilename);
205
cd->enabled = 0;
206
killpid(cd->pid, SIGTERM);
207
break;
208
}
209
210
- if(st->debug) debug(D_PLUGINSD, "PLUGINSD: '%s' is requesting a END on chart %s", cd->fullfilename, st->id);
210
+ if(unlikely(st->debug)) debug(D_PLUGINSD, "PLUGINSD: '%s' is requesting a END on chart %s", cd->fullfilename, st->id);
211
212
rrdset_done(st);
213
st = NULL;
214
}
215
- else if(hash == FLUSH_HASH && !strcmp(s, "FLUSH")) {
215
+ else if(likely(hash == FLUSH_HASH && !strcmp(s, "FLUSH"))) {
216
debug(D_PLUGINSD, "PLUGINSD: '%s' is requesting a FLUSH", cd->fullfilename);
217
st = NULL;
218
}
219
- else if(hash == CHART_HASH && !strcmp(s, "CHART")) {
219
+ else if(likely(hash == CHART_HASH && !strcmp(s, "CHART"))) {
220
st = NULL;
221
222
char *type = words[1];
223
char *id = NULL;
224
- if(type) {
224
+ if(likely(type)) {
225
id = strchr(type, '.');
226
- if(id) { *id = '\0'; id++; }
226
+ if(likely(id)) { *id = '\0'; id++; }
227
}
228
char *name = words[2];
229
char *title = words[3];
@@ -234,7 +234,7 @@ void *pluginsd_worker_thread(void *arg)
234
char *priority_s = words[8];
235
char *update_every_s = words[9];
236
237
- if(!type || !*type || !id || !*id) {
237
+ if(unlikely(!type || !*type || !id || !*id)) {
238
error("PLUGINSD: '%s' is requesting a CHART, without a type.id. Disabling it.", cd->fullfilename);
239
cd->enabled = 0;
240
killpid(cd->pid, SIGTERM);
@@ -242,21 +242,21 @@ void *pluginsd_worker_thread(void *arg)
242
}
243
244
int priority = 1000;
245
- if(priority_s) priority = atoi(priority_s);
245
+ if(likely(priority_s)) priority = atoi(priority_s);
246
247
int update_every = cd->update_every;
248
- if(update_every_s) update_every = atoi(update_every_s);
249
- if(!update_every) update_every = cd->update_every;
248
+ if(likely(update_every_s)) update_every = atoi(update_every_s);
249
+ if(unlikely(!update_every)) update_every = cd->update_every;
250
251
int chart_type = RRDSET_TYPE_LINE;
252
- if(chart) chart_type = rrdset_type_id(chart);
252
+ if(unlikely(chart)) chart_type = rrdset_type_id(chart);
253
254
- if(!name || !*name) name = NULL;
255
- if(!family || !*family) family = id;
256
- if(!category || !*category) category = type;
254
+ if(unlikely(!name || !*name)) name = NULL;
255
+ if(unlikely(!family || !*family)) family = id;
256
+ if(unlikely(!category || !*category)) category = type;
257
258
st = rrdset_find_bytype(type, id);
259
- if(!st) {
259
+ if(unlikely(!st)) {
260
debug(D_PLUGINSD, "PLUGINSD: Creating chart type='%s', id='%s', name='%s', family='%s', category='%s', chart='%s', priority=%d, update_every=%d"
261
, type, id
262
, name?name:""
@@ -270,11 +270,11 @@ void *pluginsd_worker_thread(void *arg)
270
st = rrdset_create(type, id, name, family, title, units, priority, update_every, chart_type);
271
cd->update_every = update_every;
272
273
- if(strcmp(category, "none") == 0) st->isdetail = 1;
273
+ if(unlikely(strcmp(category, "none") == 0)) st->isdetail = 1;
274
}
275
else debug(D_PLUGINSD, "PLUGINSD: Chart '%s' already exists. Not adding it again.", st->id);
276
}
277
- else if(hash == DIMENSION_HASH && !strcmp(s, "DIMENSION")) {
277
+ else if(likely(hash == DIMENSION_HASH && !strcmp(s, "DIMENSION"))) {
278
char *id = words[1];
279
char *name = words[2];
280
char *algorithm = words[3];
@@ -282,14 +282,14 @@ void *pluginsd_worker_thread(void *arg)
282
char *divisor_s = words[5];
283
char *hidden = words[6];
284
285
- if(!id || !*id) {
285
+ if(unlikely(!id || !*id)) {
286
error("PLUGINSD: '%s' is requesting a DIMENSION, without an id. Disabling it.", cd->fullfilename);
287
cd->enabled = 0;
288
killpid(cd->pid, SIGTERM);
289
break;
290
}
291
292
- if(!st) {
292
+ if(unlikely(!st)) {
293
error("PLUGINSD: '%s' is requesting a DIMENSION, without a CHART. Disabling it.", cd->fullfilename);
294
cd->enabled = 0;
295
killpid(cd->pid, SIGTERM);
@@ -298,15 +298,15 @@ void *pluginsd_worker_thread(void *arg)
298
299
long multiplier = 1;
300
if(multiplier_s && *multiplier_s) multiplier = atol(multiplier_s);
301
- if(!multiplier) multiplier = 1;
301
+ if(unlikely(!multiplier)) multiplier = 1;
302
303
long divisor = 1;
304
- if(divisor_s && *divisor_s) divisor = atol(divisor_s);
305
- if(!divisor) divisor = 1;
304
+ if(likely(divisor_s && *divisor_s)) divisor = atol(divisor_s);
305
+ if(unlikely(!divisor)) divisor = 1;
306
307
- if(!algorithm || !*algorithm) algorithm = "absolute";
307
+ if(unlikely(!algorithm || !*algorithm)) algorithm = "absolute";
308
309
- if(st->debug) debug(D_PLUGINSD, "PLUGINSD: Creating dimension in chart %s, id='%s', name='%s', algorithm='%s', multiplier=%ld, divisor=%ld, hidden='%s'"
309
+ if(unlikely(st->debug)) debug(D_PLUGINSD, "PLUGINSD: Creating dimension in chart %s, id='%s', name='%s', algorithm='%s', multiplier=%ld, divisor=%ld, hidden='%s'"
310
, st->id
311
, id
312
, name?name:""
@@ -317,31 +317,31 @@ void *pluginsd_worker_thread(void *arg)
317
);
318
319
RRDDIM *rd = rrddim_find(st, id);
320
- if(!rd) {
320
+ if(unlikely(!rd)) {
321
rd = rrddim_add(st, id, name, multiplier, divisor, rrddim_algorithm_id(algorithm));
322
- if(hidden && strcmp(hidden, "hidden") == 0) rd->hidden = 1;
322
+ if(unlikely(hidden && strcmp(hidden, "hidden") == 0)) rd->hidden = 1;
323
}
324
- else if(st->debug) debug(D_PLUGINSD, "PLUGINSD: dimension %s/%s already exists. Not adding it again.", st->id, id);
324
+ else if(unlikely(st->debug)) debug(D_PLUGINSD, "PLUGINSD: dimension %s/%s already exists. Not adding it again.", st->id, id);
325
}
326
- else if(hash == DISABLE_HASH && !strcmp(s, "DISABLE")) {
326
+ else if(unlikely(hash == DISABLE_HASH && !strcmp(s, "DISABLE"))) {
327
error("PLUGINSD: '%s' called DISABLE. Disabling it.", cd->fullfilename);
328
cd->enabled = 0;
329
killpid(cd->pid, SIGTERM);
330
break;
331
}
332
#ifdef DETACH_PLUGINS_FROM_NETDATA
333
- else if(hash == MYPID_HASH && !strcmp(s, "MYPID")) {
333
+ else if(likely(hash == MYPID_HASH && !strcmp(s, "MYPID"))) {
334
char *pid_s = words[1];
335
pid_t pid = atol(pid_s);
336
337
- if(pid) cd->pid = pid;
337
+ if(likely(pid)) cd->pid = pid;
338
debug(D_PLUGINSD, "PLUGINSD: %s is on pid %d", cd->id, cd->pid);
339
}
340
- else if(hash == STOPPING_WAKE_ME_UP_PLEASE_HASH && !strcmp(s, "STOPPING_WAKE_ME_UP_PLEASE")) {
340
+ else if(likely(hash == STOPPING_WAKE_ME_UP_PLEASE_HASH && !strcmp(s, "STOPPING_WAKE_ME_UP_PLEASE"))) {
341
error("PLUGINSD: '%s' (pid %d) called STOPPING_WAKE_ME_UP_PLEASE.", cd->fullfilename, cd->pid);
342
343
gettimeofday(&now, NULL);
344
- if(!usec && !susec) {
344
+ if(unlikely(!usec && !susec)) {
345
// our first run
346
susec = cd->rrd_update_every * 1000000ULL;
347
}
@@ -349,7 +349,7 @@ void *pluginsd_worker_thread(void *arg)
349
// second+ run
350
usec = usecdiff(&now, &last) - susec;
351
error("PLUGINSD: %s last loop took %llu usec (worked for %llu, sleeped for %llu).\n", cd->fullfilename, usec + susec, usec, susec);
352
- if(usec < (rrd_update_every * 1000000ULL / 2ULL)) susec = (rrd_update_every * 1000000ULL) - usec;
352
+ if(unlikely(usec < (rrd_update_every * 1000000ULL / 2ULL))) susec = (rrd_update_every * 1000000ULL) - usec;
353
else susec = rrd_update_every * 1000000ULL / 2ULL;
354
}
355
@@ -373,14 +373,14 @@ void *pluginsd_worker_thread(void *arg)
373
// fgets() failed or loop broke
374
mypclose(fp, cd->pid);
375
376
- if(!count && cd->enabled) {
376
+ if(unlikely(!count && cd->enabled)) {
377
error("PLUGINSD: '%s' (pid %d) does not generate usefull output. Waiting a bit before starting it again.", cd->fullfilename, cd->pid);
378
sleep(cd->update_every * 10);
379
}
380
381
cd->pid = 0;
382
383
- if(cd->enabled) sleep(cd->update_every);
383
+ if(likely(cd->enabled)) sleep(cd->update_every);
384
else break;
385
}
386
@@ -410,21 +410,21 @@ void *pluginsd_main(void *ptr)
410
411
if(scan_frequency < 1) scan_frequency = 1;
412
413
- while(1) {
413
+ while(likely(1)) {
414
dir = opendir(dir_name);
415
- if(!dir) {
415
+ if(unlikely(!dir)) {
416
error("Cannot open directory '%s'.", dir_name);
417
return NULL;
418
}
419
420
- while((file = readdir(dir))) {
420
+ while(likely((file = readdir(dir)))) {
421
debug(D_PLUGINSD, "PLUGINSD: Examining file '%s'", file->d_name);
422
423
- if(strcmp(file->d_name, ".") == 0 || strcmp(file->d_name, "..") == 0) continue;
423
+ if(unlikely(strcmp(file->d_name, ".") == 0 || strcmp(file->d_name, "..") == 0)) continue;
424
425
int len = strlen(file->d_name);
426
- if(len <= (int)PLUGINSD_FILE_SUFFIX_LEN) continue;
427
- if(strcmp(PLUGINSD_FILE_SUFFIX, &file->d_name[len - (int)PLUGINSD_FILE_SUFFIX_LEN]) != 0) {
426
+ if(unlikely(len <= (int)PLUGINSD_FILE_SUFFIX_LEN)) continue;
427
+ if(unlikely(strcmp(PLUGINSD_FILE_SUFFIX, &file->d_name[len - (int)PLUGINSD_FILE_SUFFIX_LEN]) != 0)) {
428
debug(D_PLUGINSD, "PLUGINSD: File '%s' does not end in '%s'.", file->d_name, PLUGINSD_FILE_SUFFIX);
429
continue;
430
}
@@ -433,25 +433,25 @@ void *pluginsd_main(void *ptr)
433
snprintf(pluginname, CONFIG_MAX_NAME, "%.*s", (int)(len - PLUGINSD_FILE_SUFFIX_LEN), file->d_name);
434
int enabled = config_get_boolean("plugins", pluginname, automatic_run);
435
436
- if(!enabled) {
436
+ if(unlikely(!enabled)) {
437
debug(D_PLUGINSD, "PLUGINSD: plugin '%s' is not enabled", file->d_name);
438
continue;
439
}
440
441
// check if it runs already
442
- for(cd = pluginsd_root ; cd ; cd = cd->next) {
443
- if(strcmp(cd->filename, file->d_name) == 0) break;
442
+ for(cd = pluginsd_root ; likely(cd) ; cd = cd->next) {
443
+ if(unlikely(strcmp(cd->filename, file->d_name) == 0)) break;
444
}
445
- if(cd && !cd->obsolete) {
445
+ if(likely(cd && !cd->obsolete)) {
446
debug(D_PLUGINSD, "PLUGINSD: plugin '%s' is already running", cd->filename);
447
continue;
448
}
449
450
// it is not running
451
// allocate a new one, or use the obsolete one
452
- if(!cd) {
452
+ if(unlikely(!cd)) {
453
cd = calloc(sizeof(struct plugind), 1);
454
- if(!cd) fatal("Cannot allocate memory for plugin.");
454
+ if(unlikely(!cd)) fatal("Cannot allocate memory for plugin.");
455
456
snprintf(cd->id, CONFIG_MAX_NAME, "plugin:%s", pluginname);
457
@@ -466,19 +466,19 @@ void *pluginsd_main(void *ptr)
466
snprintf(cd->cmd, PLUGINSD_CMD_MAX, "exec %s %d %s", cd->fullfilename, cd->update_every, config_get(cd->id, "command options", def));
467
468
// link it
469
- if(pluginsd_root) cd->next = pluginsd_root;
469
+ if(likely(pluginsd_root)) cd->next = pluginsd_root;
470
pluginsd_root = cd;
471
}
472
cd->obsolete = 0;
473
474
- if(!cd->enabled) continue;
474
+ if(unlikely(!cd->enabled)) continue;
475
476
// spawn a new thread for it
477
- if(pthread_create(&cd->thread, NULL, pluginsd_worker_thread, cd) != 0) {
477
+ if(unlikely(pthread_create(&cd->thread, NULL, pluginsd_worker_thread, cd) != 0)) {
478
error("CHARTS.D: failed to create new thread for chart.d %s.", cd->filename);
479
cd->obsolete = 1;
480
}
481
- else if(pthread_detach(cd->thread) != 0)
481
+ else if(unlikely(pthread_detach(cd->thread) != 0))
482
error("CHARTS.D: Cannot request detach of newly created thread for chart.d %s.", cd->filename);
483
}
484
src/popen.c
+2
@@ -6,6 +6,8 @@
6
7
#include "log.h"
8
#include "popen.h"
9
+#include "common.h"
10
+
11
/*
12
struct mypopen {
13
pid_t pid;
src/proc_diskstats.c
+1
@@ -3,6 +3,7 @@
3
#include <stdlib.h>
4
#include <string.h>
5
6
+#include "common.h"
7
#include "log.h"
8
#include "config.h"
9
#include "procfile.h"
src/proc_interrupts.c
+1
@@ -4,6 +4,7 @@
4
#include <string.h>
5
#include <ctype.h>
6
7
+#include "common.h"
8
#include "config.h"
9
#include "procfile.h"
10
#include "rrd.h"
src/proc_meminfo.c
+1
@@ -3,6 +3,7 @@
3
#include <stdlib.h>
4
#include <string.h>
5
6
+#include "common.h"
7
#include "log.h"
8
#include "config.h"
9
#include "procfile.h"
src/proc_net_dev.c
+1
@@ -2,6 +2,7 @@
2
#include <stdio.h>
3
#include <stdlib.h>
4
5
+#include "common.h"
6
#include "config.h"
7
#include "procfile.h"
8
#include "rrd.h"
src/proc_net_ip_vs_stats.c
+1
@@ -2,6 +2,7 @@
2
#include <stdio.h>
3
#include <stdlib.h>
4
5
+#include "common.h"
6
#include "config.h"
7
#include "procfile.h"
8
#include "rrd.h"
src/proc_net_netstat.c
+1
@@ -3,6 +3,7 @@
3
#include <stdlib.h>
4
#include <string.h>
5
6
+#include "common.h"
7
#include "log.h"
8
#include "config.h"
9
#include "procfile.h"
src/proc_net_rpc_nfsd.c
+1
@@ -3,6 +3,7 @@
3
#include <stdlib.h>
4
#include <string.h>
5
6
+#include "common.h"
7
#include "log.h"
8
#include "config.h"
9
#include "procfile.h"
src/proc_net_snmp.c
+1
@@ -3,6 +3,7 @@
3
#include <stdlib.h>
4
#include <string.h>
5
6
+#include "common.h"
7
#include "log.h"
8
#include "config.h"
9
#include "procfile.h"
src/proc_net_stat_conntrack.c
+1
@@ -3,6 +3,7 @@
3
#include <stdlib.h>
4
#include <string.h>
5
6
+#include "common.h"
7
#include "log.h"
8
#include "config.h"
9
#include "procfile.h"
src/proc_stat.c
+1
@@ -3,6 +3,7 @@
3
#include <stdlib.h>
4
#include <string.h>
5
6
+#include "common.h"
7
#include "log.h"
8
#include "config.h"
9
#include "procfile.h"
src/proc_sys_kernel_random_entropy_avail.c
+1
@@ -2,6 +2,7 @@
2
#include <stdio.h>
3
#include <stdlib.h>
4
5
+#include "common.h"
6
#include "config.h"
7
#include "procfile.h"
8
#include "rrd.h"
src/proc_vmstat.c
+1
@@ -4,6 +4,7 @@
4
#include <string.h>
5
#include <unistd.h>
6
7
+#include "common.h"
8
#include "log.h"
9
#include "config.h"
10
#include "procfile.h"
src/procfile.c
+48
-47
@@ -15,6 +15,7 @@
15
#include <sys/stat.h>
16
#include <sys/mman.h>
17
18
+#include "common.h"
19
#include "log.h"
20
#include "procfile.h"
21
@@ -39,11 +40,11 @@ size_t procfile_max_allocation = PROCFILE_INCREMENT_BUFFER;
40
pfwords *pfwords_add(pfwords *fw, char *str) {
41
// debug(D_PROCFILE, PF_PREFIX ": adding word No %d: '%s'", fw->len, str);
42
42
- if(fw->len == fw->size) {
43
+ if(unlikely(fw->len == fw->size)) {
44
// debug(D_PROCFILE, PF_PREFIX ": expanding words");
45
46
pfwords *new = realloc(fw, sizeof(pfwords) + (fw->size + PFWORDS_INCREASE_STEP) * sizeof(char *));
46
- if(!new) {
47
+ if(unlikely(!new)) {
48
error(PF_PREFIX ": failed to expand words");
49
free(fw);
50
return NULL;
@@ -63,7 +64,7 @@ pfwords *pfwords_new(void) {
64
uint32_t size = (procfile_adaptive_initial_allocation) ? procfile_max_words : PFWORDS_INCREASE_STEP;
65
66
pfwords *new = malloc(sizeof(pfwords) + size * sizeof(char *));
66
- if(!new) return NULL;
67
+ if(unlikely(!new)) return NULL;
68
69
new->len = 0;
70
new->size = size;
@@ -88,11 +89,11 @@ void pfwords_free(pfwords *fw) {
89
pflines *pflines_add(pflines *fl, uint32_t first_word) {
90
// debug(D_PROCFILE, PF_PREFIX ": adding line %d at word %d", fl->len, first_word);
91
91
- if(fl->len == fl->size) {
92
+ if(unlikely(fl->len == fl->size)) {
93
// debug(D_PROCFILE, PF_PREFIX ": expanding lines");
94
95
pflines *new = realloc(fl, sizeof(pflines) + (fl->size + PFLINES_INCREASE_STEP) * sizeof(ffline));
95
- if(!new) {
96
+ if(unlikely(!new)) {
97
error(PF_PREFIX ": failed to expand lines");
98
free(fl);
99
return NULL;
@@ -110,10 +111,10 @@ pflines *pflines_add(pflines *fl, uint32_t first_word) {
111
pflines *pflines_new(void) {
112
// debug(D_PROCFILE, PF_PREFIX ": initializing lines");
113
113
- uint32_t size = (procfile_adaptive_initial_allocation) ? procfile_max_words : PFLINES_INCREASE_STEP;
114
+ uint32_t size = (unlikely(procfile_adaptive_initial_allocation)) ? procfile_max_words : PFLINES_INCREASE_STEP;
115
116
pflines *new = malloc(sizeof(pflines) + size * sizeof(ffline));
116
- if(!new) return NULL;
117
+ if(unlikely(!new)) return NULL;
118
119
new->len = 0;
120
new->size = size;
@@ -143,10 +144,10 @@ void pflines_free(pflines *fl) {
144
void procfile_close(procfile *ff) {
145
debug(D_PROCFILE, PF_PREFIX ": Closing file '%s'", ff->filename);
146
146
- if(ff->lines) pflines_free(ff->lines);
147
- if(ff->words) pfwords_free(ff->words);
147
+ if(likely(ff->lines)) pflines_free(ff->lines);
148
+ if(likely(ff->words)) pfwords_free(ff->words);
149
149
- if(ff->fd != -1) close(ff->fd);
150
+ if(likely(ff->fd != -1)) close(ff->fd);
151
free(ff);
152
}
153
@@ -158,12 +159,12 @@ procfile *procfile_parser(procfile *ff) {
159
e += ff->len;
160
161
ff->lines = pflines_add(ff->lines, w);
161
- if(!ff->lines) goto cleanup;
162
+ if(unlikely(!ff->lines)) goto cleanup;
163
163
- while(s < e) {
164
+ while(likely(s < e)) {
165
switch(ff->separators[(int)(*s)]) {
166
case PF_CHAR_IS_SEPARATOR:
166
- if(s == t) {
167
+ if(likely(s == t)) {
168
// skip all leading white spaces
169
t = ++s;
170
continue;
@@ -173,7 +174,7 @@ procfile *procfile_parser(procfile *ff) {
174
*s = '\0';
175
176
ff->words = pfwords_add(ff->words, t);
176
- if(!ff->words) goto cleanup;
177
+ if(unlikely(!ff->words)) goto cleanup;
178
179
ff->lines->lines[l].words++;
180
w++;
@@ -186,7 +187,7 @@ procfile *procfile_parser(procfile *ff) {
187
*s = '\0';
188
189
ff->words = pfwords_add(ff->words, t);
189
- if(!ff->words) goto cleanup;
190
+ if(unlikely(!ff->words)) goto cleanup;
191
192
ff->lines->lines[l].words++;
193
w++;
@@ -194,7 +195,7 @@ procfile *procfile_parser(procfile *ff) {
195
// debug(D_PROCFILE, PF_PREFIX ": ended line %d with %d words", l, ff->lines->lines[l].words);
196
197
ff->lines = pflines_add(ff->lines, w);
197
- if(!ff->lines) goto cleanup;
198
+ if(unlikely(!ff->lines)) goto cleanup;
199
l++;
200
201
t = ++s;
@@ -206,16 +207,16 @@ procfile *procfile_parser(procfile *ff) {
207
}
208
}
209
209
- if(s != t) {
210
+ if(likely(s != t)) {
211
// the last word
211
- if(ff->len < ff->size) *s = '\0';
212
+ if(likely(ff->len < ff->size)) *s = '\0';
213
else {
214
// we are going to loose the last byte
215
ff->data[ff->size - 1] = '\0';
216
}
217
218
ff->words = pfwords_add(ff->words, t);
218
- if(!ff->words) goto cleanup;
219
+ if(unlikely(!ff->words)) goto cleanup;
220
221
ff->lines->lines[l].words++;
222
w++;
@@ -235,12 +236,12 @@ procfile *procfile_readall(procfile *ff) {
236
ssize_t s = 0, r = ff->size, x = ff->size;
237
ff->len = 0;
238
238
- while(r == x) {
239
+ while(likely(r == x)) {
240
if(s) {
241
debug(D_PROCFILE, PF_PREFIX ": Expanding data buffer for file '%s'.", ff->filename);
242
243
procfile *new = realloc(ff, sizeof(procfile) + ff->size + PROCFILE_INCREMENT_BUFFER);
243
- if(!new) {
244
+ if(unlikely(!new)) {
245
error(PF_PREFIX ": Cannot allocate memory for file '%s'", ff->filename);
246
procfile_close(ff);
247
return NULL;
@@ -252,8 +253,8 @@ procfile *procfile_readall(procfile *ff) {
253
254
debug(D_PROCFILE, "Reading file '%s', from position %ld with length %ld", ff->filename, s, ff->size - s);
255
r = read(ff->fd, &ff->data[s], ff->size - s);
255
- if(r == -1) {
256
- if(!(ff->flags & PROCFILE_FLAG_NO_ERROR_ON_FILE_IO)) error(PF_PREFIX ": Cannot read from file '%s'", ff->filename);
256
+ if(unlikely(r == -1)) {
257
+ if(unlikely(!(ff->flags & PROCFILE_FLAG_NO_ERROR_ON_FILE_IO))) error(PF_PREFIX ": Cannot read from file '%s'", ff->filename);
258
procfile_close(ff);
259
return NULL;
260
}
@@ -263,8 +264,8 @@ procfile *procfile_readall(procfile *ff) {
264
}
265
266
debug(D_PROCFILE, "Rewinding file '%s'", ff->filename);
266
- if(lseek(ff->fd, 0, SEEK_SET) == -1) {
267
- if(!(ff->flags & PROCFILE_FLAG_NO_ERROR_ON_FILE_IO)) error(PF_PREFIX ": Cannot rewind on file '%s'.", ff->filename);
267
+ if(unlikely(lseek(ff->fd, 0, SEEK_SET) == -1)) {
268
+ if(unlikely(!(ff->flags & PROCFILE_FLAG_NO_ERROR_ON_FILE_IO))) error(PF_PREFIX ": Cannot rewind on file '%s'.", ff->filename);
269
procfile_close(ff);
270
return NULL;
271
}
@@ -274,10 +275,10 @@ procfile *procfile_readall(procfile *ff) {
275
276
ff = procfile_parser(ff);
277
277
- if(procfile_adaptive_initial_allocation) {
278
- if(ff->len > procfile_max_allocation) procfile_max_allocation = ff->len;
279
- if(ff->lines->len > procfile_max_lines) procfile_max_lines = ff->lines->len;
280
- if(ff->words->len > procfile_max_words) procfile_max_words = ff->words->len;
278
+ if(unlikely(procfile_adaptive_initial_allocation)) {
279
+ if(unlikely(ff->len > procfile_max_allocation)) procfile_max_allocation = ff->len;
280
+ if(unlikely(ff->lines->len > procfile_max_lines)) procfile_max_lines = ff->lines->len;
281
+ if(unlikely(ff->words->len > procfile_max_words)) procfile_max_words = ff->words->len;
282
}
283
284
debug(D_PROCFILE, "File '%s' updated.", ff->filename);
@@ -288,41 +289,41 @@ static void procfile_set_separators(procfile *ff, const char *separators) {
289
static char def[256] = { [0 ... 255] = 0 };
290
int i;
291
291
- if(!def[255]) {
292
+ if(unlikely(!def[255])) {
293
// this is thread safe
294
// we check that the last byte is non-zero
295
// if it is zero, multiple threads may be executing this at the same time
296
// setting in def[] the exact same values
296
- for(i = 0; i < 256 ;i++) {
297
- if(i == '\n' || i == '\r') def[i] = PF_CHAR_IS_NEWLINE;
298
- else if(isspace(i) || !isprint(i)) def[i] = PF_CHAR_IS_SEPARATOR;
297
+ for(i = 0; likely(i < 256) ;i++) {
298
+ if(unlikely(i == '\n' || i == '\r')) def[i] = PF_CHAR_IS_NEWLINE;
299
+ else if(unlikely(isspace(i) || !isprint(i))) def[i] = PF_CHAR_IS_SEPARATOR;
300
else def[i] = PF_CHAR_IS_WORD;
301
}
302
}
303
304
// copy the default
305
char *ffs = ff->separators, *ffd = def, *ffe = &def[256];
305
- while(ffd != ffe) *ffs++ = *ffd++;
306
+ while(likely(ffd != ffe)) *ffs++ = *ffd++;
307
308
// set the separators
308
- if(!separators) separators = " \t=|";
309
+ if(unlikely(!separators)) separators = " \t=|";
310
ffs = ff->separators;
311
const char *s = separators;
311
- while(*s) ffs[(int)*s++] = PF_CHAR_IS_SEPARATOR;
312
+ while(likely(*s)) ffs[(int)*s++] = PF_CHAR_IS_SEPARATOR;
313
}
314
315
procfile *procfile_open(const char *filename, const char *separators, uint32_t flags) {
316
debug(D_PROCFILE, PF_PREFIX ": Opening file '%s'", filename);
317
318
int fd = open(filename, O_RDONLY, 0666);
318
- if(fd == -1) {
319
- if(!(flags & PROCFILE_FLAG_NO_ERROR_ON_FILE_IO)) error(PF_PREFIX ": Cannot open file '%s'", filename);
319
+ if(unlikely(fd == -1)) {
320
+ if(unlikely(!(flags & PROCFILE_FLAG_NO_ERROR_ON_FILE_IO))) error(PF_PREFIX ": Cannot open file '%s'", filename);
321
return NULL;
322
}
323
323
- size_t size = (procfile_adaptive_initial_allocation) ? procfile_max_allocation : PROCFILE_INCREMENT_BUFFER;
324
+ size_t size = (unlikely(procfile_adaptive_initial_allocation)) ? procfile_max_allocation : PROCFILE_INCREMENT_BUFFER;
325
procfile *ff = malloc(sizeof(procfile) + size);
325
- if(!ff) {
326
+ if(unlikely(!ff)) {
327
error(PF_PREFIX ": Cannot allocate memory for file '%s'", filename);
328
close(fd);
329
return NULL;
@@ -339,7 +340,7 @@ procfile *procfile_open(const char *filename, const char *separators, uint32_t f
340
ff->lines = pflines_new();
341
ff->words = pfwords_new();
342
342
- if(!ff->lines || !ff->words) {
343
+ if(unlikely(!ff->lines || !ff->words)) {
344
error(PF_PREFIX ": Cannot initialize parser for file '%s'", filename);
345
procfile_close(ff);
346
return NULL;
@@ -352,12 +353,12 @@ procfile *procfile_open(const char *filename, const char *separators, uint32_t f
353
}
354
355
procfile *procfile_reopen(procfile *ff, const char *filename, const char *separators, uint32_t flags) {
355
- if(!ff) return procfile_open(filename, separators, flags);
356
+ if(unlikely(!ff)) return procfile_open(filename, separators, flags);
357
357
- if(ff->fd != -1) close(ff->fd);
358
+ if(likely(ff->fd != -1)) close(ff->fd);
359
360
ff->fd = open(filename, O_RDONLY, 0666);
360
- if(ff->fd == -1) {
361
+ if(unlikely(ff->fd == -1)) {
362
procfile_close(ff);
363
return NULL;
364
}
@@ -368,7 +369,7 @@ procfile *procfile_reopen(procfile *ff, const char *filename, const char *separa
369
ff->flags = flags;
370
371
// do not do the separators again if NULL is given
371
- if(separators) procfile_set_separators(ff, separators);
372
+ if(likely(separators)) procfile_set_separators(ff, separators);
373
374
return ff;
375
}
@@ -383,12 +384,12 @@ void procfile_print(procfile *ff) {
384
385
debug(D_PROCFILE, "File '%s' with %d lines and %d words", ff->filename, ff->lines->len, ff->words->len);
386
386
- for(l = 0; l < lines ;l++) {
387
+ for(l = 0; likely(l < lines) ;l++) {
388
words = procfile_linewords(ff, l);
389
390
debug(D_PROCFILE, " line %d starts at word %d and has %d words", l, ff->lines->lines[l].first, ff->lines->lines[l].words);
391
391
- for(w = 0; w < words ;w++) {
392
+ for(w = 0; likely(w < words) ;w++) {
393
s = procfile_lineword(ff, l, w);
394
debug(D_PROCFILE, " [%d.%d] '%s'", l, w, s);
395
}
src/rrd.c
+69
-62
@@ -143,9 +143,9 @@ static RRDDIM *rrddim_index_find(RRDSET *st, const char *id, uint32_t hash) {
143
144
int rrdset_type_id(const char *name)
145
{
146
- if(strcmp(name, RRDSET_TYPE_AREA_NAME) == 0) return RRDSET_TYPE_AREA;
147
- if(strcmp(name, RRDSET_TYPE_STACKED_NAME) == 0) return RRDSET_TYPE_STACKED;
148
- if(strcmp(name, RRDSET_TYPE_LINE_NAME) == 0) return RRDSET_TYPE_LINE;
146
+ if(unlikely(strcmp(name, RRDSET_TYPE_AREA_NAME) == 0)) return RRDSET_TYPE_AREA;
147
+ else if(unlikely(strcmp(name, RRDSET_TYPE_STACKED_NAME) == 0)) return RRDSET_TYPE_STACKED;
148
+ else if(unlikely(strcmp(name, RRDSET_TYPE_LINE_NAME) == 0)) return RRDSET_TYPE_LINE;
149
return RRDSET_TYPE_LINE;
150
}
151
@@ -194,9 +194,9 @@ const char *rrd_memory_mode_name(int id)
194
195
int rrd_memory_mode_id(const char *name)
196
{
197
- if(!strcmp(name, RRD_MEMORY_MODE_RAM_NAME))
197
+ if(unlikely(!strcmp(name, RRD_MEMORY_MODE_RAM_NAME)))
198
return RRD_MEMORY_MODE_RAM;
199
- else if(!strcmp(name, RRD_MEMORY_MODE_MAP_NAME))
199
+ else if(unlikely(!strcmp(name, RRD_MEMORY_MODE_MAP_NAME)))
200
return RRD_MEMORY_MODE_MAP;
201
202
return RRD_MEMORY_MODE_SAVE;
@@ -660,7 +660,7 @@ void rrdset_save_all(void)
660
}
661
662
for(rd = st->dimensions; rd ; rd = rd->next) {
663
- if(rd->mapped == RRD_MEMORY_MODE_SAVE) {
663
+ if(likely(rd->mapped == RRD_MEMORY_MODE_SAVE)) {
664
debug(D_RRD_CALLS, "Saving dimension '%s' to '%s'.", rd->name, rd->cache_filename);
665
savememory(rd->cache_filename, rd, rd->memsize);
666
}
@@ -722,7 +722,7 @@ int rrddim_hide(RRDSET *st, const char *id)
722
debug(D_RRD_CALLS, "rrddim_hide() for chart %s, dimension %s", st->name, id);
723
724
RRDDIM *rd = rrddim_find(st, id);
725
- if(!rd) {
725
+ if(unlikely(!rd)) {
726
error("Cannot find dimension with id '%s' on stats '%s' (%s).", id, st->name, st->id);
727
return 1;
728
}
@@ -736,7 +736,7 @@ int rrddim_unhide(RRDSET *st, const char *id)
736
debug(D_RRD_CALLS, "rrddim_unhide() for chart %s, dimension %s", st->name, id);
737
738
RRDDIM *rd = rrddim_find(st, id);
739
- if(!rd) {
739
+ if(unlikely(!rd)) {
740
error("Cannot find dimension with id '%s' on stats '%s' (%s).", id, st->name, st->id);
741
return 1;
742
}
@@ -757,7 +757,7 @@ void rrddim_set_by_pointer(RRDSET *st, RRDDIM *rd, collected_number value)
757
int rrddim_set(RRDSET *st, const char *id, collected_number value)
758
{
759
RRDDIM *rd = rrddim_find(st, id);
760
- if(!rd) {
760
+ if(unlikely(!rd)) {
761
error("Cannot find dimension with id '%s' on stats '%s' (%s).", id, st->name, st->id);
762
return 1;
763
}
@@ -770,7 +770,7 @@ void rrdset_next_usec(RRDSET *st, unsigned long long microseconds)
770
{
771
debug(D_RRD_CALLS, "rrdset_next_usec() for chart %s with microseconds %llu", st->name, microseconds);
772
773
- if(st->debug) debug(D_RRD_STATS, "%s: NEXT: %llu microseconds", st->name, microseconds);
773
+ if(unlikely(st->debug)) debug(D_RRD_STATS, "%s: NEXT: %llu microseconds", st->name, microseconds);
774
st->usec_since_last_update = microseconds;
775
}
776
@@ -778,7 +778,7 @@ void rrdset_next(RRDSET *st)
778
{
779
unsigned long long microseconds = 0;
780
781
- if(st->last_collected_time.tv_sec) {
781
+ if(likely(st->last_collected_time.tv_sec)) {
782
struct timeval now;
783
gettimeofday(&now, NULL);
784
microseconds = usecdiff(&now, &st->last_collected_time);
@@ -799,22 +799,22 @@ unsigned long long rrdset_done(RRDSET *st)
799
RRDDIM *rd, *last;
800
int oldstate, store_this_entry = 1;
801
802
- if(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate) != 0)
802
+ if(unlikely(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate) != 0))
803
error("Cannot set pthread cancel state to DISABLE.");
804
805
// a read lock is OK here
806
pthread_rwlock_rdlock(&st->rwlock);
807
808
// check if the chart has a long time to be refreshed
809
- if(st->usec_since_last_update > st->entries * st->update_every * 1000000ULL) {
809
+ if(unlikely(st->usec_since_last_update > st->entries * st->update_every * 1000000ULL)) {
810
info("%s: took too long to be updated (%0.3Lf secs). Reseting it.", st->name, (long double)(st->usec_since_last_update / 1000000.0));
811
rrdset_reset(st);
812
st->usec_since_last_update = st->update_every * 1000000ULL;
813
}
814
- if(st->debug) debug(D_RRD_STATS, "%s: microseconds since last update: %llu", st->name, st->usec_since_last_update);
814
+ if(unlikely(st->debug)) debug(D_RRD_STATS, "%s: microseconds since last update: %llu", st->name, st->usec_since_last_update);
815
816
// set last_collected_time
817
- if(!st->last_collected_time.tv_sec) {
817
+ if(unlikely(!st->last_collected_time.tv_sec)) {
818
// it is the first entry
819
// set the last_collected_time to now
820
gettimeofday(&st->last_collected_time, NULL);
@@ -822,7 +822,7 @@ unsigned long long rrdset_done(RRDSET *st)
822
// the first entry should not be stored
823
store_this_entry = 0;
824
825
- if(st->debug) debug(D_RRD_STATS, "%s: initializing last_collected to now. Will not store the next entry.", st->name);
825
+ if(unlikely(st->debug)) debug(D_RRD_STATS, "%s: initializing last_collected to now. Will not store the next entry.", st->name);
826
}
827
else {
828
// it is not the first entry
@@ -834,7 +834,7 @@ unsigned long long rrdset_done(RRDSET *st)
834
835
// if this set has not been updated in the past
836
// we fake the last_update time to be = now - usec_since_last_update
837
- if(!st->last_updated.tv_sec) {
837
+ if(unlikely(!st->last_updated.tv_sec)) {
838
// it has never been updated before
839
// set a fake last_updated, in the past using usec_since_last_update
840
unsigned long long ut = st->last_collected_time.tv_sec * 1000000ULL + st->last_collected_time.tv_usec - st->usec_since_last_update;
@@ -844,11 +844,11 @@ unsigned long long rrdset_done(RRDSET *st)
844
// the first entry should not be stored
845
store_this_entry = 0;
846
847
- if(st->debug) debug(D_RRD_STATS, "%s: initializing last_updated to now - %llu microseconds (%0.3Lf). Will not store the next entry.", st->name, st->usec_since_last_update, (long double)ut/1000000.0);
847
+ if(unlikely(st->debug)) debug(D_RRD_STATS, "%s: initializing last_updated to now - %llu microseconds (%0.3Lf). Will not store the next entry.", st->name, st->usec_since_last_update, (long double)ut/1000000.0);
848
}
849
850
// check if we will re-write the entire data set
851
- if(usecdiff(&st->last_collected_time, &st->last_updated) > st->update_every * st->entries * 1000000ULL) {
851
+ if(unlikely(usecdiff(&st->last_collected_time, &st->last_updated) > st->update_every * st->entries * 1000000ULL)) {
852
info("%s: too old data (last updated at %u.%u, last collected at %u.%u). Reseting it. Will not store the next entry.", st->name, st->last_updated.tv_sec, st->last_updated.tv_usec, st->last_collected_time.tv_sec, st->last_collected_time.tv_usec);
853
rrdset_reset(st);
854
@@ -872,20 +872,22 @@ unsigned long long rrdset_done(RRDSET *st)
872
unsigned long long now_ut = st->last_collected_time.tv_sec * 1000000ULL + st->last_collected_time.tv_usec;
873
unsigned long long next_ut = (st->last_updated.tv_sec + st->update_every) * 1000000ULL;
874
875
- if(st->debug) debug(D_RRD_STATS, "%s: last ut = %0.3Lf (last updated time)", st->name, (long double)last_ut/1000000.0);
876
- if(st->debug) debug(D_RRD_STATS, "%s: now ut = %0.3Lf (current update time)", st->name, (long double)now_ut/1000000.0);
877
- if(st->debug) debug(D_RRD_STATS, "%s: next ut = %0.3Lf (next interpolation point)", st->name, (long double)next_ut/1000000.0);
875
+ if(unlikely(st->debug)) {
876
+ debug(D_RRD_STATS, "%s: last ut = %0.3Lf (last updated time)", st->name, (long double)last_ut/1000000.0);
877
+ debug(D_RRD_STATS, "%s: now ut = %0.3Lf (current update time)", st->name, (long double)now_ut/1000000.0);
878
+ debug(D_RRD_STATS, "%s: next ut = %0.3Lf (next interpolation point)", st->name, (long double)next_ut/1000000.0);
879
+ }
880
879
- if(!st->counter_done) {
881
+ if(unlikely(!st->counter_done)) {
882
store_this_entry = 0;
881
- if(st->debug) debug(D_RRD_STATS, "%s: Will not store the next entry.", st->name);
883
+ if(unlikely(st->debug)) debug(D_RRD_STATS, "%s: Will not store the next entry.", st->name);
884
}
885
st->counter_done++;
886
887
// calculate totals and count the dimensions
888
int dimensions;
889
st->collected_total = 0;
888
- for( rd = st->dimensions, dimensions = 0 ; rd ; rd = rd->next, dimensions++ )
890
+ for( rd = st->dimensions, dimensions = 0 ; likely(rd) ; rd = rd->next, dimensions++ )
891
st->collected_total += rd->collected_value;
892
893
uint32_t storage_flags = SN_EXISTS;
@@ -893,9 +895,9 @@ unsigned long long rrdset_done(RRDSET *st)
895
// process all dimensions to calculate their values
896
// based on the collected figures only
897
// at this stage we do not interpolate anything
896
- for( rd = st->dimensions ; rd ; rd = rd->next ) {
898
+ for( rd = st->dimensions ; likely(rd) ; rd = rd->next ) {
899
898
- if(st->debug) debug(D_RRD_STATS, "%s/%s: "
900
+ if(unlikely(st->debug)) debug(D_RRD_STATS, "%s/%s: "
901
" last_collected_value = " COLLECTED_NUMBER_FORMAT
902
" collected_value = " COLLECTED_NUMBER_FORMAT
903
" last_calculated_value = " CALCULATED_NUMBER_FORMAT
@@ -911,13 +913,13 @@ unsigned long long rrdset_done(RRDSET *st)
913
case RRDDIM_PCENT_OVER_DIFF_TOTAL:
914
// the percentage of the current increment
915
// over the increment of all dimensions together
914
- if(st->collected_total == st->last_collected_total) rd->calculated_value = rd->last_calculated_value;
916
+ if(unlikely(st->collected_total == st->last_collected_total)) rd->calculated_value = rd->last_calculated_value;
917
else rd->calculated_value =
918
(calculated_number)100
919
* (calculated_number)(rd->collected_value - rd->last_collected_value)
920
/ (calculated_number)(st->collected_total - st->last_collected_total);
921
920
- if(st->debug)
922
+ if(unlikely(st->debug))
923
debug(D_RRD_STATS, "%s/%s: CALC PCENT-DIFF "
924
CALCULATED_NUMBER_FORMAT " = 100"
925
" * (" COLLECTED_NUMBER_FORMAT " - " COLLECTED_NUMBER_FORMAT ")"
@@ -930,7 +932,7 @@ unsigned long long rrdset_done(RRDSET *st)
932
break;
933
934
case RRDDIM_PCENT_OVER_ROW_TOTAL:
933
- if(!st->collected_total) rd->calculated_value = 0;
935
+ if(unlikely(!st->collected_total)) rd->calculated_value = 0;
936
else
937
// the percentage of the current value
938
// over the total of all dimensions
@@ -939,7 +941,7 @@ unsigned long long rrdset_done(RRDSET *st)
941
* (calculated_number)rd->collected_value
942
/ (calculated_number)st->collected_total;
943
942
- if(st->debug)
944
+ if(unlikely(st->debug))
945
debug(D_RRD_STATS, "%s/%s: CALC PCENT-ROW "
946
CALCULATED_NUMBER_FORMAT " = 100"
947
" * " COLLECTED_NUMBER_FORMAT
@@ -954,7 +956,7 @@ unsigned long long rrdset_done(RRDSET *st)
956
case RRDDIM_INCREMENTAL:
957
// if the new is smaller than the old (an overflow, or reset), set the old equal to the new
958
// to reset the calculation (it will give zero as the calculation for this second)
957
- if(rd->last_collected_value > rd->collected_value) {
959
+ if(unlikely(rd->last_collected_value > rd->collected_value)) {
960
info("%s.%s: Detect RESET or OVERFLOW. Last collected value = " COLLECTED_NUMBER_FORMAT ", current = " COLLECTED_NUMBER_FORMAT
961
, st->name, rd->name
962
, rd->last_collected_value
@@ -965,7 +967,7 @@ unsigned long long rrdset_done(RRDSET *st)
967
968
rd->calculated_value += (calculated_number)(rd->collected_value - rd->last_collected_value);
969
968
- if(st->debug)
970
+ if(unlikely(st->debug))
971
debug(D_RRD_STATS, "%s/%s: CALC INC "
972
CALCULATED_NUMBER_FORMAT " += "
973
COLLECTED_NUMBER_FORMAT " - " COLLECTED_NUMBER_FORMAT
@@ -978,7 +980,7 @@ unsigned long long rrdset_done(RRDSET *st)
980
case RRDDIM_ABSOLUTE:
981
rd->calculated_value = (calculated_number)rd->collected_value;
982
981
- if(st->debug)
983
+ if(unlikely(st->debug))
984
debug(D_RRD_STATS, "%s/%s: CALC ABS/ABS-NO-IN "
985
CALCULATED_NUMBER_FORMAT " = "
986
COLLECTED_NUMBER_FORMAT
@@ -993,7 +995,7 @@ unsigned long long rrdset_done(RRDSET *st)
995
// it gets noticed when we add new types
996
rd->calculated_value = 0;
997
996
- if(st->debug)
998
+ if(unlikely(st->debug))
999
debug(D_RRD_STATS, "%s/%s: CALC "
1000
CALCULATED_NUMBER_FORMAT " = 0"
1001
, st->id, rd->name
@@ -1009,16 +1011,18 @@ unsigned long long rrdset_done(RRDSET *st)
1011
unsigned long long first_ut = last_ut;
1012
int iterations = (now_ut - last_ut) / (st->update_every * 1000000ULL);
1013
1012
- for( ; next_ut <= now_ut ; next_ut += st->update_every * 1000000ULL, iterations-- ) {
1014
+ for( ; likely(next_ut <= now_ut) ; next_ut += st->update_every * 1000000ULL, iterations-- ) {
1015
if(iterations < 0) error("iterations calculation wrapped!");
1016
1015
- if(st->debug) debug(D_RRD_STATS, "%s: last ut = %0.3Lf (last updated time)", st->name, (long double)last_ut/1000000.0);
1016
- if(st->debug) debug(D_RRD_STATS, "%s: next ut = %0.3Lf (next interpolation point)", st->name, (long double)next_ut/1000000.0);
1017
+ if(unlikely(st->debug)) {
1018
+ debug(D_RRD_STATS, "%s: last ut = %0.3Lf (last updated time)", st->name, (long double)last_ut/1000000.0);
1019
+ debug(D_RRD_STATS, "%s: next ut = %0.3Lf (next interpolation point)", st->name, (long double)next_ut/1000000.0);
1020
+ }
1021
1022
st->last_updated.tv_sec = next_ut / 1000000ULL;
1023
st->last_updated.tv_usec = 0;
1024
1021
- for( rd = st->dimensions ; rd ; rd = rd->next ) {
1025
+ for( rd = st->dimensions ; likely(rd) ; rd = rd->next ) {
1026
calculated_number new_value;
1027
1028
switch(rd->algorithm) {
@@ -1029,7 +1033,7 @@ unsigned long long rrdset_done(RRDSET *st)
1033
/ (calculated_number)(now_ut - last_ut)
1034
);
1035
1032
- if(st->debug)
1036
+ if(unlikely(st->debug))
1037
debug(D_RRD_STATS, "%s/%s: CALC2 INC "
1038
CALCULATED_NUMBER_FORMAT " = "
1039
CALCULATED_NUMBER_FORMAT
@@ -1057,7 +1061,7 @@ unsigned long long rrdset_done(RRDSET *st)
1061
+ rd->last_calculated_value
1062
);
1063
1060
- if(st->debug)
1064
+ if(unlikely(st->debug))
1065
debug(D_RRD_STATS, "%s/%s: CALC2 DEF "
1066
CALCULATED_NUMBER_FORMAT " = ((("
1067
"(" CALCULATED_NUMBER_FORMAT " - " CALCULATED_NUMBER_FORMAT ")"
@@ -1070,23 +1074,23 @@ unsigned long long rrdset_done(RRDSET *st)
1074
, (now_ut - first_ut), rd->last_calculated_value
1075
);
1076
1073
- if(next_ut + st->update_every * 1000000ULL > now_ut) rd->calculated_value = new_value;
1077
+ if(likely(next_ut + st->update_every * 1000000ULL > now_ut)) rd->calculated_value = new_value;
1078
break;
1079
}
1080
1077
- if(!store_this_entry) {
1081
+ if(unlikely(!store_this_entry)) {
1082
store_this_entry = 1;
1083
continue;
1084
}
1085
1082
- if(rd->updated && iterations < st->gap_when_lost_iterations_above) {
1086
+ if(likely(rd->updated && iterations < st->gap_when_lost_iterations_above)) {
1087
rd->values[st->current_entry] = pack_storage_number(
1088
new_value
1089
* (calculated_number)rd->multiplier
1090
/ (calculated_number)rd->divisor
1091
, storage_flags );
1092
1089
- if(st->debug)
1093
+ if(unlikely(st->debug))
1094
debug(D_RRD_STATS, "%s/%s: STORE[%ld] "
1095
CALCULATED_NUMBER_FORMAT " = " CALCULATED_NUMBER_FORMAT
1096
" * %ld"
@@ -1099,14 +1103,14 @@ unsigned long long rrdset_done(RRDSET *st)
1103
);
1104
}
1105
else {
1102
- if(st->debug) debug(D_RRD_STATS, "%s/%s: STORE[%ld] = NON EXISTING "
1106
+ if(unlikely(st->debug)) debug(D_RRD_STATS, "%s/%s: STORE[%ld] = NON EXISTING "
1107
, st->id, rd->name
1108
, st->current_entry
1109
);
1110
rd->values[st->current_entry] = pack_storage_number(0, SN_NOT_EXISTS);
1111
}
1112
1109
- if(st->debug) {
1113
+ if(unlikely(st->debug)) {
1114
calculated_number t1 = new_value * (calculated_number)rd->multiplier / (calculated_number)rd->divisor;
1115
calculated_number t2 = unpack_storage_number(rd->values[st->current_entry]);
1116
calculated_number accuracy = accuracy_loss(t1, t2);
@@ -1137,7 +1141,7 @@ unsigned long long rrdset_done(RRDSET *st)
1141
// reset the storage flags for the next point, if any;
1142
storage_flags = SN_EXISTS;
1143
1140
- if(st->first_entry_t && st->counter >= (unsigned long long)st->entries) {
1144
+ if(unlikely(st->first_entry_t && st->counter >= (unsigned long long)st->entries)) {
1145
// the db is overwriting values
1146
// add the value we will overwrite
1147
st->first_entry_t += st->update_every * 1000000ULL;
@@ -1145,12 +1149,12 @@ unsigned long long rrdset_done(RRDSET *st)
1149
1150
st->counter++;
1151
st->current_entry = ((st->current_entry + 1) >= st->entries) ? 0 : st->current_entry + 1;
1148
- if(!st->first_entry_t) st->first_entry_t = next_ut;
1152
+ if(unlikely(!st->first_entry_t)) st->first_entry_t = next_ut;
1153
last_ut = next_ut;
1154
}
1155
1152
- for( rd = st->dimensions; rd ; rd = rd->next ) {
1153
- if(!rd->updated) continue;
1156
+ for( rd = st->dimensions; likely(rd) ; rd = rd->next ) {
1157
+ if(unlikely(!rd->updated)) continue;
1158
rd->last_collected_value = rd->collected_value;
1159
rd->last_calculated_value = rd->calculated_value;
1160
rd->collected_value = 0;
@@ -1159,7 +1163,7 @@ unsigned long long rrdset_done(RRDSET *st)
1163
// if this is the first entry of incremental dimensions
1164
// we have to set the first calculated_value to zero
1165
// to eliminate the first spike
1162
- if(st->counter_done == 1) switch(rd->algorithm) {
1166
+ if(unlikely(st->counter_done == 1)) switch(rd->algorithm) {
1167
case RRDDIM_PCENT_OVER_DIFF_TOTAL:
1168
case RRDDIM_INCREMENTAL:
1169
rd->calculated_value = 0;
@@ -1173,25 +1177,25 @@ unsigned long long rrdset_done(RRDSET *st)
1177
// --------------------------------------------------------------------
1178
1179
// find if there are any obsolete dimensions (not updated recently)
1176
- if(rrd_delete_unupdated_dimensions) {
1180
+ if(unlikely(rrd_delete_unupdated_dimensions)) {
1181
1178
- for( rd = st->dimensions; rd ; rd = rd->next )
1182
+ for( rd = st->dimensions; likely(rd) ; rd = rd->next )
1183
if((rd->last_collected_time.tv_sec + (rrd_delete_unupdated_dimensions * st->update_every)) < st->last_collected_time.tv_sec)
1184
break;
1185
1182
- if(rd) {
1186
+ if(unlikely(rd)) {
1187
// there is dimension to free
1188
// upgrade our read lock to a write lock
1189
pthread_rwlock_unlock(&st->rwlock);
1190
pthread_rwlock_wrlock(&st->rwlock);
1191
1188
- for( rd = st->dimensions, last = NULL ; rd ; ) {
1192
+ for( rd = st->dimensions, last = NULL ; likely(rd) ; ) {
1193
// remove it only it is not updated in rrd_delete_unupdated_dimensions seconds
1194
1191
- if((rd->last_collected_time.tv_sec + (rrd_delete_unupdated_dimensions * st->update_every)) < st->last_collected_time.tv_sec) {
1192
- debug(D_RRD_STATS, "Removing obsolete dimension '%s' (%s) of '%s' (%s).", rd->name, rd->id, st->name, st->id);
1195
+ if(unlikely((rd->last_collected_time.tv_sec + (rrd_delete_unupdated_dimensions * st->update_every)) < st->last_collected_time.tv_sec)) {
1196
+ info("Removing obsolete dimension '%s' (%s) of '%s' (%s).", rd->name, rd->id, st->name, st->id);
1197
1194
- if(!last) {
1198
+ if(unlikely(!last)) {
1199
st->dimensions = rd->next;
1200
rd->next = NULL;
1201
rrddim_free(st, rd);
@@ -1211,13 +1215,16 @@ unsigned long long rrdset_done(RRDSET *st)
1215
rd = rd->next;
1216
}
1217
1214
- if(!st->dimensions) st->enabled = 0;
1218
+ if(unlikely(!st->dimensions)) {
1219
+ info("Disabling chart %s (%s) since it does not have any dimensions", st->name, st->id);
1220
+ st->enabled = 0;
1221
+ }
1222
}
1223
}
1224
1225
pthread_rwlock_unlock(&st->rwlock);
1226
1220
- if(pthread_setcancelstate(oldstate, NULL) != 0)
1227
+ if(unlikely(pthread_setcancelstate(oldstate, NULL) != 0))
1228
error("Cannot set pthread cancel state to RESTORE (%d).", oldstate);
1229
1230
return(st->usec_since_last_update);
@@ -1227,7 +1234,7 @@ unsigned long long rrdset_done(RRDSET *st)
1234
// find the oldest entry in the data, skipping all empty slots
1235
time_t rrdset_first_entry_t(RRDSET *st)
1236
{
1230
- if(!st->first_entry_t) return st->last_updated.tv_sec;
1237
+ if(unlikely(!st->first_entry_t)) return st->last_updated.tv_sec;
1238
1239
return st->first_entry_t / 1000000;
1240
}
src/storage_number.c
+1
@@ -2,6 +2,7 @@
2
#include <math.h>
3
#endif
4
5
+#include "common.h"
6
#include "log.h"
7
#include "storage_number.h"
8
src/unit_test.c
+1
@@ -3,6 +3,7 @@
3
#include <string.h>
4
#include <sys/resource.h>
5
6
+#include "common.h"
7
#include "storage_number.h"
8
#include "rrd.h"
9
#include "log.h"
src/url.c
+1
@@ -2,6 +2,7 @@
2
#include <string.h>
3
#include <ctype.h>
4
5
+#include "common.h"
6
#include "log.h"
7
#include "url.h"
8