Changeset 12546 in vbox for trunk/src/VBox/Main/linux
- Timestamp:
- Sep 17, 2008 5:11:15 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 36733
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/linux/PerformanceLinux.cpp
r12400 r12546 27 27 #include <iprt/param.h> 28 28 #include <iprt/string.h> 29 30 #include <map> 31 #include <vector> 32 33 #include "Logging.h" 29 34 #include "Performance.h" 30 35 … … 34 39 { 35 40 public: 41 virtual int preCollect(const CollectorHints& hints); 36 42 virtual int getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available); 37 43 virtual int getProcessMemoryUsage(RTPROCESS process, ULONG *used); … … 40 46 virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total); 41 47 private: 48 virtual int _getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle); 42 49 int getRawProcessStats(RTPROCESS process, uint64_t *cpuUser, uint64_t *cpuKernel, ULONG *memPagesUsed); 50 51 struct VMProcessStats 52 { 53 uint64_t cpuUser; 54 uint64_t cpuKernel; 55 ULONG pagesUsed; 56 }; 57 58 typedef std::map<RTPROCESS, VMProcessStats> VMProcessMap; 59 60 VMProcessMap mProcessStats; 61 uint64_t mUser, mKernel, mIdle; 43 62 }; 44 63 … … 50 69 // Collector HAL for Linux 51 70 52 int CollectorLinux::getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle) 71 int CollectorLinux::preCollect(const CollectorHints& hints) 72 { 73 std::vector<RTPROCESS> processes; 74 hints.getProcesses(processes); 75 76 std::vector<RTPROCESS>::iterator it; 77 for(it = processes.begin(); it != processes.end(); it++) 78 { 79 VMProcessStats vmStats; 80 int rc = getRawProcessStats(*it, &vmStats.cpuUser, &vmStats.cpuKernel, &vmStats.pagesUsed); 81 if (RT_FAILURE(rc)) 82 return rc; 83 mProcessStats[*it] = vmStats; 84 } 85 if (hints.isHostCpuLoadCollected() || mProcessStats.size()) 86 { 87 _getRawHostCpuLoad(&mUser, &mKernel, &mIdle); 88 } 89 return VINF_SUCCESS; 90 } 91 92 int CollectorLinux::_getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle) 53 93 { 54 94 int rc = VINF_SUCCESS; … … 74 114 } 75 115 116 int CollectorLinux::getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle) 117 { 118 *user = mUser; 119 *kernel = mKernel; 120 *idle = mIdle; 121 return VINF_SUCCESS; 122 } 123 76 124 int CollectorLinux::getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total) 77 125 { 78 int rc = VINF_SUCCESS; 79 uint64_t uHostUser, uHostKernel, uHostIdle; 80 81 rc = getRawHostCpuLoad(&uHostUser, &uHostKernel, &uHostIdle); 82 if (RT_SUCCESS(rc)) 83 { 84 ULONG ulTmp; 85 *total = (uint64_t)uHostUser + uHostKernel + uHostIdle; 86 rc = getRawProcessStats(process, user, kernel, &ulTmp); 87 } 88 89 return rc; 126 VMProcessMap::const_iterator it = mProcessStats.find(process); 127 128 if (it == mProcessStats.end()) 129 { 130 Log (("No stats pre-collected for process %x\n", process)); 131 return VERR_INTERNAL_ERROR; 132 } 133 *user = it->second.cpuUser; 134 *kernel = it->second.cpuKernel; 135 *total = mUser + mKernel + mIdle; 136 return VINF_SUCCESS; 90 137 } 91 138 … … 119 166 int CollectorLinux::getProcessMemoryUsage(RTPROCESS process, ULONG *used) 120 167 { 121 uint64_t u64Tmp;122 ULONG nPagesUsed; 123 i nt rc = getRawProcessStats(process, &u64Tmp, &u64Tmp, &nPagesUsed);124 if (RT_SUCCESS(rc))125 {126 Assert(PAGE_SIZE >= 1024);127 *used = nPagesUsed * (PAGE_SIZE / 1024);128 }129 return rc;168 VMProcessMap::const_iterator it = mProcessStats.find(process); 169 170 if (it == mProcessStats.end()) 171 { 172 Log (("No stats pre-collected for process %x\n", process)); 173 return VERR_INTERNAL_ERROR; 174 } 175 *used = it->second.pagesUsed * (PAGE_SIZE / 1024); 176 return VINF_SUCCESS; 130 177 } 131 178
Note:
See TracChangeset
for help on using the changeset viewer.