Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx> --- data/org.libvirt.Connect.xml | 7 +++++++ src/connect.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 1502849..0dcc6e8 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -173,6 +173,13 @@ <arg name="maxCells" type="i" direction="in"/> <arg name="freeMems" type="at" direction="out"/> </method> + <method name="NodeGetCPUStats"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetCPUStats"/> + <arg name="cpuNum" type="i" direction="in"/> + <arg name="flags" type="u" direction="in"/> + <arg name="cpuStats" type="a{st}" direction="out"/> + </method> <signal name="DomainEvent"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEventCallback"/> diff --git a/src/connect.c b/src/connect.c index 78b438e..80b5c67 100644 --- a/src/connect.c +++ b/src/connect.c @@ -880,6 +880,47 @@ virtDBusConnectNodeGetCellsFreeMemory(GVariant *inArgs, *outArgs = g_variant_new_tuple(&res, 1); } +static void +virtDBusConnectNodeGetCPUStats(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + + gint cpuNum; + guint flags; + g_autofree virNodeCPUStatsPtr stats = NULL; + gint count = 0; + gint ret; + GVariant *gret; + GVariantBuilder builder; + + g_variant_get(inArgs, "(iu)", &cpuNum, &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + ret = virNodeGetCPUStats(connect->connection, cpuNum, NULL, &count, flags); + if (ret == 0 && count != 0) { + stats = g_new0(virNodeCPUStats, count); + if (virNodeGetCPUStats(connect->connection, cpuNum, stats, + &count, flags) < 0) { + return virtDBusUtilSetLastVirtError(error); + } + } + + g_variant_builder_init(&builder, G_VARIANT_TYPE("a{st}")); + for (gint i = 0; i < count; i++) + g_variant_builder_add(&builder, "{st}", stats[i].field, stats[i].value); + gret = g_variant_builder_end(&builder); + + *outArgs = g_variant_new_tuple(&gret, 1); +} + static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = { { "Encrypted", virtDBusConnectGetEncrypted, NULL }, { "Hostname", virtDBusConnectGetHostname, NULL }, @@ -912,6 +953,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NetworkLookupByName", virtDBusConnectNetworkLookupByName }, { "NetworkLookupByUUID", virtDBusConnectNetworkLookupByUUID }, { "NodeGetCellsFreeMemory", virtDBusConnectNodeGetCellsFreeMemory }, + { "NodeGetCPUStats", virtDBusConnectNodeGetCPUStats }, { 0 } }; -- 2.15.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list