Changeset 10868 in vbox for trunk/src/VBox/Main/linux
- Timestamp:
- Jul 24, 2008 6:34:35 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 33686
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/linux/PerformanceLinux.cpp
r10754 r10868 37 37 virtual int getProcessMemoryUsage(RTPROCESS process, unsigned long *used); 38 38 39 virtual int getRawHostCpuLoad(u nsigned long *user, unsigned long *kernel, unsigned long*idle);40 virtual int getRawProcessCpuLoad(RTPROCESS process, u nsigned long *user, unsigned long *kernel);39 virtual int getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle); 40 virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total); 41 41 }; 42 42 … … 49 49 } 50 50 51 BaseMetric *MetricFactoryLinux::createHostCpuLoad(ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle)52 {53 Assert(mHAL);54 return new HostCpuLoadRaw(mHAL, object, user, kernel, idle);55 }56 57 BaseMetric *MetricFactoryLinux::createMachineCpuLoad(ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel)58 {59 Assert(mHAL);60 return new MachineCpuLoadRaw(mHAL, object, process, user, kernel);61 }62 63 51 // Collector HAL for Linux 64 52 65 int CollectorLinux::getRawHostCpuLoad(u nsigned long *user, unsigned long *kernel, unsigned long*idle)53 int CollectorLinux::getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle) 66 54 { 67 55 int rc = VINF_SUCCESS; 68 unsigned long nice;56 unsigned long u32user, u32nice, u32kernel, u32idle; 69 57 FILE *f = fopen("/proc/stat", "r"); 70 58 71 59 if (f) 72 60 { 73 if (fscanf(f, "cpu %lu %lu %lu %lu", user, &nice, kernel, idle) == 4) 74 *user += nice; 61 if (fscanf(f, "cpu %lu %lu %lu %lu", &u32user, &u32nice, &u32kernel, &u32idle) == 4) 62 { 63 *user = (uint64_t)u32user + u32nice; 64 *kernel = u32kernel; 65 *idle = u32idle; 66 } 75 67 else 76 68 rc = VERR_FILE_IO_ERROR; … … 83 75 } 84 76 85 int CollectorLinux::getRawProcessCpuLoad(RTPROCESS process, u nsigned long *user, unsigned long *kernel)77 int CollectorLinux::getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total) 86 78 { 87 79 int rc = VINF_SUCCESS; … … 91 83 int iTmp; 92 84 unsigned uTmp; 93 unsigned long ulTmp ;85 unsigned long ulTmp, u32user, u32kernel; 94 86 char buf[80]; /* @todo: this should be tied to max allowed proc name. */ 87 88 uint64_t uHostUser, uHostKernel, uHostIdle; 89 rc = getRawHostCpuLoad(uHostUser, uHostKernel, uHostIdle); 90 if (RT_FAILURE(rc)) 91 return rc; 92 *total = (uint64_t)uHostUser + uHostKernel + uHostIdle; 95 93 96 94 RTStrAPrintf(&pszName, "/proc/%d/stat", process); … … 103 101 if (fscanf(f, "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu", 104 102 &pid2, buf, &c, &iTmp, &iTmp, &iTmp, &iTmp, &iTmp, &uTmp, 105 &ulTmp, &ulTmp, &ulTmp, &ulTmp, user,kernel) == 15)103 &ulTmp, &ulTmp, &ulTmp, &ulTmp, &u32user, &u32kernel) == 15) 106 104 { 107 105 Assert((pid_t)process == pid2); 106 *user = u32user; 107 *kernel = u32kernel; 108 108 } 109 109 else
Note:
See TracChangeset
for help on using the changeset viewer.