Skip to content

Commit

Permalink
processes: add delay-irq for latest taskstats
Browse files Browse the repository at this point in the history
Linux taskstats version has updated to VERSION 14 while collectd only
support VERSION 8 at the moment.
This commit only add delay-irq in VERSION 14.
Other metrics after VERSION 8 should be added in later commits.

Signed-off-by: tiozhang <zyhtheonly@yeah.net>
  • Loading branch information
zzzyhtheonly committed Jul 25, 2024
1 parent 3b1c7d4 commit 68e0338
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/collectd.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,7 @@
# CollectContextSwitch true
# CollectMemoryMaps true
# CollectDelayAccounting false
# CollectDelayAccountingIRQ false
# CollectSystemContextSwitch false
# Process "name"
# ProcessMatch "name" "regex"
Expand Down
20 changes: 19 additions & 1 deletion src/collectd.conf.pod
Original file line number Diff line number Diff line change
Expand Up @@ -8106,6 +8106,7 @@ B<Synopsis:>
CollectFileDescriptor true
CollectContextSwitch true
CollectDelayAccounting false
CollectDelayAccountingIRQ false
CollectSystemContextSwitch false
Process "name"
ProcessMatch "name" "regex"
Expand Down Expand Up @@ -8154,6 +8155,22 @@ Disabled by default.
This option is only available on Linux, requires the C<libmnl> library and
requires the C<CAP_NET_ADMIN> capability at runtime.

=item B<CollectDelayAccountingIRQ> I<Boolean>

If enabled, collect Linux Delay Accounding information for matching processes.
Delay IRQ provides the time processes wait for the CPU running in IRQ context.
The metric is reported as "seconds per second"
using the C<delay_rate> type, e.g. C<delay_rate-delay-irq>.
Disabled by default.

This option is only available on Linux, requires the C<libmnl> library and
requires the C<CAP_NET_ADMIN> capability at runtime.

Note that if you are using your customized Linux system, please make sure
`/usr/include/linux/taskstats.h` (in C<libmnl> by default) is equal to
`/your_cutomized_linux_source_path/include/uapi/linux/taskstats.h`.
Otherwise metrics in B<CollectDelayAccounting> would not work.

=item B<CollectFileDescriptor> I<Boolean>

Collect number of file descriptors of matched processes.
Expand All @@ -8175,7 +8192,8 @@ blocks.
=back

The B<CollectContextSwitch>, B<CollectDelayAccounting>,
B<CollectFileDescriptor> and B<CollectMemoryMaps> options may be used inside
B<CollectDelayAccounting>, B<CollectFileDescriptor>
and B<CollectMemoryMaps> options may be used inside
B<Process> and B<ProcessMatch> blocks. When used there, these options affect
reporting the corresponding processes only. Outside of B<Process> and
B<ProcessMatch> blocks these options set the default value for subsequent
Expand Down
43 changes: 43 additions & 0 deletions src/processes.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ typedef struct procstat_entry_s {
value_to_rate_state_t delay_blkio;
value_to_rate_state_t delay_swapin;
value_to_rate_state_t delay_freepages;
/* taskstats v14 */
value_to_rate_state_t delay_irq;
#endif

struct procstat_entry_s *next;
Expand Down Expand Up @@ -292,11 +294,14 @@ typedef struct procstat {
gauge_t delay_blkio;
gauge_t delay_swapin;
gauge_t delay_freepages;
gauge_t delay_irq;

bool report_fd_num;
bool report_maps_num;
bool report_ctx_switch;
/* delay accounting */
bool report_delay;
bool report_delay_irq;

struct procstat *next;
struct procstat_entry_s *instances;
Expand All @@ -309,6 +314,7 @@ static bool report_ctx_switch;
static bool report_fd_num;
static bool report_maps_num;
static bool report_delay;
static bool report_delay_irq;
static bool report_sys_ctxt_switch;

#if HAVE_THREAD_INFO
Expand Down Expand Up @@ -381,6 +387,7 @@ static procstat_t *ps_list_register(const char *name, const char *regexp) {
new->report_maps_num = report_maps_num;
new->report_ctx_switch = report_ctx_switch;
new->report_delay = report_delay;
new->report_delay_irq = report_delay_irq;

#if HAVE_REGEX_H
if (regexp != NULL) {
Expand Down Expand Up @@ -519,6 +526,8 @@ static void ps_update_delay(procstat_t *out, procstat_entry_t *prev,
curr->delay.swapin_ns, now);
ps_update_delay_one(&out->delay_freepages, &prev->delay_freepages,
curr->delay.freepages_ns, now);
ps_update_delay_one(&out->delay_irq, &prev->delay_irq, curr->delay.irq_ns,
now);
}
#endif

Expand Down Expand Up @@ -636,6 +645,7 @@ static void ps_list_reset(void) {
ps->delay_blkio = NAN;
ps->delay_swapin = NAN;
ps->delay_freepages = NAN;
ps->delay_irq = NAN;

pse_prev = NULL;
pse = ps->instances;
Expand Down Expand Up @@ -679,6 +689,12 @@ static void ps_tune_instance(oconfig_item_t *ci, procstat_t *ps) {
#else
WARNING("processes plugin: The plugin has been compiled without support "
"for the \"CollectDelayAccounting\" option.");
} else if (strcasecmp(c->key, "CollectDelayAccountingIRQ") == 0) {
#if HAVE_LIBTASKSTATS
cf_util_get_boolean(c, &ps->report_delay_irq);
#else
WARNING("processes plugin: The plugin has been compiled without support "
"for the \"CollectDelayAccountingIRQ\" option.");
#endif
} else {
ERROR("processes plugin: Option \"%s\" not allowed here.", c->key);
Expand Down Expand Up @@ -747,6 +763,13 @@ static int ps_config(oconfig_item_t *ci) {
#else
WARNING("processes plugin: The plugin has been compiled without support "
"for the \"CollectDelayAccounting\" option.");
#endif
} else if (strcasecmp(c->key, "CollectDelayAccountingIRQ") == 0) {
#if HAVE_LIBTASKSTATS
cf_util_get_boolean(c, &report_delay_irq);
#else
WARNING("processes plugin: The plugin has been compiled without support "
"for the \"CollectDelayAccountingIRQ\" option.");
#endif
} else if (strcasecmp(c->key, "CollectSystemContextSwitch") == 0) {
cf_util_get_boolean(c, &report_sys_ctxt_switch);
Expand Down Expand Up @@ -967,6 +990,26 @@ static void ps_submit_proc_list(procstat_t *ps) {
plugin_dispatch_values(&vl);
}

if (ps->report_delay_irq) {
struct {
const char *type_instance;
gauge_t rate_ns;
} delay_metrics_extra[] = {
{"delay-irq", ps->delay_irq},
};
for (size_t i = 0; i < STATIC_ARRAY_SIZE(delay_metrics_extra); i++) {
if (isnan(delay_metrics_extra[i].rate_ns)) {
continue;
}
sstrncpy(vl.type, "delay_rate", sizeof(vl.type));
sstrncpy(vl.type_instance, delay_metrics_extra[i].type_instance,
sizeof(vl.type_instance));
vl.values[0].gauge = delay_metrics_extra[i].rate_ns / delay_factor;
vl.values_len = 1;
plugin_dispatch_values(&vl);
}
}

DEBUG(
"name = %s; num_proc = %lu; num_lwp = %lu; num_fd = %lu; num_maps = %lu; "
"vmem_size = %lu; vmem_rss = %lu; vmem_data = %lu; "
Expand Down
5 changes: 5 additions & 0 deletions src/utils/taskstats/taskstats.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,5 +303,10 @@ int ts_delay_by_tgid(ts_t *ts, uint32_t tgid, ts_delay_t *out) {
.swapin_ns = raw.swapin_delay_total,
.freepages_ns = raw.freepages_delay_total,
};

#if TASKSTATS_VERSION >= 14
out->irq_ns = raw.irq_delay_total;
#endif

return 0;
}
2 changes: 2 additions & 0 deletions src/utils/taskstats/taskstats.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ typedef struct {
uint64_t blkio_ns;
uint64_t swapin_ns;
uint64_t freepages_ns;
/* v14: Delay waiting for IRQ/SOFTIRQ */
uint64_t irq_ns;
} ts_delay_t;

ts_t *ts_create(void);
Expand Down

0 comments on commit 68e0338

Please sign in to comment.