Changeset 10878 in vbox for trunk/src/VBox/Main
- Timestamp:
- Jul 25, 2008 7:48:31 AM (17 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/linux/PerformanceLinux.cpp
r10872 r10878 39 39 virtual int getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle); 40 40 virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total); 41 private: 42 int getRawProcessStats(RTPROCESS process, uint64_t *cpuUser, uint64_t *cpuKernel, unsigned long *memPagesUsed); 41 43 }; 42 44 … … 78 80 { 79 81 int rc = VINF_SUCCESS; 80 char *pszName; 81 pid_t pid2; 82 char c; 83 int iTmp; 84 unsigned uTmp; 85 unsigned long ulTmp, u32user, u32kernel; 86 char buf[80]; /* @todo: this should be tied to max allowed proc name. */ 82 uint64_t uHostUser, uHostKernel, uHostIdle; 87 83 88 uint64_t uHostUser, uHostKernel, uHostIdle;89 84 rc = getRawHostCpuLoad(&uHostUser, &uHostKernel, &uHostIdle); 90 if (RT_FAILURE(rc)) 91 return rc; 92 *total = (uint64_t)uHostUser + uHostKernel + uHostIdle; 93 94 RTStrAPrintf(&pszName, "/proc/%d/stat", process); 95 //printf("Opening %s...\n", pszName); 96 FILE *f = fopen(pszName, "r"); 97 RTMemFree(pszName); 98 99 if (f) 85 if (RT_SUCCESS(rc)) 100 86 { 101 if (fscanf(f, "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu", 102 &pid2, buf, &c, &iTmp, &iTmp, &iTmp, &iTmp, &iTmp, &uTmp, 103 &ulTmp, &ulTmp, &ulTmp, &ulTmp, &u32user, &u32kernel) == 15) 104 { 105 Assert((pid_t)process == pid2); 106 *user = u32user; 107 *kernel = u32kernel; 108 } 109 else 110 rc = VERR_FILE_IO_ERROR; 111 fclose(f); 87 unsigned long ulTmp; 88 *total = (uint64_t)uHostUser + uHostKernel + uHostIdle; 89 rc = getRawProcessStats(process, user, kernel, &ulTmp); 112 90 } 113 else114 rc = VERR_ACCESS_DENIED;115 91 116 92 return rc; … … 145 121 return rc; 146 122 } 123 147 124 int CollectorLinux::getProcessMemoryUsage(RTPROCESS process, unsigned long *used) 148 125 { 149 return E_NOTIMPL; 126 uint64_t u64Tmp; 127 unsigned long nPagesUsed; 128 int rc = getRawProcessStats(process, &u64Tmp, &u64Tmp, &nPagesUsed); 129 if (RT_SUCCESS(rc)) 130 { 131 Assert(getpagesize() >= 1024); 132 *used = nPagesUsed * (getpagesize() / 1024); 133 } 134 return rc; 135 } 136 137 int CollectorLinux::getRawProcessStats(RTPROCESS process, uint64_t *cpuUser, uint64_t *cpuKernel, unsigned long *memPagesUsed) 138 { 139 int rc = VINF_SUCCESS; 140 char *pszName; 141 pid_t pid2; 142 char c; 143 int iTmp; 144 uint64_t u64Tmp; 145 unsigned uTmp; 146 unsigned long ulTmp, u32user, u32kernel; 147 char buf[80]; /* @todo: this should be tied to max allowed proc name. */ 148 149 RTStrAPrintf(&pszName, "/proc/%d/stat", process); 150 //printf("Opening %s...\n", pszName); 151 FILE *f = fopen(pszName, "r"); 152 RTMemFree(pszName); 153 154 if (f) 155 { 156 if (fscanf(f, "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu " 157 "%ld %ld %ld %ld %ld %ld %llu %lu %ld", 158 &pid2, buf, &c, &iTmp, &iTmp, &iTmp, &iTmp, &iTmp, &uTmp, 159 &ulTmp, &ulTmp, &ulTmp, &ulTmp, &u32user, &u32kernel, 160 &ulTmp, &ulTmp, &ulTmp, &ulTmp, &ulTmp, &ulTmp, &u64Tmp, 161 &ulTmp, memPagesUsed) == 24) 162 { 163 Assert((pid_t)process == pid2); 164 *cpuUser = u32user; 165 *cpuKernel = u32kernel; 166 } 167 else 168 rc = VERR_FILE_IO_ERROR; 169 fclose(f); 170 } 171 else 172 rc = VERR_ACCESS_DENIED; 173 174 return rc; 150 175 } 151 176 152 177 } 178 -
trunk/src/VBox/Main/testcase/tstAPI.cpp
r10870 r10878 975 975 CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam())); 976 976 977 RTThreadSleep( 3000); // Sleep for 10seconds977 RTThreadSleep(5000); // Sleep for 5 seconds 978 978 979 979 printf("Metrics collected with DSL machine running: --------------------\n"); … … 981 981 982 982 // Pause 983 printf ("Press enter to pause the VM execution in the remote session...");984 getchar();983 //printf ("Press enter to pause the VM execution in the remote session..."); 984 //getchar(); 985 985 CHECK_RC (console->Pause()); 986 986 987 RTThreadSleep( 10000); // Sleep for 10seconds987 RTThreadSleep(5000); // Sleep for 5 seconds 988 988 989 989 printf("Metrics collected with DSL machine paused: ---------------------\n");
Note:
See TracChangeset
for help on using the changeset viewer.