[PATCH v2 5/6] virsh: host: refactor cmdNodeCpuStats()

Kristina Hanicova khanicov at redhat.com
Thu Sep 23 23:25:11 UTC 2021


Signed-off-by: Kristina Hanicova <khanicov at redhat.com>
---
 tools/virsh-host.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index be9cbc2096..bcd44cefe1 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -803,30 +803,30 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd)
                          cpu_stats[i]);
             }
         }
+        return true;
+    }
+
+    if (present[VIRSH_CPU_USAGE]) {
+        vshPrint(ctl, "%-15s %5.1llu%%\n",
+                 _("usage:"), cpu_stats[VIRSH_CPU_USAGE]);
+        vshPrint(ctl, "%-15s %5.1llu%%\n",
+                 _("idle:"), 100 - cpu_stats[VIRSH_CPU_USAGE]);
     } else {
-        if (present[VIRSH_CPU_USAGE]) {
-            vshPrint(ctl, "%-15s %5.1llu%%\n",
-                     _("usage:"), cpu_stats[VIRSH_CPU_USAGE]);
-            vshPrint(ctl, "%-15s %5.1llu%%\n",
-                     _("idle:"), 100 - cpu_stats[VIRSH_CPU_USAGE]);
-        } else {
-            double usage, total_time = 0;
-            for (i = 0; i < VIRSH_CPU_USAGE; i++)
-                total_time += cpu_stats[i];
-
-            usage = (cpu_stats[VIRSH_CPU_USER] + cpu_stats[VIRSH_CPU_SYSTEM])
-                / total_time * 100;
-
-            vshPrint(ctl, "%-15s %5.1lf%%\n", _("usage:"), usage);
-            for (i = 0; i < VIRSH_CPU_USAGE; i++) {
-                if (present[i]) {
-                    vshPrint(ctl, "%-15s %5.1lf%%\n", _(virshCPUOutput[i]),
-                             cpu_stats[i] / total_time * 100);
-                }
+        double usage, total_time = 0;
+        for (i = 0; i < VIRSH_CPU_USAGE; i++)
+            total_time += cpu_stats[i];
+
+        usage = (cpu_stats[VIRSH_CPU_USER] + cpu_stats[VIRSH_CPU_SYSTEM])
+            / total_time * 100;
+
+        vshPrint(ctl, "%-15s %5.1lf%%\n", _("usage:"), usage);
+        for (i = 0; i < VIRSH_CPU_USAGE; i++) {
+            if (present[i]) {
+                vshPrint(ctl, "%-15s %5.1lf%%\n", _(virshCPUOutput[i]),
+                         cpu_stats[i] / total_time * 100);
             }
         }
     }
-
     return true;
 }
 
-- 
2.31.1




More information about the libvir-list mailing list