From nobody Sun May 19 06:05:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=weirdnatto.in ARC-Seal: i=1; a=rsa-sha256; t=1662546898; cv=none; d=zohomail.com; s=zohoarc; b=kYP7KnvTRuePzBGRtJ5Ta/7u5k/O4jahkCEllGgDyM0y66hGgqoH6g1caQfIs9BB/031ve7w/zTIkR7rbFnQ50bskzJqG2X0CJmyTQiOAfuMxtsoXWTQg6c7lCgJv1rMZxYMgMeweODMdi4j5nK4XmGDKkYXIQMRWxqXEwGnDso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662546898; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1VmHz6msWRIg0LkBXOpoC4+7HpuQKZudu7dDiEiw9L8=; b=IbhRZVK3yuOyv5SmTPzgAqwpiFrpi3agk0jTIEhfl4Uw8+XqNX4kXvCTIoltMvtz9rbwGNdhpFpseWPtuF1fiPVz/Ao7OpImz4c5GRGVrok7aFVfOM1abmGIGbVLoSNKyvY/yTjfH6RSbfoLe8gLZ3/TMJQBfhnmn2bKVCDORwc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1662546898948238.60982138302222; Wed, 7 Sep 2022 03:34:58 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-675-sVaVna5fMDud4g9KAQVE3Q-1; Wed, 07 Sep 2022 06:34:54 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 09F2480D196; Wed, 7 Sep 2022 10:34:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A6EE492C3B; Wed, 7 Sep 2022 10:34:51 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3F08F1946A48; Wed, 7 Sep 2022 10:34:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8C10A1946A40 for ; Wed, 7 Sep 2022 10:34:50 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5DA5C2166B29; Wed, 7 Sep 2022 10:34:50 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 59BEC2166B26 for ; Wed, 7 Sep 2022 10:34:50 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3CEC2803301 for ; Wed, 7 Sep 2022 10:34:50 +0000 (UTC) Received: from mail.weirdnatto.in (140.238.225.67 [140.238.225.67]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-343-8uBEa3bpOPa6TOsZs0NzYg-1; Wed, 07 Sep 2022 06:34:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662546897; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=1VmHz6msWRIg0LkBXOpoC4+7HpuQKZudu7dDiEiw9L8=; b=P5AnYgbUNOu/4mCJs+tUXVWivnWmebCrv/FcJRdcmiHSnOa5TmWI1wDUa/0az+a4ZBc3Xd N0SR/2oSXmyVuQS1xhkP7VmQ3TX1NKzFPkzNQAtT4IGo3zS4fZ7eFeWrMDHu7PcizH3l2Y 3DkYAcTUk8iAVVES5NF7gxyvMz5CzyI= X-MC-Unique: sVaVna5fMDud4g9KAQVE3Q-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: 8uBEa3bpOPa6TOsZs0NzYg-1 From: Amneesh Singh To: libvir-list@redhat.com Subject: [RFC PATCH 1/6] qemu_monitor: add qemuMonitorQueryStatsSchema Date: Wed, 7 Sep 2022 16:04:18 +0530 Message-Id: <20220907103423.662344-2-natto@weirdnatto.in> In-Reply-To: <20220907103423.662344-1-natto@weirdnatto.in> References: <20220907103423.662344-1-natto@weirdnatto.in> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mkletzan@redhat.com, pbonzini@redhat.com, Amneesh Singh Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662546900676100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Related: https://gitlab.com/libvirt/libvirt/-/issues/276 This patch adds a simple API for "query-stats-schemas" QMP command Signed-off-by: Amneesh Singh Reviewed-by: Martin Kletzander --- src/qemu/qemu_monitor.c | 29 +++++++++++ src/qemu/qemu_monitor.h | 35 ++++++++++++++ src/qemu/qemu_monitor_json.c | 93 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 4 ++ 4 files changed, 161 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index c2808c75a3..9581e90796 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4355,6 +4355,35 @@ qemuMonitorQueryStatsProviderNew(qemuMonitorQuerySta= tsProviderType provider_type } =20 =20 +VIR_ENUM_IMPL(qemuMonitorQueryStatsUnit, + QEMU_MONITOR_QUERY_STATS_UNIT_LAST, + "bytes", + "seconds", + "cycles", + "boolean", +); + + +VIR_ENUM_IMPL(qemuMonitorQueryStatsType, + QEMU_MONITOR_QUERY_STATS_TYPE_LAST, + "cumulative", + "instant", + "peak", + "linear-histogram", + "log2-histogram", +); + + +GHashTable * +qemuMonitorQueryStatsSchema(qemuMonitor *mon, + qemuMonitorQueryStatsProviderType provider_typ= e) +{ + QEMU_CHECK_MONITOR_NULL(mon); + + return qemuMonitorJSONQueryStatsSchema(mon, provider_type); +} + + virJSONValue * qemuMonitorQueryStats(qemuMonitor *mon, qemuMonitorQueryStatsTargetType target, diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 63269e15bc..4c817dea20 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1521,6 +1521,41 @@ qemuMonitorQueryStatsProviderNew(qemuMonitorQuerySta= tsProviderType provider_type G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuMonitorQueryStatsProvider, qemuMonitorQueryStatsProviderFree); =20 +typedef enum { + QEMU_MONITOR_QUERY_STATS_UNIT_BYTES, + QEMU_MONITOR_QUERY_STATS_UNIT_SECONDS, + QEMU_MONITOR_QUERY_STATS_UNIT_CYCLES, + QEMU_MONITOR_QUERY_STATS_UNIT_BOOLEAN, + QEMU_MONITOR_QUERY_STATS_UNIT_LAST, +} qemuMonitorQueryStatsUnitType; + +VIR_ENUM_DECL(qemuMonitorQueryStatsUnit); + +typedef enum { + QEMU_MONITOR_QUERY_STATS_TYPE_CUMULATIVE, + QEMU_MONITOR_QUERY_STATS_TYPE_INSTANT, + QEMU_MONITOR_QUERY_STATS_TYPE_PEAK, + QEMU_MONITOR_QUERY_STATS_TYPE_LINEAR_HISTOGRAM, + QEMU_MONITOR_QUERY_STATS_TYPE_LOG2_HISTOGRAM, + QEMU_MONITOR_QUERY_STATS_TYPE_LAST, +} qemuMonitorQueryStatsTypeType; + +VIR_ENUM_DECL(qemuMonitorQueryStatsType); + +typedef struct _qemuMonitorQueryStatsSchemaData qemuMonitorQueryStatsSchem= aData; +struct _qemuMonitorQueryStatsSchemaData { + qemuMonitorQueryStatsTargetType target; + qemuMonitorQueryStatsUnitType unit; + qemuMonitorQueryStatsTypeType type; + unsigned int bucket_size; + int base; + int exponent; +}; + +GHashTable * +qemuMonitorQueryStatsSchema(qemuMonitor *mon, + qemuMonitorQueryStatsProviderType provider_typ= e); + virJSONValue * qemuMonitorQueryStats(qemuMonitor *mon, qemuMonitorQueryStatsTargetType target, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 70fba50e6c..f822a8908c 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -8575,6 +8575,99 @@ qemuMonitorJSONMigrateRecover(qemuMonitor *mon, return qemuMonitorJSONCheckError(cmd, reply); } =20 +static GHashTable * +qemuMonitorJSONExtractQueryStatsSchema(virJSONValue *json) +{ + g_autoptr(GHashTable) schema =3D virHashNew(g_free); + size_t i; + + for (i =3D 0; i < virJSONValueArraySize(json); i++) { + virJSONValue *obj, *stats; + const char *target_str; + int target; + size_t j; + + obj =3D virJSONValueArrayGet(json, i); + + if (!virJSONValueIsObject(obj)) + continue; + + stats =3D virJSONValueObjectGetArray(obj, "stats"); + + if (!virJSONValueIsArray(stats)) + continue; + + target_str =3D virJSONValueObjectGetString(obj, "target"); + target =3D qemuMonitorQueryStatsTargetTypeFromString(target_str); + + for (j =3D 0; j < virJSONValueArraySize(stats); j++) { + virJSONValue *stat =3D virJSONValueArrayGet(stats, j); + const char *name, *type_str, *unit_str; + qemuMonitorQueryStatsSchemaData *data; + int type, unit; + + if (!virJSONValueIsObject(stat)) + continue; + + name =3D virJSONValueObjectGetString(stat, "name"); + + if (!name) + continue; + + type_str =3D virJSONValueObjectGetString(stat, "type"); + unit_str =3D virJSONValueObjectGetString(stat, "unit"); + type =3D qemuMonitorQueryStatsTypeTypeFromString(type_str); + unit =3D qemuMonitorQueryStatsUnitTypeFromString(unit_str); + + data =3D g_new0(qemuMonitorQueryStatsSchemaData, 1); + data->target =3D (target =3D=3D -1) ? QEMU_MONITOR_QUERY_STATS= _TARGET_LAST : target; + data->type =3D (type =3D=3D -1) ? QEMU_MONITOR_QUERY_STATS_TYP= E_LAST : type; + data->unit =3D (unit =3D=3D -1) ? QEMU_MONITOR_QUERY_STATS_UNI= T_LAST : unit; + + if (virJSONValueObjectGetNumberInt(stat, "base", &data->base) = < 0 || + virJSONValueObjectGetNumberInt(stat, "exponent", &data->ex= ponent) < 0) + data->base =3D 0, data->exponent =3D 0; + + /* a base of zero means that there is simply no scale, data->e= xponent is + set to 0 just for safety measures */ + + if (data->type =3D=3D QEMU_MONITOR_QUERY_STATS_TYPE_LINEAR_HIS= TOGRAM && + virJSONValueObjectGetNumberUint(stat, "bucket-size", &data= ->bucket_size) < 0) + data->bucket_size =3D 0; + + virHashAddEntry(schema, name, data); + } + } + + return g_steal_pointer(&schema); +} + +GHashTable * +qemuMonitorJSONQueryStatsSchema(qemuMonitor *mon, + qemuMonitorQueryStatsProviderType provider= _type) +{ + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; + virJSONValue *ret; + + const char *type_str =3D qemuMonitorQueryStatsProviderTypeToString(pro= vider_type); + + if (!(cmd =3D qemuMonitorJSONMakeCommand("query-stats-schemas", + "S:provider", type_str, + NULL))) + return NULL; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + return NULL; + + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) + return NULL; + + ret =3D virJSONValueObjectGetArray(reply, "return"); + + return qemuMonitorJSONExtractQueryStatsSchema(ret); +} + =20 /** * qemuMonitorJSONQueryStats: diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index a53e6423df..c910e46504 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -813,6 +813,10 @@ int qemuMonitorJSONMigrateRecover(qemuMonitor *mon, const char *uri); =20 +GHashTable * +qemuMonitorJSONQueryStatsSchema(qemuMonitor *mon, + qemuMonitorQueryStatsProviderType provider= _type); + virJSONValue * qemuMonitorJSONQueryStats(qemuMonitor *mon, qemuMonitorQueryStatsTargetType target, --=20 2.37.1 From nobody Sun May 19 06:05:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=weirdnatto.in ARC-Seal: i=1; a=rsa-sha256; t=1662546900; cv=none; d=zohomail.com; s=zohoarc; b=ehGhaGAH/vobN6kO8ZxmCqy8X4eqt64W/vyVpY5wSgyorkG3hJ86DInt+cbcLHDbxKipssSZ2/oFzyHKRtzH2vB3sEzMu9CSpHznV+VZbiRofXOdE561BP+CwyXiH49UsJSGNbuxDTiofntzn7NNaOdwlhb1tAA9SIBWoowATSo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662546900; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BH2bkGVdp5tp+Tr8RFoLhkOSUkd5uVdlNDMe9fGtiaM=; b=jpdOjsp6luKZy2YRwqjKUXey4Y1YpKU7vZj9HUnMHDa8v0WmPY4RC+XnU/0HBcUlDjd+cKsdJE+b5OgACwhxXMRk/4LmYcUbzcoKesJQqDRlABCpm6IoX0t54R+AN43IdW+gkW9tVEhQtARQEuFsfheGlyPcFu/HFLpntJtKiAA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1662546900019717.5880282887936; Wed, 7 Sep 2022 03:35:00 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-12-dhwA9peQNcauQnHSrRQjHA-1; Wed, 07 Sep 2022 06:34:56 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6363C85A58C; Wed, 7 Sep 2022 10:34:54 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 120D6403D0DA; Wed, 7 Sep 2022 10:34:54 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DFB251946A57; Wed, 7 Sep 2022 10:34:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8CA3A1946A51 for ; Wed, 7 Sep 2022 10:34:52 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 6F7DD141513D; Wed, 7 Sep 2022 10:34:52 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 69890141513E for ; Wed, 7 Sep 2022 10:34:52 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 53A54101E989 for ; Wed, 7 Sep 2022 10:34:52 +0000 (UTC) Received: from mail.weirdnatto.in (140.238.225.67 [140.238.225.67]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-624-BoBhpE3JMSqSTExSKyWMMQ-1; Wed, 07 Sep 2022 06:34:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662546898; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=BH2bkGVdp5tp+Tr8RFoLhkOSUkd5uVdlNDMe9fGtiaM=; b=F7/JqjTEOV1gbZDLstNhhN0j/c9ts607LUjN03Jk9YCQGik2EzTBc7qg4uDWeZpAExvVFQ w0P9Q4ZeHyiO4OzkuSoiUgjFv5blMZuWV058cmVGUQqya1eSwUCLEQN2smqzI0GQ3dUNEl BFTeJQozUj0WctwNd9oUxo4xlplrS9A= X-MC-Unique: dhwA9peQNcauQnHSrRQjHA-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: BoBhpE3JMSqSTExSKyWMMQ-1 From: Amneesh Singh To: libvir-list@redhat.com Subject: [RFC PATCH 2/6] qemu_capabilities: add "query-stats-schemas" QMP command to the QEMU capabilities Date: Wed, 7 Sep 2022 16:04:19 +0530 Message-Id: <20220907103423.662344-3-natto@weirdnatto.in> In-Reply-To: <20220907103423.662344-1-natto@weirdnatto.in> References: <20220907103423.662344-1-natto@weirdnatto.in> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mkletzan@redhat.com, pbonzini@redhat.com, Amneesh Singh Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662546900676100002 Content-Type: text/plain; charset="utf-8"; x-default="true" Related: https://gitlab.com/libvirt/libvirt/-/issues/276 Signed-off-by: Amneesh Singh Reviewed-by: Martin Kletzander --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + tests/qemucapabilitiesdata/caps_7.1.0.x86_64.xml | 1 + 3 files changed, 4 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 71018b4f6b..821d5d4ede 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -676,6 +676,7 @@ VIR_ENUM_IMPL(virQEMUCaps, =20 /* 435 */ "query-stats", /* QEMU_CAPS_QUERY_STATS */ + "query-stats-schemas", /* QEMU_CAPS_QUERY_STATS_SCHEMAS */ ); =20 =20 @@ -1226,6 +1227,7 @@ struct virQEMUCapsStringFlags virQEMUCapsCommands[] = =3D { { "sev-inject-launch-secret", QEMU_CAPS_SEV_INJECT_LAUNCH_SECRET }, { "calc-dirty-rate", QEMU_CAPS_CALC_DIRTY_RATE }, { "query-stats", QEMU_CAPS_QUERY_STATS }, + { "query-stats-schemas", QEMU_CAPS_QUERY_STATS_SCHEMAS }, }; =20 struct virQEMUCapsStringFlags virQEMUCapsMigration[] =3D { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 382c357a78..badc0e82f9 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -655,6 +655,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for = syntax-check */ =20 /* 435 */ QEMU_CAPS_QUERY_STATS, /* accepts query-stats */ + QEMU_CAPS_QUERY_STATS_SCHEMAS, /* accepts query-stats-schemas */ =20 QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/tests/qemucapabilitiesdata/caps_7.1.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_7.1.0.x86_64.xml index de961e0569..d602b066a8 100644 --- a/tests/qemucapabilitiesdata/caps_7.1.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_7.1.0.x86_64.xml @@ -222,6 +222,7 @@ + 7001000 0 43100244 --=20 2.37.1 From nobody Sun May 19 06:05:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=weirdnatto.in ARC-Seal: i=1; a=rsa-sha256; t=1662546903; cv=none; d=zohomail.com; s=zohoarc; b=YrPUGkHh0zEuGor4snEWn/6At0b5d51Zbm+foVeeiyhMsOdP+efmqyyDOTUAL1EirxNV8GIcaFhUym3mdxZEEbcgGS5niFTWM4xtSYkbZL8P7YdeIslkmujR0oI5i9FFjYPWwJ0E/sI/VLNa2h+w37Al/gtdO8pwNdBLwgEPoLY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662546903; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SlYDy5UJ/KHZfbCxZplCx2T24n91kpaRE4Us8I+FU0E=; b=DyNfxHFcOkeGVB7xRnpxAB5RI2YVAnvgaAVVdMI+ACe/hx0hCufZ+cTbj8b4cSoJADJKC/ZkLgesuUxUGMgMaa+aiIMEOiCGNmJXLnE43P5UgUO4Up48oONOhz+EQOT17GCP1hLly1unAGSCURxIEj6c4iuI9HCfJbIb1Zv806M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1662546903254600.5235833126327; Wed, 7 Sep 2022 03:35:03 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-359-1igLp7_BPU6v0sPK-LVi6g-1; Wed, 07 Sep 2022 06:34:58 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 484C31818800; Wed, 7 Sep 2022 10:34:55 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3450A141513D; Wed, 7 Sep 2022 10:34:55 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 29A9F1946A48; Wed, 7 Sep 2022 10:34:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C57271946A57 for ; Wed, 7 Sep 2022 10:34:53 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B7642492CA2; Wed, 7 Sep 2022 10:34:53 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B3B05492C3B for ; Wed, 7 Sep 2022 10:34:53 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9C8EF811E90 for ; Wed, 7 Sep 2022 10:34:53 +0000 (UTC) Received: from mail.weirdnatto.in (140.238.225.67 [140.238.225.67]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-596-FpKFEdu2Mny_HkjUocOiUg-1; Wed, 07 Sep 2022 06:34:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662546901; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=SlYDy5UJ/KHZfbCxZplCx2T24n91kpaRE4Us8I+FU0E=; b=X/itlhUdIVcc71FmiVzuRUoQfaLtaEHVmrbqJDfVsSSHmi24hIlDgSKT7dQFtdvF8FWRcX iejNzMSX8trEjvS8rJq77kjn55cbGSF6UWC2WNgliBs/HERZ0xv99SCCrHgQkbwpM+CeiX Tr8Xo7gYAfex/YGxJTG046WPeNvRueM= X-MC-Unique: 1igLp7_BPU6v0sPK-LVi6g-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: FpKFEdu2Mny_HkjUocOiUg-1 From: Amneesh Singh To: libvir-list@redhat.com Subject: [RFC PATCH 3/6] qemu_domain: add statsSchema to qemuDomainObjPrivate Date: Wed, 7 Sep 2022 16:04:20 +0530 Message-Id: <20220907103423.662344-4-natto@weirdnatto.in> In-Reply-To: <20220907103423.662344-1-natto@weirdnatto.in> References: <20220907103423.662344-1-natto@weirdnatto.in> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mkletzan@redhat.com, pbonzini@redhat.com, Amneesh Singh Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662546904659100002 Content-Type: text/plain; charset="utf-8"; x-default="true" This patch adds a hashtable for storing the stats schema and a function to refresh it by querying "query-stats-schemas" using qemuMonitorQueryStatsSchema Signed-off-by: Amneesh Singh Reviewed-by: Martin Kletzander --- src/qemu/qemu_domain.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 5 +++++ 2 files changed, 46 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index fe3ce023a4..e621e8b25e 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1708,6 +1708,8 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivate *p= riv) =20 priv->originalMemlock =3D 0; priv->preMigrationMemlock =3D 0; + + virHashRemoveAll(priv->statsSchema); } =20 =20 @@ -1747,6 +1749,9 @@ qemuDomainObjPrivateFree(void *data) g_object_unref(priv->eventThread); } =20 + if (priv->statsSchema) + g_clear_pointer(&priv->statsSchema, g_hash_table_destroy); + g_free(priv); } =20 @@ -1778,6 +1783,8 @@ qemuDomainObjPrivateAlloc(void *opaque) priv->migMaxBandwidth =3D QEMU_DOMAIN_MIG_BANDWIDTH_MAX; priv->driver =3D opaque; =20 + priv->statsSchema =3D NULL; + return g_steal_pointer(&priv); } =20 @@ -11744,3 +11751,37 @@ qemuDomainObjWait(virDomainObj *vm) =20 return 0; } + + +/** + * virDomainRefreshStatsSchema: + * @driver: qemu driver data + * @vm: Pointer to the vm object + * + * Load data into dom->privateData->statsSchema if not stored + * + * Returns -1 on failure, 0 otherwise. + */ +int +qemuDomainRefreshStatsSchema(virDomainObj *dom) +{ + qemuDomainObjPrivate *priv =3D dom->privateData; + GHashTable *schema =3D priv->statsSchema; + + if (schema && g_hash_table_size(schema) > 0) + return 0; + + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_QUERY_STATS_SCHEMAS)) + return 0; + + qemuDomainObjEnterMonitor(dom); + schema =3D qemuMonitorQueryStatsSchema(priv->mon, QEMU_MONITOR_QUERY_S= TATS_PROVIDER_LAST); + qemuDomainObjExitMonitor(dom); + + if (!schema) + return -1; + + priv->statsSchema =3D schema; + + return 0; +} diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 592ee9805b..cbc65feafc 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -244,6 +244,8 @@ struct _qemuDomainObjPrivate { =20 unsigned long long originalMemlock; /* Original RLIMIT_MEMLOCK, zero i= f no * restore will be required later = */ + + GHashTable *statsSchema; /* (name, data) pair for stats */ }; =20 #define QEMU_DOMAIN_PRIVATE(vm) \ @@ -1098,3 +1100,6 @@ qemuDomainRemoveLogs(virQEMUDriver *driver, =20 int qemuDomainObjWait(virDomainObj *vm); + +int +qemuDomainRefreshStatsSchema(virDomainObj *dom); --=20 2.37.1 From nobody Sun May 19 06:05:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=weirdnatto.in ARC-Seal: i=1; a=rsa-sha256; t=1662546898; cv=none; d=zohomail.com; s=zohoarc; b=hLNCyFwyg1Pp1Q9TzhJM6GO13w9pHplKqis/lh0B0pSBBbr3q5ihAXeXWCTLgkXlgqATboUIvT1VI6S15V4ixF50QkSxe1lyBhsQnZiMDX8uO7CjMBBb+QqlzuThuvGVjjY82euBEjE4/3HzFncjEgeReJHjV7dCzeUkC5VfFUM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662546898; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/GcNF7WJk65F00Su59AIX8E0bPPEd8FwljuVzFCFfZw=; b=jOV5FWfZgDsWjLA2iDOqp1brQYdFgnhyUxfpybRnAhzVctXx02kFywU/TDzL4vJ7GJYCr0nLrJZ9kTaSz/DXkDswjaUpgBMjI/t4OhEnWjntuYJGY9FxYWTdb5bDm5489n6b7Tfdyln7OwwmYZ4l0Z5yKrXXaUcr7I4Gp25OwiM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1662546898905109.20946305737357; Wed, 7 Sep 2022 03:34:58 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-468-cTk9w8yqP0-x12imJligKA-1; Wed, 07 Sep 2022 06:34:55 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BB8571C06ED1; Wed, 7 Sep 2022 10:34:53 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7E48C15BB3; Wed, 7 Sep 2022 10:34:53 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9CA4E1946A49; Wed, 7 Sep 2022 10:34:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0588B1946A40 for ; Wed, 7 Sep 2022 10:34:53 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id DC5442026D64; Wed, 7 Sep 2022 10:34:52 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast07.extmail.prod.ext.rdu2.redhat.com [10.11.55.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D83082026D4C for ; Wed, 7 Sep 2022 10:34:52 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BB73A3C0D1B1 for ; Wed, 7 Sep 2022 10:34:52 +0000 (UTC) Received: from mail.weirdnatto.in (140.238.225.67 [140.238.225.67]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-606-vvClTFZSNCeF8if10knfBw-1; Wed, 07 Sep 2022 06:34:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662546898; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=/GcNF7WJk65F00Su59AIX8E0bPPEd8FwljuVzFCFfZw=; b=ScI20njZwyElAN6YFzBOaYlbvwjQ20DSCftswcFsTPYDHuHgcjtIEpQOPi4Lep80qPx8uj ohQESsiwR5Z76Icu3Mf9qNrVt69gRR9ralYas7e81HO2pN/CtuMHLJg+1tmE4X3DuWTQ40 kB+G78lbD7J+m0+UnRWtFP1RQmXPStw= X-MC-Unique: cTk9w8yqP0-x12imJligKA-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: vvClTFZSNCeF8if10knfBw-1 From: Amneesh Singh To: libvir-list@redhat.com Subject: [RFC PATCH 4/6] qemu_monitor: add qemuMonitorGetStatsByQOMPath Date: Wed, 7 Sep 2022 16:04:21 +0530 Message-Id: <20220907103423.662344-5-natto@weirdnatto.in> In-Reply-To: <20220907103423.662344-1-natto@weirdnatto.in> References: <20220907103423.662344-1-natto@weirdnatto.in> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mkletzan@redhat.com, pbonzini@redhat.com, Amneesh Singh Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662546900683100003 Content-Type: text/plain; charset="utf-8"; x-default="true" This function returns the virJSONValue object which has the same qom_path as specified. Signed-off-by: Amneesh Singh Reviewed-by: Martin Kletzander --- src/qemu/qemu_monitor.c | 38 ++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor.h | 4 ++++ 2 files changed, 42 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 9581e90796..3d4302a6ed 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -1537,6 +1537,7 @@ qemuMonitorGetCPUInfoLegacy(struct qemuMonitorQueryCp= usEntry *cpuentries, vcpus[i].tid =3D cpuentries[i].tid; vcpus[i].halted =3D cpuentries[i].halted; vcpus[i].qemu_id =3D cpuentries[i].qemu_id; + vcpus[i].qom_path =3D g_strdup(cpuentries[i].qom_path); } =20 /* for legacy hotplug to work we need to fake the vcpu count added= by @@ -4446,3 +4447,40 @@ qemuMonitorExtractQueryStats(virJSONValue *info) =20 return g_steal_pointer(&hash_table); } + + +/** + * qemuMonitorStatsSchemaByQOMPath: + * @arr: Array of objects returned by qemuMonitorQueryStats + * + * Returns the object which matches the QOM path of the vCPU + * + * Returns NULL on failure. + */ +virJSONValue * +qemuMonitorGetStatsByQOMPath(virJSONValue *arr, + char *qom_path) +{ + size_t i; + + if (!virJSONValueIsArray(arr) || !qom_path) + return NULL; + + for (i =3D 0; i < virJSONValueArraySize(arr); i++) { + virJSONValue *obj =3D virJSONValueArrayGet(arr, i); + const char *test_qom_path =3D NULL; + + if (!obj) + return NULL; + + test_qom_path =3D virJSONValueObjectGetString(obj, "qom-path"); + + if (!test_qom_path) + return NULL; + + if (STRCASEEQ(qom_path, test_qom_path)) + return obj; + } + + return NULL; +} diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 4c817dea20..6b0440fdf0 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1564,3 +1564,7 @@ qemuMonitorQueryStats(qemuMonitor *mon, =20 GHashTable * qemuMonitorExtractQueryStats(virJSONValue *info); + +virJSONValue * +qemuMonitorGetStatsByQOMPath(virJSONValue *arr, + char *qom_path); --=20 2.37.1 From nobody Sun May 19 06:05:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=weirdnatto.in ARC-Seal: i=1; a=rsa-sha256; t=1662546907; cv=none; d=zohomail.com; s=zohoarc; b=TUeAInhwpz0XFgaXVCwxUATlY9NxITm2QYan+UEz6Zy2VSvigT33O7H4Rc9uJa30401ObqEUeSEMa41yhskLRzVCdtUBFJHGTeIY5GM/3OTu1SCCaVGhnn60enu2pkmxEixx0GsYGy3UCNiK2iZAJ5N0UmzJN0oUCjyEFR4+fSw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662546907; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=J3nrhT/BHYrrvwj1Jnu4tmzHTmNUYNAwtSR35Htv1bc=; b=IQDzGD5nsx21woN4oviIA75vQoeRn5Pe1cQYzMkzdkbVkhUb8zcd04IF5R/1HirJnLwSK0VWDvosZNnp5Chix977IjKylMxZpdguMUA9L2M5uxeiTfa2GkBPjngRU0TzVtLebi7DLaWt9xe8GJBUQx9qTr9bZq0o5Pwsp92WqAc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1662546907795833.8750003926815; Wed, 7 Sep 2022 03:35:07 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-44-vbEvFvMSM-eMn9i1wspAPA-1; Wed, 07 Sep 2022 06:34:59 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DDF6185A58A; Wed, 7 Sep 2022 10:34:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id C8B4240D282E; Wed, 7 Sep 2022 10:34:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BDB401946A48; Wed, 7 Sep 2022 10:34:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A0EC81946A48 for ; Wed, 7 Sep 2022 10:34:55 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 93F1A492CAA; Wed, 7 Sep 2022 10:34:55 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 903DE492CA6 for ; Wed, 7 Sep 2022 10:34:55 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7A30A811E90 for ; Wed, 7 Sep 2022 10:34:55 +0000 (UTC) Received: from mail.weirdnatto.in (140.238.225.67 [140.238.225.67]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-478-IAlkQkmoPQaDShC6lGiOqA-1; Wed, 07 Sep 2022 06:34:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662546905; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=J3nrhT/BHYrrvwj1Jnu4tmzHTmNUYNAwtSR35Htv1bc=; b=S49RwO2W/k5j4+2kes4Ez8M5VAXmh33Dhc9g4ENcP0JOb9qt9Z0AXJJo3ug3ejh1+vYDQH FCU4cjANkeznlhlRop0ogIbRk/2RhYvVhePzdVmpinytByPNiiF2uegNBcQ56fY3klI+X/ Uu5a2L2B0aI886/mRu0pwLJlWbX3dEY= X-MC-Unique: vbEvFvMSM-eMn9i1wspAPA-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: IAlkQkmoPQaDShC6lGiOqA-1 From: Amneesh Singh To: libvir-list@redhat.com Subject: [RFC PATCH 5/6] qemu_driver: add the vCPU stats by KVM to the current stats Date: Wed, 7 Sep 2022 16:04:22 +0530 Message-Id: <20220907103423.662344-6-natto@weirdnatto.in> In-Reply-To: <20220907103423.662344-1-natto@weirdnatto.in> References: <20220907103423.662344-1-natto@weirdnatto.in> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mkletzan@redhat.com, pbonzini@redhat.com, Amneesh Singh Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662546908739100002 Content-Type: text/plain; charset="utf-8"; x-default="true" This patch adds the stats queried by qemuMonitorQueryStats for vCPU and add them according to their QOM device path Signed-off-by: Amneesh Singh Reviewed-by: Martin Kletzander --- src/qemu/qemu_driver.c | 86 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ea7d74806c..79146b6bb8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17966,6 +17966,68 @@ qemuDomainGetStatsBalloon(virQEMUDriver *driver G_= GNUC_UNUSED, } =20 =20 +static void +qemuDomainAddStatsFromHashTable(GHashTable *stats, + GHashTable *schema, + const char *prefix, + virTypedParamList *params) +{ + GHashTableIter iter; + virJSONValue *value; + char *key; + + if (!stats || !schema) + return; + + g_hash_table_iter_init(&iter, stats); + + while (g_hash_table_iter_next(&iter, (gpointer *)&key, (gpointer *)&va= lue)) { + qemuMonitorQueryStatsSchemaData *data =3D g_hash_table_lookup(sche= ma, key); + const char *type =3D NULL; + + if (!data) + continue; + + switch (data->type) { + case QEMU_MONITOR_QUERY_STATS_TYPE_CUMULATIVE: + type =3D "sum"; + break; + case QEMU_MONITOR_QUERY_STATS_TYPE_INSTANT: + type =3D "cur"; + break; + + case QEMU_MONITOR_QUERY_STATS_TYPE_PEAK: + type =3D "max"; + break; + + case QEMU_MONITOR_QUERY_STATS_TYPE_LOG2_HISTOGRAM: + case QEMU_MONITOR_QUERY_STATS_TYPE_LINEAR_HISTOGRAM: + case QEMU_MONITOR_QUERY_STATS_TYPE_LAST: + default: + continue; + } + + if (data->unit =3D=3D QEMU_MONITOR_QUERY_STATS_UNIT_BOOLEAN) { + bool stat; + + if (virJSONValueGetBoolean(value, &stat) < 0) + continue; + + ignore_value(virTypedParamListAddBoolean(params, stat, "%s.%s.= %s", + prefix, key, type)); + } else { + unsigned long long stat; + + if (virJSONValueGetNumberUlong(value, &stat) < 0) + continue; + + ignore_value(virTypedParamListAddULLong(params, stat, "%s.%s.%= s", + prefix, key, type)); + } + } +} + + static int qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GNUC_UNUSED, virDomainObj *dom, @@ -17979,6 +18041,8 @@ qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GNUC= _UNUSED, virVcpuInfoPtr cpuinfo =3D NULL; g_autofree unsigned long long *cpuwait =3D NULL; g_autofree unsigned long long *cpudelay =3D NULL; + qemuDomainObjPrivate *priv =3D dom->privateData; + g_autoptr(virJSONValue) queried_stats =3D NULL; =20 if (virTypedParamListAddUInt(params, virDomainDefGetVcpus(dom->def), "vcpu.current") < 0) @@ -18007,7 +18071,21 @@ qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GNU= C_UNUSED, goto cleanup; } =20 + if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_QUERY_STATS) && + !qemuDomainRefreshStatsSchema(dom) && + HAVE_JOB(privflags)) { + qemuDomainObjEnterMonitor(dom); + queried_stats =3D qemuMonitorQueryStats(priv->mon, + QEMU_MONITOR_QUERY_STATS_TAR= GET_VCPU, + NULL, NULL); + qemuDomainObjExitMonitor(dom); + } + for (i =3D 0; i < virDomainDefGetVcpus(dom->def); i++) { + virJSONValue *stat_obj =3D NULL; + g_autoptr(GHashTable) stats =3D NULL; + g_autofree char *prefix =3D g_strdup_printf("vcpu.%u", cpuinfo[i].= number); + if (virTypedParamListAddInt(params, cpuinfo[i].state, "vcpu.%u.state", cpuinfo[i].number) < = 0) goto cleanup; @@ -18041,6 +18119,14 @@ qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GNU= C_UNUSED, cpuinfo[i].number) < 0) goto cleanup; } + + if (!queried_stats) + continue; + + stat_obj =3D qemuMonitorGetStatsByQOMPath(queried_stats, vcpupriv-= >qomPath); + stats =3D qemuMonitorExtractQueryStats(stat_obj); + + qemuDomainAddStatsFromHashTable(stats, priv->statsSchema, prefix, = params); } =20 ret =3D 0; --=20 2.37.1 From nobody Sun May 19 06:05:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=weirdnatto.in ARC-Seal: i=1; a=rsa-sha256; t=1662546906; cv=none; d=zohomail.com; s=zohoarc; b=d8R7M8lRe/YeIXMQIh87av+amv/XZEUtPZN4YhE6YAsjb4Ec9wHB5b0eXUZDHPbSCfVzcYFUot2Gxt3jzD9OcU3ES5pK7tYruWz5mMT7g1FpJ8d9lKMwMg+0TWf0JlFssNdlmKCyZoLgoBgxmJnIBfo9LJJMlNyr9oHwwwvbsI4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662546906; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=D+uHqlvNUmhVrWc9kDgg+6nPSZSvDFO3rjqEZNyNrGM=; b=Q10l3wRYxSS0RpYhWbqJwb3cqFONIZoPqknY1t1vyBNyh/Ed836BWVEtqAxyT+Q3V6jMQkWHpLS34hRJM13+aaUvX5Afz7IWrvpgZEN3bkzyY1t25gV6HHZj/yUIX4o4US+djIZQ0ah0L44BcJl2ST6aKSyLHu4TFBszVgTX9qs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1662546906594108.65722022557861; Wed, 7 Sep 2022 03:35:06 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-515-ceOnpqTVMMyw4gToeYR3EA-1; Wed, 07 Sep 2022 06:34:59 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9087680A0C2; Wed, 7 Sep 2022 10:34:55 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7ADD4492CA2; Wed, 7 Sep 2022 10:34:55 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 672D01946A5A; Wed, 7 Sep 2022 10:34:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 36F8F1946A49 for ; Wed, 7 Sep 2022 10:34:54 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 27DC5403162; Wed, 7 Sep 2022 10:34:54 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2361E403167 for ; Wed, 7 Sep 2022 10:34:54 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ED5EF8039CD for ; Wed, 7 Sep 2022 10:34:53 +0000 (UTC) Received: from mail.weirdnatto.in (140.238.225.67 [140.238.225.67]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-482--FjmsAP7N9Ojgytugu2jhw-1; Wed, 07 Sep 2022 06:34:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662546904; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=D+uHqlvNUmhVrWc9kDgg+6nPSZSvDFO3rjqEZNyNrGM=; b=gk6gfdiKTsCRsp6gZFGbF4arIa/B9uNY6sPN0e0Mw98yZ+TRRKKfrsJClIAJheWtlX72Dj Bj6B2P3X1LHJWB2V01DF0yEZNQdxYNyQB7hIRa4RnQjY9yp3L6lP8xXQK2aqu/mKjWhlJ+ j4VNyzzqLyX1xXMVMS+RmAzXyCljy1E= X-MC-Unique: ceOnpqTVMMyw4gToeYR3EA-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: -FjmsAP7N9Ojgytugu2jhw-1 From: Amneesh Singh To: libvir-list@redhat.com Subject: [RFC PATCH 6/6] qemu_driver: add new stats worker qemuDomainGetStatsVm Date: Wed, 7 Sep 2022 16:04:23 +0530 Message-Id: <20220907103423.662344-7-natto@weirdnatto.in> In-Reply-To: <20220907103423.662344-1-natto@weirdnatto.in> References: <20220907103423.662344-1-natto@weirdnatto.in> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mkletzan@redhat.com, pbonzini@redhat.com, Amneesh Singh Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662546908723100001 Content-Type: text/plain; charset="utf-8"; x-default="true" This patch adds a new worker qemuDomainGetStatsVm which reports the stats returned by "query-stats" via qemuMonitorQueryStats for the VM target. Signed-off-by: Amneesh Singh Reviewed-by: Martin Kletzander --- include/libvirt/libvirt-domain.h | 1 + src/libvirt-domain.c | 3 +++ src/qemu/qemu_driver.c | 41 ++++++++++++++++++++++++++++++++ tools/virsh-domain-monitor.c | 7 ++++++ 4 files changed, 52 insertions(+) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 7430a08619..3b25c8dd77 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -2706,6 +2706,7 @@ typedef enum { VIR_DOMAIN_STATS_IOTHREAD =3D (1 << 7), /* return iothread poll info (= Since: 4.10.0) */ VIR_DOMAIN_STATS_MEMORY =3D (1 << 8), /* return domain memory info (Si= nce: 6.0.0) */ VIR_DOMAIN_STATS_DIRTYRATE =3D (1 << 9), /* return domain dirty rate i= nfo (Since: 7.2.0) */ + VIR_DOMAIN_STATS_VM =3D (1 << 10), /* return vm info (Since: 8.6.0) */ } virDomainStatsTypes; =20 /** diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 80a6f0f269..52fa136186 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -12481,6 +12481,9 @@ virConnectGetDomainCapabilities(virConnectPtr conn, * rate for a virtual cp= u as * unsigned long long. * + * VIR_DOMAIN_STATS_VM: + * Return fd-based KVM statistics for the target VM + * * Note that entire stats groups or individual stat fields may be missing = from * the output in case they are not supported by the given hypervisor, are = not * applicable for the current state of the guest domain, or their retrieval diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 79146b6bb8..ce4d4a0f03 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18727,6 +18727,41 @@ qemuDomainGetStatsDirtyRate(virQEMUDriver *driver = G_GNUC_UNUSED, return 0; } =20 + +static int +qemuDomainGetStatsVm(virQEMUDriver *driver G_GNUC_UNUSED, + virDomainObj *dom, + virTypedParamList *params, + unsigned int privflags) +{ + qemuDomainObjPrivate *priv =3D dom->privateData; + g_autoptr(virJSONValue) queried_stats =3D NULL; + g_autoptr(GHashTable) stats =3D NULL; + virJSONValue *stats_obj =3D NULL; + + if (!HAVE_JOB(privflags) || !virDomainObjIsActive(dom)) + return 0; + + if (qemuDomainRefreshStatsSchema(dom) < 0) + return 0; + + qemuDomainObjEnterMonitor(dom); + queried_stats =3D qemuMonitorQueryStats(priv->mon, + QEMU_MONITOR_QUERY_STATS_TARGET_= VM, + NULL, NULL); + qemuDomainObjExitMonitor(dom); + + if (!queried_stats || virJSONValueArraySize(queried_stats) !=3D 1) + return 0; + + stats_obj =3D virJSONValueArrayGet(queried_stats, 0); + stats =3D qemuMonitorExtractQueryStats(stats_obj); + + qemuDomainAddStatsFromHashTable(stats, priv->statsSchema, "vm", params= ); + + return 0; +} + typedef int (*qemuDomainGetStatsFunc)(virQEMUDriver *driver, virDomainObj *dom, @@ -18751,6 +18786,11 @@ static virQEMUCapsFlags queryDirtyRateRequired[] = =3D { QEMU_CAPS_LAST }; =20 +static virQEMUCapsFlags queryVmRequired[] =3D { + QEMU_CAPS_QUERY_STATS, + QEMU_CAPS_LAST +}; + static struct qemuDomainGetStatsWorker qemuDomainGetStatsWorkers[] =3D { { qemuDomainGetStatsState, VIR_DOMAIN_STATS_STATE, false, NULL }, { qemuDomainGetStatsCpu, VIR_DOMAIN_STATS_CPU_TOTAL, true, NULL }, @@ -18762,6 +18802,7 @@ static struct qemuDomainGetStatsWorker qemuDomainGe= tStatsWorkers[] =3D { { qemuDomainGetStatsIOThread, VIR_DOMAIN_STATS_IOTHREAD, true, queryIO= ThreadRequired }, { qemuDomainGetStatsMemory, VIR_DOMAIN_STATS_MEMORY, false, NULL }, { qemuDomainGetStatsDirtyRate, VIR_DOMAIN_STATS_DIRTYRATE, true, query= DirtyRateRequired }, + { qemuDomainGetStatsVm, VIR_DOMAIN_STATS_VM, true, queryVmRequired }, { NULL, 0, false, NULL } }; =20 diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index dc5fe13e49..be8f827685 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -2065,6 +2065,10 @@ static const vshCmdOptDef opts_domstats[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("report domain dirty rate information"), }, + {.name =3D "vm", + .type =3D VSH_OT_BOOL, + .help =3D N_("report fd-based VM statistics by KVM"), + }, {.name =3D "list-active", .type =3D VSH_OT_BOOL, .help =3D N_("list only active domains"), @@ -2186,6 +2190,9 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "dirtyrate")) stats |=3D VIR_DOMAIN_STATS_DIRTYRATE; =20 + if (vshCommandOptBool(cmd, "vm")) + stats |=3D VIR_DOMAIN_STATS_VM; + if (vshCommandOptBool(cmd, "list-active")) flags |=3D VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE; =20 --=20 2.37.1