diff options
author | bobo1on1 <bobo1on1@svn> | 2010-01-16 19:07:36 +0000 |
---|---|---|
committer | bobo1on1 <bobo1on1@svn> | 2010-01-16 19:07:36 +0000 |
commit | 0358a8571a70781352854b4ed4004eac94c04ea4 (patch) | |
tree | 46541d73d31298022497ce3ee521fb3895f01b2e | |
parent | e1db6d5ef2ee7429553f9a4051df48dfd554d969 (diff) |
removed: unused variables and system calls
fixed: add io ticks to idle when available
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@26916 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
-rw-r--r-- | xbmc/utils/CPUInfo.cpp | 34 | ||||
-rw-r--r-- | xbmc/utils/CPUInfo.h | 10 |
2 files changed, 28 insertions, 16 deletions
diff --git a/xbmc/utils/CPUInfo.cpp b/xbmc/utils/CPUInfo.cpp index 92bca500a4..87b2d9fa00 100644 --- a/xbmc/utils/CPUInfo.cpp +++ b/xbmc/utils/CPUInfo.cpp @@ -166,7 +166,7 @@ CCPUInfo::CCPUInfo(void) m_cpuModel = "Unknown"; } - readProcStat(m_userTicks, m_niceTicks, m_systemTicks, m_idleTicks); + readProcStat(m_userTicks, m_niceTicks, m_systemTicks, m_idleTicks, m_ioTicks); #endif } @@ -193,8 +193,9 @@ int CCPUInfo::getUsedPercentage() unsigned long long niceTicks; unsigned long long systemTicks; unsigned long long idleTicks; + unsigned long long ioTicks; - if (!readProcStat(userTicks, niceTicks, systemTicks, idleTicks)) + if (!readProcStat(userTicks, niceTicks, systemTicks, idleTicks, ioTicks)) { return 0; } @@ -203,17 +204,19 @@ int CCPUInfo::getUsedPercentage() niceTicks -= m_niceTicks; systemTicks -= m_systemTicks; idleTicks -= m_idleTicks; + ioTicks -= m_ioTicks; #ifdef _WIN32 int result = (int) ((userTicks + systemTicks - idleTicks) * 100 / (userTicks + systemTicks)); #else - int result = (int) ((userTicks + niceTicks + systemTicks) * 100 / (userTicks + niceTicks + systemTicks + idleTicks)); + int result = (int) ((userTicks + niceTicks + systemTicks) * 100 / (userTicks + niceTicks + systemTicks + idleTicks + ioTicks)); #endif m_userTicks += userTicks; m_niceTicks += niceTicks; m_systemTicks += systemTicks; m_idleTicks += idleTicks; + m_ioTicks += ioTicks; m_lastUsedPercentage = result; @@ -320,7 +323,7 @@ const CoreInfo &CCPUInfo::GetCoreInfo(int nCoreId) } bool CCPUInfo::readProcStat(unsigned long long& user, unsigned long long& nice, - unsigned long long& system, unsigned long long& idle) + unsigned long long& system, unsigned long long& idle, unsigned long long& io) { #ifdef _WIN32 @@ -351,7 +354,8 @@ bool CCPUInfo::readProcStat(unsigned long long& user, unsigned long long& nice, m_cores[0].m_user += coreUser; m_cores[0].m_system += coreSystem; m_cores[0].m_idle += coreIdle; - gettimeofday(&m_cores[0].m_lastSample, NULL); + + io = 0; #else if (m_fProcStat == NULL) @@ -364,12 +368,18 @@ bool CCPUInfo::readProcStat(unsigned long long& user, unsigned long long& nice, if (!fgets(buf, sizeof(buf), m_fProcStat)) return false; - int num = sscanf(buf, "cpu %llu %llu %llu %llu %*s\n", &user, &nice, &system, &idle); + int num = sscanf(buf, "cpu %llu %llu %llu %llu %llu %*s\n", &user, &nice, &system, &idle, &io); + if (num < 5) + io = 0; + while (fgets(buf, sizeof(buf), m_fProcStat) && num >= 4) { - unsigned long long coreUser, coreNice, coreSystem, coreIdle; + unsigned long long coreUser, coreNice, coreSystem, coreIdle, coreIO; int nCpu=0; - num = sscanf(buf, "cpu%d %llu %llu %llu %llu %*s\n", &nCpu, &coreUser, &coreNice, &coreSystem, &coreIdle); + num = sscanf(buf, "cpu%d %llu %llu %llu %llu %llu %*s\n", &nCpu, &coreUser, &coreNice, &coreSystem, &coreIdle, &coreIO); + if (num < 6) + coreIO = 0; + map<int, CoreInfo>::iterator iter = m_cores.find(nCpu); if (num > 4 && iter != m_cores.end()) { @@ -377,12 +387,16 @@ bool CCPUInfo::readProcStat(unsigned long long& user, unsigned long long& nice, coreNice -= iter->second.m_nice; coreSystem -= iter->second.m_system; coreIdle -= iter->second.m_idle; - iter->second.m_fPct = ((double)(coreUser + coreNice + coreSystem) * 100.0) / (double)(coreUser + coreNice + coreSystem + coreIdle); + coreIO -= iter->second.m_io; + + double total = (double)(coreUser + coreNice + coreSystem + coreIdle + coreIO); + iter->second.m_fPct = ((double)(coreUser + coreNice + coreSystem) * 100.0) / total; + iter->second.m_user += coreUser; iter->second.m_nice += coreNice; iter->second.m_system += coreSystem; iter->second.m_idle += coreIdle; - gettimeofday(&iter->second.m_lastSample, NULL); + iter->second.m_io += coreIO; } } #endif diff --git a/xbmc/utils/CPUInfo.h b/xbmc/utils/CPUInfo.h index f567333803..f0646d4b0f 100644 --- a/xbmc/utils/CPUInfo.h +++ b/xbmc/utils/CPUInfo.h @@ -38,13 +38,10 @@ struct CoreInfo unsigned long long m_nice; unsigned long long m_system; unsigned long long m_idle; - struct timeval m_lastSample; + unsigned long long m_io; CStdString m_strVendor; CStdString m_strModel; - CoreInfo() : m_id(0), m_fSpeed(.0), m_fPct(.0), m_user(0LL), m_nice(0LL), m_system(0LL), m_idle(0LL) - { - memset(&m_lastSample,0,sizeof(struct timeval)); - } + CoreInfo() : m_id(0), m_fSpeed(.0), m_fPct(.0), m_user(0LL), m_nice(0LL), m_system(0LL), m_idle(0LL), m_io(0LL) {} }; class CCPUInfo @@ -66,7 +63,7 @@ public: private: bool readProcStat(unsigned long long& user, unsigned long long& nice, unsigned long long& system, - unsigned long long& idle); + unsigned long long& idle, unsigned long long& io); FILE* m_fProcStat; FILE* m_fProcTemperature; @@ -76,6 +73,7 @@ private: unsigned long long m_niceTicks; unsigned long long m_systemTicks; unsigned long long m_idleTicks; + unsigned long long m_ioTicks; int m_lastUsedPercentage; time_t m_lastReadTime; |