From: Pavel Rochnyack Date: Thu, 23 May 2019 21:16:47 +0000 (+0700) Subject: virt plugin: Do not request cpu maps when not required X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=4436eed7d1b5e841a87604de85ff0267dfd1a631 virt plugin: Do not request cpu maps when not required --- diff --git a/src/virt.c b/src/virt.c index 17420269..64f9415d 100644 --- a/src/virt.c +++ b/src/virt.c @@ -1589,7 +1589,6 @@ static void vcpu_pin_submit(virDomainPtr dom, int max_cpus, int vcpu, static int get_vcpu_stats(virDomainPtr domain, unsigned short nr_virt_cpu) { int max_cpus = VIR_NODEINFO_MAXCPUS(nodeinfo); - int cpu_map_len = VIR_CPU_MAPLEN(max_cpus); virVcpuInfoPtr vinfo = calloc(nr_virt_cpu, sizeof(*vinfo)); if (vinfo == NULL) { @@ -1597,11 +1596,17 @@ static int get_vcpu_stats(virDomainPtr domain, unsigned short nr_virt_cpu) { return -1; } - unsigned char *cpumaps = calloc(nr_virt_cpu, cpu_map_len); - if (cpumaps == NULL) { - ERROR(PLUGIN_NAME " plugin: calloc failed."); - sfree(vinfo); - return -1; + int cpu_map_len = 0; + unsigned char *cpumaps = NULL; + if (extra_stats & ex_stats_vcpupin) { + cpu_map_len = VIR_CPU_MAPLEN(max_cpus); + cpumaps = calloc(nr_virt_cpu, cpu_map_len); + + if (cpumaps == NULL) { + ERROR(PLUGIN_NAME " plugin: calloc failed."); + sfree(vinfo); + return -1; + } } int status =