public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Alexandre Derumier <aderumier@odiso.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-common 2/4] read_proc_stat: substract guest && guest_nice from user && nice time
Date: Mon, 10 Jan 2022 05:52:58 +0100	[thread overview]
Message-ID: <20220110045300.3668895-3-aderumier@odiso.com> (raw)
In-Reply-To: <20220110045300.3668895-1-aderumier@odiso.com>

user && nice time already include guest value
https://github.com/torvalds/linux/blob/4ec9f7a18/kernel/sched/cputime.c#L151-L158

Other monitoring tools are already substracting theses guest values

https://github.com/htop-dev/htop/blob/main/linux/LinuxProcessList.c
https://github.com/influxdata/telegraf/blob/c66ccee46f47717c399ccc0348d17c95d11f477d/plugins/inputs/cpu/cpu.go
---
 src/PVE/ProcFSTools.pm | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/PVE/ProcFSTools.pm b/src/PVE/ProcFSTools.pm
index c816131..79d4a4c 100644
--- a/src/PVE/ProcFSTools.pm
+++ b/src/PVE/ProcFSTools.pm
@@ -169,8 +169,8 @@ sub read_proc_stat {
     if (my $fh = IO::File->new ("/proc/stat", "r")) {
 	while (defined (my $line = <$fh>)) {
 	    if ($line =~ m|^cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)|) {
-		$res->{user} = $1;
-		$res->{nice} = $2;
+		$res->{user} = $1 - $9;
+		$res->{nice} = $2 - $10;
 		$res->{system} = $3;
 		$res->{idle} = $4;
 		$res->{used} = $1+$2+$3;
@@ -191,7 +191,7 @@ sub read_proc_stat {
 
     my $ctime = gettimeofday; # floating point time in seconds
 
-    # the sum of all (non-guest) fields
+    # the sum of all fields
     $res->{total} = $res->{user}
 	+ $res->{nice}
 	+ $res->{system}
@@ -199,7 +199,9 @@ sub read_proc_stat {
 	+ $res->{irq}
 	+ $res->{softirq}
 	+ $res->{steal}
-	+ $res->{idle};
+	+ $res->{idle}
+	+ $res->{guest}
+	+ $res->{guest_nice};
 
     $res->{ctime} = $ctime;
     $res->{cpu} = 0;
-- 
2.30.2




  parent reply	other threads:[~2022-01-10  4:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-10  4:52 [pve-devel] [PATCH pve-common 0/4] improve host read_proc_stat Alexandre Derumier
2022-01-10  4:52 ` [pve-devel] [PATCH pve-common 1/4] read_proc_stat : initialize newer fields to 0 Alexandre Derumier
2022-01-10  4:52 ` Alexandre Derumier [this message]
2022-01-10  4:52 ` [pve-devel] [PATCH pve-common 3/4] read_proc_stat: add irq/softirq/steal to total used cpu Alexandre Derumier
2022-01-10  4:53 ` [pve-devel] [PATCH pve-common 4/4] read_proc_stat: use total of fields to compute percentage Alexandre Derumier
2022-01-13 15:33 ` [pve-devel] applied-series: [PATCH pve-common 0/4] improve host read_proc_stat Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220110045300.3668895-3-aderumier@odiso.com \
    --to=aderumier@odiso.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal