From 109131eb4925a9c5da7a260d0f223ffd438b203c Mon Sep 17 00:00:00 2001
From: yuanxing <yuanxing@kylinos.com.cn>
Date: Wed, 20 Oct 2021 14:26:34 +0800
Subject: [PATCH 1006/1006] fix(*):get pcpu with double to solve the cpu% don't
 changed bug
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- 将获取的pcpu的值定义为double类型解决cpu%不变化的问题

Related #45071
---
 src/proctable.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/proctable.cpp b/src/proctable.cpp
index f2eb3b5..6601cc6 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -804,12 +804,15 @@ update_info (ProcData *procdata, ProcInfo *info)
     guint64 difference = proctime.rtime - info->cpu_time;
     if (difference > 0)
         info->status = GLIBTOP_PROCESS_RUNNING;
-    info->pcpu = difference * 100 / procdata->cpu_total_time;
-    info->pcpu = MIN(info->pcpu, 100);
+
+    double pcpu = difference * 100.0 / procdata->cpu_total_time * 1.0;
+    if(pcpu >100)
+        pcpu = 100;
 
     if (not procdata->config.solaris_mode)
-      info->pcpu *= procdata->config.num_cpus;
+        pcpu *= procdata->config.num_cpus;
 
+    info->pcpu = int(pcpu);
     ProcInfo::cpu_times[info->pid] = info->cpu_time = proctime.rtime;
     info->nice = procuid.nice;
 
-- 
2.27.0

