On Wed, Mar 25, 2015 at 19:39:12 +0100, Ján Tomko wrote:
Add cpuTime to virDomainIOThreadInfo, fill it out in the qemu driver
and print it in virsh.
---
daemon/remote.c | 1 +
include/libvirt/libvirt-domain.h | 1 +
src/qemu/qemu_driver.c | 10 ++++++++++
src/remote/remote_driver.c | 1 +
src/remote/remote_protocol.x | 1 +
src/remote_protocol-structs | 1 +
tools/virsh-domain.c | 18 ++++++++++++++----
7 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c
index 2f4df48..1f44ed5 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -2317,6 +2317,7 @@ remoteDispatchDomainGetIOThreadInfo(virNetServerPtr server
ATTRIBUTE_UNUSED,
*/
dst->cpumap.cpumap_len = info[i]->cpumaplen;
dst->cpumap.cpumap_val = (char *)info[i]->cpumap;
+ dst->cpu_time = info[i]->cpuTime;
info[i]->cpumap = NULL;
}
} else {
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 7be4219..cca08ca 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -1603,6 +1603,7 @@ struct _virDomainIOThreadInfo {
unsigned char *cpumap; /* CPU map for thread. A pointer to an */
/* array of real CPUs (in 8-bit bytes) */
int cpumaplen; /* cpumap size */
+ unsigned long long cpuTime; /* CPU time used, in nanoseconds */
Perhaps add a note that 0 is returned for offline VMs?
};
void virDomainIOThreadInfoFree(virDomainIOThreadInfoPtr info);
...
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index cb9cb9d..929cceb 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
...
@@ -6875,12 +6875,22 @@ cmdIOThreadInfo(vshControl *ctl, const vshCmd
*cmd)
vshPrint(ctl, " %-15u ", info[i]->iothread_id);
vshPrint(ctl, " %-15s ", mapstr);
+ if (info[i]->cpuTime != 0) {
+ double cpuUsed = info[i]->cpuTime;
+
+ cpuUsed /= 1000000000.0;
+
+ vshPrint(ctl, " %.1lf s ", cpuUsed);
+ }
Should we print a dash or something when the data is not present?
vshPrint(ctl, "\n");
- virDomainIOThreadInfoFree(info[i]);
}
- VIR_FREE(info);
cleanup:
+ if (niothreads > 0) {
+ for (i = 0; i < niothreads; i++)
+ virDomainIOThreadInfoFree(info[i]);
+ VIR_FREE(info);
If you initialize info to NULL when it's defined you can avoid having
the if (niothreads > 0) condition.
+ }
virBitmapFree(map);
virDomainFree(dom);
return niothreads >= 0;
ACK. I'll not insisting on fixing all the comments, but I'd prefer to
have a dash in the output if CPU time doesn't make sense.
Peter