Skip to content

Commit

Permalink
fixed, cpu percent used. zero out sleeping cpus
Browse files Browse the repository at this point in the history
  • Loading branch information
davilla authored and koying committed Jun 29, 2016
1 parent ca2467f commit 3660b30
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions xbmc/utils/CPUInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,8 @@ bool CCPUInfo::readProcStat(unsigned long long& user, unsigned long long& nice,
total = (double)(coreUser + coreNice + coreSystem + coreIdle + coreIO);
if(total != 0.0f)
iter->second.m_fPct = ((double)(coreUser + coreNice + coreSystem) * 100.0) / total;
else
iter->second.m_fPct = 0.0f;

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

// zero out cpu percents, cpu's can idle and disappear.
for (int i = 0; i < m_cpuCount; i++)
{
std::map<int, CoreInfo>::iterator iter = m_cores.find(i);
if (iter != m_cores.end())
iter->second.m_fPct = 0.0;
}

while (fgets(buf, sizeof(buf), m_fProcStat) && num >= 4)
{
unsigned long long coreUser, coreNice, coreSystem, coreIdle, coreIO;
Expand Down

0 comments on commit 3660b30

Please sign in to comment.