On Thu, Dec 10, 2015 at 08:34:34PM +0800, Qiaowei Ren wrote: > This patch implement the internal driver API for perf event into > qemu driver. > > Signed-off-by: Qiaowei Ren <qiaowei.ren@xxxxxxxxx> > --- > include/libvirt/libvirt-domain.h | 1 + > src/qemu/qemu_domain.h | 3 + > src/qemu/qemu_driver.c | 133 +++++++++++++++++++++++++++++++++++++++ > src/qemu/qemu_process.c | 6 ++ > 4 files changed, 143 insertions(+) > > @@ -19427,6 +19508,55 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver, > > #undef QEMU_ADD_COUNT_PARAM > > +static int > +qemuDomainGetStatsPerfCmt(virPerfPtr perf, > + virDomainStatsRecordPtr record, > + int *maxparams) > +{ > + uint64_t cache = 0; > + > + if (virPerfReadEvent(perf, VIR_PERF_EVENT_CMT, &cache) < 0) > + return -1; > + > + if (virTypedParamsAddULLong(&record->params, > + &record->nparams, > + maxparams, > + "perf.cache", > + cache) < 0) > + return -1; > + > + return 0; > +} > + > +static int > +qemuDomainGetStatsPerf(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, > + virDomainObjPtr dom, > + virDomainStatsRecordPtr record, > + int *maxparams, > + unsigned int privflags ATTRIBUTE_UNUSED) > +{ > + size_t i; > + qemuDomainObjPrivatePtr priv = dom->privateData; > + int ret = -1; > + > + for (i = 0; i < VIR_PERF_EVENT_LAST; i++) { > + if (!virPerfEventIsEnabled(priv->perf, i)) > + continue; > + > + switch (i) { > + case VIR_PERF_EVENT_CMT: > + if (qemuDomainGetStatsPerfCmt(priv->perf, record, maxparams)) > + goto cleanup; I guess that should be checking '< 0' > + break; > + } > + } > + > + ret = 0; > + > + cleanup: > + return ret; > +} > + > typedef int > (*qemuDomainGetStatsFunc)(virQEMUDriverPtr driver, > virDomainObjPtr dom, > @@ -19447,6 +19577,7 @@ static struct qemuDomainGetStatsWorker qemuDomainGetStatsWorkers[] = { > { qemuDomainGetStatsVcpu, VIR_DOMAIN_STATS_VCPU, false }, > { qemuDomainGetStatsInterface, VIR_DOMAIN_STATS_INTERFACE, false }, > { qemuDomainGetStatsBlock, VIR_DOMAIN_STATS_BLOCK, true }, > + { qemuDomainGetStatsPerf, VIR_DOMAIN_STATS_PERF, false }, > { NULL, 0, false } > }; > > @@ -20207,6 +20338,8 @@ static virHypervisorDriver qemuHypervisorDriver = { > .domainMigrateFinish3 = qemuDomainMigrateFinish3, /* 0.9.2 */ > .domainMigrateConfirm3 = qemuDomainMigrateConfirm3, /* 0.9.2 */ > .domainSendKey = qemuDomainSendKey, /* 0.9.4 */ > + .domainGetPerfEvents = qemuDomainGetPerfEvents, /* 1.3.1 */ > + .domainSetPerfEvents = qemuDomainSetPerfEvents, /* 1.3.1 */ > .domainBlockJobAbort = qemuDomainBlockJobAbort, /* 0.9.4 */ > .domainGetBlockJobInfo = qemuDomainGetBlockJobInfo, /* 0.9.4 */ > .domainBlockJobSetSpeed = qemuDomainBlockJobSetSpeed, /* 0.9.4 */ > diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c > index 4201962..8679d29 100644 > --- a/src/qemu/qemu_process.c > +++ b/src/qemu/qemu_process.c > @@ -4844,6 +4844,10 @@ qemuProcessLaunch(virConnectPtr conn, > if (qemuSetupCgroup(driver, vm, nnicindexes, nicindexes) < 0) > goto cleanup; > > + priv->perf = virPerfNew(); > + if (!priv->perf) > + goto cleanup; > + You also need todo this in qemuProcessReconnect so that it works after libvirtd is restarted, and in qemuProcessAttach too Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list