On Mon, Mar 11, 2019 at 17:56:18 -0300, Julio Faracco wrote: > This method is responsible to fetch all Balloon Memory Stats and store > data into virDomainStatsRecordPtr structure. > > Signed-off-by: Julio Faracco <jcfaracco@xxxxxxxxx> > --- > src/lxc/lxc_driver.c | 71 ++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 71 insertions(+) > > diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c > index 1190d67a81..ea48214073 100644 > --- a/src/lxc/lxc_driver.c > +++ b/src/lxc/lxc_driver.c > @@ -2876,6 +2876,77 @@ lxcDomainGetBlkioParameters(virDomainPtr dom, > return ret; > } > > +static int > +lxcDomainGetBalloonStats(virDomainObjPtr dom, > + virDomainStatsRecordPtr record, > + int *maxparams) > +{ > + virLXCDomainObjPrivatePtr priv = dom->privateData; > + virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR]; > + unsigned long long swap_usage; > + unsigned long mem_usage; > + size_t i; > + int ret = -1; > + > + if (virTypedParamsAddULLong(&record->params, > + &record->nparams, > + maxparams, > + "balloon.maximum", > + virDomainDefGetMemoryTotal(dom->def)) < 0) > + return -1; > + > + if (virTypedParamsAddULLong(&record->params, > + &record->nparams, > + maxparams, > + "balloon.current", > + virDomainDefGetMemoryTotal(dom->def)) < 0) > + return -1; > + > + if (virCgroupGetMemSwapUsage(priv->cgroup, &swap_usage) < 0) > + return -1; > + > + if (virCgroupGetMemoryUsage(priv->cgroup, &mem_usage) < 0) > + return -1; > + > + ret = 0; > + if (ret < *maxparams) { > + stats[ret].tag = VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON; > + stats[ret].val = dom->def->mem.cur_balloon; > + ret++; Erm, why do you put this into the temporary 'stats' variable ... > + } > + if (ret < *maxparams) { > + stats[ret].tag = VIR_DOMAIN_MEMORY_STAT_SWAP_IN; > + stats[ret].val = swap_usage; > + ret++; > + } > + if (ret < *maxparams) { > + stats[ret].tag = VIR_DOMAIN_MEMORY_STAT_RSS; > + stats[ret].val = mem_usage; > + ret++; > + } > + > +#define LXC_STORE_MEM_RECORD(TAG, NAME) \ > + if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_ ##TAG) \ > + if (virTypedParamsAddULLong(&record->params, \ > + &record->nparams, \ > + maxparams, \ > + "balloon." NAME, \ ... if you then convert it right away into typed parameters? That does not make much sense. You should fill the parameters right away. > + stats[i].val) < 0) \ > + return -1; > + > + for (i = 0; i < ret; i++) { > + LXC_STORE_MEM_RECORD(SWAP_IN, "swap_in") > + LXC_STORE_MEM_RECORD(SWAP_OUT, "swap_out") > + LXC_STORE_MEM_RECORD(MAJOR_FAULT, "major_fault") > + LXC_STORE_MEM_RECORD(MINOR_FAULT, "minor_fault") > + LXC_STORE_MEM_RECORD(AVAILABLE, "available") > + LXC_STORE_MEM_RECORD(UNUSED, "unused") > + } > + > +#undef LXC_STORE_MEM_RECORD > + > + return 0; > +} > > static int > lxcDomainInterfaceStats(virDomainPtr dom, > -- > 2.19.1 > > -- > libvir-list mailing list > libvir-list@xxxxxxxxxx > https://www.redhat.com/mailman/listinfo/libvir-list
Attachment:
signature.asc
Description: PGP signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list