diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2018-11-07 12:19:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2018-11-07 12:20:17 +0000 |
commit | a64a253794ac64cb40befee54db53bde17dd0d49 (patch) | |
tree | c1024acc5f6e508814b944d99f112259bb28b1be /collectors/proc.plugin/proc_interrupts.c | |
parent | New upstream version 1.10.0+dfsg (diff) | |
download | netdata-a64a253794ac64cb40befee54db53bde17dd0d49.tar.xz netdata-a64a253794ac64cb40befee54db53bde17dd0d49.zip |
New upstream version 1.11.0+dfsgupstream/1.11.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | collectors/proc.plugin/proc_interrupts.c (renamed from src/proc_interrupts.c) | 77 |
1 files changed, 36 insertions, 41 deletions
diff --git a/src/proc_interrupts.c b/collectors/proc.plugin/proc_interrupts.c index 867f39eb2..73b117179 100644 --- a/src/proc_interrupts.c +++ b/collectors/proc.plugin/proc_interrupts.c @@ -1,4 +1,9 @@ -#include "common.h" +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "plugin_proc.h" + +#define PLUGIN_PROC_MODULE_INTERRUPTS_NAME "/proc/interrupts" +#define CONFIG_SECTION_PLUGIN_PROC_INTERRUPTS "plugin:" PLUGIN_PROC_CONFIG_NAME ":" PLUGIN_PROC_MODULE_INTERRUPTS_NAME #define MAX_INTERRUPT_NAME 50 @@ -51,16 +56,16 @@ static inline struct interrupt *get_interrupts_array(size_t lines, int cpus) { int do_proc_interrupts(int update_every, usec_t dt) { (void)dt; static procfile *ff = NULL; - static int cpus = -1, do_per_core = -1; + static int cpus = -1, do_per_core = CONFIG_BOOLEAN_INVALID; struct interrupt *irrs = NULL; - if(unlikely(do_per_core == -1)) - do_per_core = config_get_boolean("plugin:proc:/proc/interrupts", "interrupts per core", 1); + if(unlikely(do_per_core == CONFIG_BOOLEAN_INVALID)) + do_per_core = config_get_boolean_ondemand(CONFIG_SECTION_PLUGIN_PROC_INTERRUPTS, "interrupts per core", CONFIG_BOOLEAN_AUTO); if(unlikely(!ff)) { char filename[FILENAME_MAX + 1]; snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/proc/interrupts"); - ff = procfile_open(config_get("plugin:proc:/proc/interrupts", "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT); + ff = procfile_open(config_get(CONFIG_SECTION_PLUGIN_PROC_INTERRUPTS, "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT); } if(unlikely(!ff)) return 1; @@ -109,8 +114,8 @@ int do_proc_interrupts(int update_every, usec_t dt) { if(unlikely(!irr->id || !irr->id[0])) continue; size_t idlen = strlen(irr->id); - if(unlikely(idlen && irr->id[idlen - 1] == ':')) - irr->id[idlen - 1] = '\0'; + if(irr->id[idlen - 1] == ':') + irr->id[--idlen] = '\0'; int c; for(c = 0; c < cpus ;c++) { @@ -125,7 +130,6 @@ int do_proc_interrupts(int update_every, usec_t dt) { if(unlikely(isdigit(irr->id[0]) && (uint32_t)(cpus + 2) < words)) { strncpyz(irr->name, procfile_lineword(ff, l, words - 1), MAX_INTERRUPT_NAME); size_t nlen = strlen(irr->name); - idlen = strlen(irr->id); if(likely(nlen + 1 + idlen <= MAX_INTERRUPT_NAME)) { irr->name[nlen] = '_'; strncpyz(&irr->name[nlen + 1], irr->id, MAX_INTERRUPT_NAME - nlen - 1); @@ -154,9 +158,9 @@ int do_proc_interrupts(int update_every, usec_t dt) { , NULL , "System interrupts" , "interrupts/s" - , "proc" - , "interrupts" - , 1000 + , PLUGIN_PROC_NAME + , PLUGIN_PROC_MODULE_INTERRUPTS_NAME + , NETDATA_CHART_PRIO_SYSTEM_INTERRUPTS , update_every , RRDSET_TYPE_STACKED ); @@ -165,34 +169,30 @@ int do_proc_interrupts(int update_every, usec_t dt) { for(l = 0; l < lines ;l++) { struct interrupt *irr = irrindex(irrs, l, cpus); - if(unlikely(!irr->used)) continue; - - // some interrupt may have changed without changing the total number of lines - // if the same number of interrupts have been added and removed between two - // calls of this function. - if(unlikely(!irr->rd || strncmp(irr->rd->name, irr->name, MAX_INTERRUPT_NAME) != 0)) { - irr->rd = rrddim_find(st_system_interrupts, irr->id); - - if(unlikely(!irr->rd)) + if(irr->used && irr->total) { + // some interrupt may have changed without changing the total number of lines + // if the same number of interrupts have been added and removed between two + // calls of this function. + if(unlikely(!irr->rd || strncmp(irr->rd->name, irr->name, MAX_INTERRUPT_NAME) != 0)) { irr->rd = rrddim_add(st_system_interrupts, irr->id, irr->name, 1, 1, RRD_ALGORITHM_INCREMENTAL); - else rrddim_set_name(st_system_interrupts, irr->rd, irr->name); - // also reset per cpu RRDDIMs to avoid repeating strncmp() in the per core loop - if(likely(do_per_core)) { - int c; - for (c = 0; c < cpus ;c++) irr->cpu[c].rd = NULL; + // also reset per cpu RRDDIMs to avoid repeating strncmp() in the per core loop + if(likely(do_per_core != CONFIG_BOOLEAN_NO)) { + int c; + for(c = 0; c < cpus; c++) irr->cpu[c].rd = NULL; + } } - } - rrddim_set_by_pointer(st_system_interrupts, irr->rd, irr->total); + rrddim_set_by_pointer(st_system_interrupts, irr->rd, irr->total); + } } rrdset_done(st_system_interrupts); // -------------------------------------------------------------------- - if(likely(do_per_core)) { + if(likely(do_per_core != CONFIG_BOOLEAN_NO)) { static RRDSET **core_st = NULL; static int old_cpus = 0; @@ -219,9 +219,9 @@ int do_proc_interrupts(int update_every, usec_t dt) { , "cpu.interrupts" , title , "interrupts/s" - , "proc" - , "interrupts" - , 1100 + c + , PLUGIN_PROC_NAME + , PLUGIN_PROC_MODULE_INTERRUPTS_NAME + , NETDATA_CHART_PRIO_INTERRUPTS_PER_CORE + c , update_every , RRDSET_TYPE_STACKED ); @@ -230,19 +230,14 @@ int do_proc_interrupts(int update_every, usec_t dt) { for(l = 0; l < lines ;l++) { struct interrupt *irr = irrindex(irrs, l, cpus); - - if(unlikely(!irr->used)) continue; - - if(unlikely(!irr->cpu[c].rd)) { - irr->cpu[c].rd = rrddim_find(core_st[c], irr->id); - - if(unlikely(!irr->cpu[c].rd)) + if(irr->used && (do_per_core == CONFIG_BOOLEAN_YES || irr->cpu[c].value)) { + if(unlikely(!irr->cpu[c].rd)) { irr->cpu[c].rd = rrddim_add(core_st[c], irr->id, irr->name, 1, 1, RRD_ALGORITHM_INCREMENTAL); - else rrddim_set_name(core_st[c], irr->cpu[c].rd, irr->name); - } + } - rrddim_set_by_pointer(core_st[c], irr->cpu[c].rd, irr->cpu[c].value); + rrddim_set_by_pointer(core_st[c], irr->cpu[c].rd, irr->cpu[c].value); + } } rrdset_done(core_st[c]); |