Skip to content
This repository was archived by the owner on Dec 24, 2024. It is now read-only.

Commit 347957b

Browse files
davillakoying
authored andcommitted
fixed, cpu percent used. zero out sleeping cpus
1 parent 8387c14 commit 347957b

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

xbmc/utils/CPUInfo.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,8 @@ bool CCPUInfo::readProcStat(unsigned long long& user, unsigned long long& nice,
749749
total = (double)(coreUser + coreNice + coreSystem + coreIdle + coreIO);
750750
if(total != 0.0f)
751751
iter->second.m_fPct = ((double)(coreUser + coreNice + coreSystem) * 100.0) / total;
752+
else
753+
iter->second.m_fPct = 0.0f;
752754

753755
iter->second.m_user += coreUser;
754756
iter->second.m_nice += coreNice;
@@ -787,6 +789,14 @@ bool CCPUInfo::readProcStat(unsigned long long& user, unsigned long long& nice,
787789
if (num < 5)
788790
io = 0;
789791

792+
// zero out cpu percents, cpu's can idle and disappear.
793+
for (int i = 0; i < m_cpuCount; i++)
794+
{
795+
std::map<int, CoreInfo>::iterator iter = m_cores.find(i);
796+
if (iter != m_cores.end())
797+
iter->second.m_fPct = 0.0;
798+
}
799+
790800
while (fgets(buf, sizeof(buf), m_fProcStat) && num >= 4)
791801
{
792802
unsigned long long coreUser, coreNice, coreSystem, coreIdle, coreIO;

0 commit comments

Comments
 (0)