Changeset 27972 in vbox
- Timestamp:
- Apr 2, 2010 10:59:54 PM (15 years ago)
- Location:
- trunk/src/VBox/Additions/common/VBoxService
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceBalloon.cpp
r27496 r27972 281 281 282 282 /** 283 * Query the size of the memory balloon, given as a count of chunks.283 * Query the size of the memory balloon, given as a page count. 284 284 * 285 * @returns The number of chunks (VMMDEV_MEMORY_BALLOON_CHUNK_SIZE). 286 */ 287 uint32_t VBoxServiceBalloonQueryChunks(void) 288 { 289 return g_cMemBalloonChunks; 285 * @returns Number of pages. 286 * @param cbPage The page size. 287 */ 288 uint32_t VBoxServiceBalloonQueryPages(uint32_t cbPage) 289 { 290 return g_cMemBalloonChunks * (VMMDEV_MEMORY_BALLOON_CHUNK_SIZE / cbPage); 290 291 } 291 292 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h
r27926 r27972 216 216 217 217 #ifdef VBOXSERVICE_MANAGEMENT 218 extern uint32_t VBoxServiceBalloonQuery Chunks(void);218 extern uint32_t VBoxServiceBalloonQueryPages(uint32_t cbPage); 219 219 #endif 220 220 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceStats.cpp
r27944 r27972 19 19 * additional information or have any questions. 20 20 */ 21 #ifdef TARGET_NT4 22 #undef _WIN32_WINNT 23 #define _WIN32_WINNT 0x501 24 #endif 25 21 22 /******************************************************************************* 23 * Header Files * 24 *******************************************************************************/ 26 25 #if defined(RT_OS_WINDOWS) 26 # ifdef TARGET_NT4 27 # undef _WIN32_WINNT 28 # define _WIN32_WINNT 0x501 29 # endif 27 30 # include <windows.h> 28 31 # include <psapi.h> 29 32 # include <winternl.h> 33 30 34 #elif defined(RT_OS_LINUX) 31 35 # include <iprt/ctype.h> 32 36 # include <iprt/stream.h> 37 # include <unistd.h> 38 39 #else 40 /** @todo port me. */ 41 33 42 #endif 34 43 35 44 #include <iprt/assert.h> 36 45 #include <iprt/mem.h> 37 #include <iprt/thread.h> 46 #include <VBox/param.h> 47 #include <iprt/semaphore.h> 38 48 #include <iprt/string.h> 39 #include <iprt/semaphore.h>40 49 #include <iprt/system.h> 41 50 #include <iprt/time.h> 51 #include <iprt/thread.h> 42 52 #include <VBox/VBoxGuestLib.h> 43 53 #include "VBoxServiceInternal.h" 44 54 #include "VBoxServiceUtils.h" 45 55 46 #define NR_CPUS 32 47 56 57 /******************************************************************************* 58 * Structures and Typedefs * 59 *******************************************************************************/ 48 60 typedef struct _VBOXSTATSCONTEXT 49 61 { 50 62 RTMSINTERVAL cMsStatInterval; 51 63 52 uint64_t u64LastCpuLoad_Idle[NR_CPUS];53 uint64_t u64LastCpuLoad_Kernel[NR_CPUS];54 uint64_t u64LastCpuLoad_User[NR_CPUS];55 uint64_t u64LastCpuLoad_Nice[NR_CPUS];64 uint64_t au64LastCpuLoad_Idle[VMM_MAX_CPU_COUNT]; 65 uint64_t au64LastCpuLoad_Kernel[VMM_MAX_CPU_COUNT]; 66 uint64_t au64LastCpuLoad_User[VMM_MAX_CPU_COUNT]; 67 uint64_t au64LastCpuLoad_Nice[VMM_MAX_CPU_COUNT]; 56 68 57 69 #ifdef RT_OS_WINDOWS … … 62 74 } VBOXSTATSCONTEXT; 63 75 76 64 77 /******************************************************************************* 65 78 * Global Variables * … … 98 111 99 112 gCtx.cMsStatInterval = 0; /* default; update disabled */ 100 RT_ZERO(gCtx. u64LastCpuLoad_Idle);101 RT_ZERO(gCtx. u64LastCpuLoad_Kernel);102 RT_ZERO(gCtx. u64LastCpuLoad_User);103 RT_ZERO(gCtx. u64LastCpuLoad_Nice);113 RT_ZERO(gCtx.au64LastCpuLoad_Idle); 114 RT_ZERO(gCtx.au64LastCpuLoad_Kernel); 115 RT_ZERO(gCtx.au64LastCpuLoad_User); 116 RT_ZERO(gCtx.au64LastCpuLoad_Nice); 104 117 105 118 rc = VbglR3StatQueryInterval(&gCtx.cMsStatInterval); … … 153 166 154 167 155 static void VBoxServiceVMStatsReport() 168 /** 169 * Gathers VM statistics and reports them to the host. 170 * 171 * @returns 172 * @param oid . 173 */ 174 static void VBoxServiceVMStatsReport(void) 156 175 { 157 176 #if defined(RT_OS_WINDOWS) … … 159 178 PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION pProcInfo; 160 179 MEMORYSTATUSEX memStatus; 161 VMMDevReportGuestStats req;162 180 uint32_t cbStruct; 163 181 DWORD cbReturned; … … 168 186 return; 169 187 188 /* Clear the report so we don't report garbage should NtQuerySystemInformation 189 behave in an unexpected manner. */ 190 VMMDevReportGuestStats req; 191 RT_ZERO(req); 192 170 193 /* Query and report guest statistics */ 171 194 GetSystemInfo(&systemInfo); … … 175 198 176 199 req.guestStats.u32PageSize = systemInfo.dwPageSize; 177 req.guestStats.u32PhysMemTotal = (uint32_t)(memStatus.ullTotalPhys / systemInfo.dwPageSize); 178 req.guestStats.u32PhysMemAvail = (uint32_t)(memStatus.ullAvailPhys / systemInfo.dwPageSize); 179 /* The current size of the committed memory limit, in bytes. This is physical memory plus the size of the page file, minus a small overhead. */ 180 req.guestStats.u32PageFileSize = (uint32_t)(memStatus.ullTotalPageFile / systemInfo.dwPageSize) - req.guestStats.u32PhysMemTotal; 200 req.guestStats.u32PhysMemTotal = (uint32_t)(memStatus.ullTotalPhys / _4K); 201 req.guestStats.u32PhysMemAvail = (uint32_t)(memStatus.ullAvailPhys / _4K); 202 /* The current size of the committed memory limit, in bytes. This is physical 203 memory plus the size of the page file, minus a small overhead. */ 204 req.guestStats.u32PageFileSize = (uint32_t)(memStatus.ullTotalPageFile / _4K) - req.guestStats.u32PhysMemTotal; 181 205 req.guestStats.u32MemoryLoad = memStatus.dwMemoryLoad; 182 req.guestStats.u32PhysMemBalloon = VBoxServiceBalloonQueryChunks() * (_1M/systemInfo.dwPageSize); /* was in megabytes */ 183 req.guestStats.u32StatCaps = VBOX_GUEST_STAT_PHYS_MEM_TOTAL | VBOX_GUEST_STAT_PHYS_MEM_AVAIL | VBOX_GUEST_STAT_PAGE_FILE_SIZE | VBOX_GUEST_STAT_MEMORY_LOAD | VBOX_GUEST_STAT_PHYS_MEM_BALLOON; 206 req.guestStats.u32PhysMemBalloon = VBoxServiceBalloonQueryPages(_4K); 207 req.guestStats.u32StatCaps = VBOX_GUEST_STAT_PHYS_MEM_TOTAL | VBOX_GUEST_STAT_PHYS_MEM_AVAIL | VBOX_GUEST_STAT_PAGE_FILE_SIZE 208 | VBOX_GUEST_STAT_MEMORY_LOAD | VBOX_GUEST_STAT_PHYS_MEM_BALLOON; 184 209 185 210 if (gCtx.pfnGetPerformanceInfo) … … 197 222 req.guestStats.u32MemKernelNonPaged = perfInfo.KernelNonpaged; /* already in pages */ 198 223 req.guestStats.u32MemSystemCache = perfInfo.SystemCache; /* already in pages */ 199 req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_PROCESSES | VBOX_GUEST_STAT_THREADS | VBOX_GUEST_STAT_HANDLES | VBOX_GUEST_STAT_MEM_COMMIT_TOTAL | VBOX_GUEST_STAT_MEM_KERNEL_TOTAL | VBOX_GUEST_STAT_MEM_KERNEL_PAGED | VBOX_GUEST_STAT_MEM_KERNEL_NONPAGED | VBOX_GUEST_STAT_MEM_SYSTEM_CACHE; 224 req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_PROCESSES | VBOX_GUEST_STAT_THREADS | VBOX_GUEST_STAT_HANDLES 225 | VBOX_GUEST_STAT_MEM_COMMIT_TOTAL | VBOX_GUEST_STAT_MEM_KERNEL_TOTAL 226 | VBOX_GUEST_STAT_MEM_KERNEL_PAGED | VBOX_GUEST_STAT_MEM_KERNEL_NONPAGED 227 | VBOX_GUEST_STAT_MEM_SYSTEM_CACHE; 200 228 } 201 229 else … … 204 232 205 233 /* Query CPU load information */ 206 cbStruct = systemInfo.dwNumberOfProcessors*sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION); 207 pProcInfo = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)malloc(cbStruct); 208 Assert(pProcInfo); 234 cbStruct = systemInfo.dwNumberOfProcessors * sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION); 235 pProcInfo = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)RTMemAlloc(cbStruct); 209 236 if (!pProcInfo) 210 237 return; … … 215 242 && cbReturned == cbStruct) 216 243 { 217 if (gCtx. u64LastCpuLoad_Kernel == 0)244 if (gCtx.au64LastCpuLoad_Kernel == 0) 218 245 { 219 246 /* first time */ 220 gCtx. u64LastCpuLoad_Idle[0] = pProcInfo->IdleTime.QuadPart;221 gCtx. u64LastCpuLoad_Kernel[0] = pProcInfo->KernelTime.QuadPart;222 gCtx. u64LastCpuLoad_User[0] = pProcInfo->UserTime.QuadPart;247 gCtx.au64LastCpuLoad_Idle[0] = pProcInfo->IdleTime.QuadPart; 248 gCtx.au64LastCpuLoad_Kernel[0] = pProcInfo->KernelTime.QuadPart; 249 gCtx.au64LastCpuLoad_User[0] = pProcInfo->UserTime.QuadPart; 223 250 224 251 Sleep(250); … … 228 255 } 229 256 230 uint64_t deltaIdle = (pProcInfo->IdleTime.QuadPart - gCtx. u64LastCpuLoad_Idle[0]);231 uint64_t deltaKernel = (pProcInfo->KernelTime.QuadPart - gCtx. u64LastCpuLoad_Kernel[0]);232 uint64_t deltaUser = (pProcInfo->UserTime.QuadPart - gCtx. u64LastCpuLoad_User[0]);257 uint64_t deltaIdle = (pProcInfo->IdleTime.QuadPart - gCtx.au64LastCpuLoad_Idle[0]); 258 uint64_t deltaKernel = (pProcInfo->KernelTime.QuadPart - gCtx.au64LastCpuLoad_Kernel[0]); 259 uint64_t deltaUser = (pProcInfo->UserTime.QuadPart - gCtx.au64LastCpuLoad_User[0]); 233 260 deltaKernel -= deltaIdle; /* idle time is added to kernel time */ 234 261 uint64_t ullTotalTime = deltaIdle + deltaKernel + deltaUser; … … 240 267 req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_CPU_LOAD_IDLE | VBOX_GUEST_STAT_CPU_LOAD_KERNEL | VBOX_GUEST_STAT_CPU_LOAD_USER; 241 268 242 gCtx.u64LastCpuLoad_Idle[0] = pProcInfo->IdleTime.QuadPart; 243 gCtx.u64LastCpuLoad_Kernel[0] = pProcInfo->KernelTime.QuadPart; 244 gCtx.u64LastCpuLoad_User[0] = pProcInfo->UserTime.QuadPart; 245 } 246 247 for (uint32_t i=0; i<systemInfo.dwNumberOfProcessors; i++) 269 gCtx.au64LastCpuLoad_Idle[0] = pProcInfo->IdleTime.QuadPart; 270 gCtx.au64LastCpuLoad_Kernel[0] = pProcInfo->KernelTime.QuadPart; 271 gCtx.au64LastCpuLoad_User[0] = pProcInfo->UserTime.QuadPart; 272 /** @todo SMP: report details for each CPU? */ 273 } 274 275 for (uint32_t i = 0; i < systemInfo.dwNumberOfProcessors; i++) 248 276 { 249 277 req.guestStats.u32CpuId = i; … … 256 284 } 257 285 258 free(pProcInfo);286 RTMemFree(pProcInfo); 259 287 260 288 #elif defined(RT_OS_LINUX) … … 313 341 } 314 342 315 req.guestStats.u32PhysMemBalloon = VBoxServiceBalloonQueryChunks() * (_1M/_4K); 343 req.guestStats.u32PageSize = getpagesize(); 344 req.guestStats.u32PhysMemBalloon = VBoxServiceBalloonQueryPages(_4K); 316 345 req.guestStats.u32StatCaps = VBOX_GUEST_STAT_PHYS_MEM_TOTAL \ 317 346 | VBOX_GUEST_STAT_PHYS_MEM_AVAIL \ … … 319 348 | VBOX_GUEST_STAT_PAGE_FILE_SIZE; 320 349 350 /** @todo req.guestStats.u32Threads */ 351 /** @todo req.guestStats.u32Processes */ 352 /* req.guestStats.u32Handles doesn't make sense here. */ 353 /** @todo req.guestStats.u32MemoryLoad */ 354 /** @todo req.guestStats.u32MemCommitTotal */ 355 /** @todo req.guestStats.u32MemKernelTotal */ 356 /** @todo req.guestStats.u32MemKernelPaged, make any sense? = u32MemKernelTotal? */ 357 /** @todo req.guestStats.u32MemKernelNonPaged, make any sense? = 0? */ 358 321 359 rc = RTStrmOpen("/proc/stat", "r", &pStrm); 322 360 if (RT_SUCCESS(rc)) … … 324 362 for (;;) 325 363 { 326 uint32_t u32CpuId;327 uint64_t u64User = 0, u64Nice = 0, u64System = 0, u64Idle = 0;328 364 rc = RTStrmGetLine(pStrm, szLine, sizeof(szLine)); 329 365 if (RT_FAILURE(rc)) … … 333 369 && RT_C_IS_DIGIT(szLine[3])) 334 370 { 371 uint32_t u32CpuId; 335 372 rc = RTStrToUInt32Ex(&szLine[3], &psz, 0, &u32CpuId); 336 if (u32CpuId < NR_CPUS)373 if (u32CpuId < VMM_MAX_CPU_COUNT) 337 374 { 375 uint64_t u64User = 0; 338 376 if (RT_SUCCESS(rc)) 339 377 rc = RTStrToUInt64Ex(RTStrStripL(psz), &psz, 0, &u64User); 378 379 uint64_t u64Nice = 0; 340 380 if (RT_SUCCESS(rc)) 341 381 rc = RTStrToUInt64Ex(RTStrStripL(psz), &psz, 0, &u64Nice); 382 383 uint64_t u64System = 0; 342 384 if (RT_SUCCESS(rc)) 343 385 rc = RTStrToUInt64Ex(RTStrStripL(psz), &psz, 0, &u64System); 386 387 uint64_t u64Idle = 0; 344 388 if (RT_SUCCESS(rc)) 345 389 rc = RTStrToUInt64Ex(RTStrStripL(psz), &psz, 0, &u64Idle); 346 390 347 uint64_t u64DeltaIdle = u64Idle - gCtx. u64LastCpuLoad_Idle[u32CpuId];348 uint64_t u64DeltaSystem = u64System - gCtx. u64LastCpuLoad_Kernel[u32CpuId];349 uint64_t u64DeltaUser = u64User - gCtx. u64LastCpuLoad_User[u32CpuId];350 uint64_t u64DeltaNice = u64Nice - gCtx. u64LastCpuLoad_Nice[u32CpuId];391 uint64_t u64DeltaIdle = u64Idle - gCtx.au64LastCpuLoad_Idle[u32CpuId]; 392 uint64_t u64DeltaSystem = u64System - gCtx.au64LastCpuLoad_Kernel[u32CpuId]; 393 uint64_t u64DeltaUser = u64User - gCtx.au64LastCpuLoad_User[u32CpuId]; 394 uint64_t u64DeltaNice = u64Nice - gCtx.au64LastCpuLoad_Nice[u32CpuId]; 351 395 352 396 uint64_t u64DeltaAll = u64DeltaIdle … … 355 399 + u64DeltaNice; 356 400 357 gCtx. u64LastCpuLoad_Idle[u32CpuId] = u64Idle;358 gCtx. u64LastCpuLoad_Kernel[u32CpuId] = u64System;359 gCtx. u64LastCpuLoad_User[u32CpuId] = u64User;360 gCtx. u64LastCpuLoad_Nice[u32CpuId] = u64Nice;401 gCtx.au64LastCpuLoad_Idle[u32CpuId] = u64Idle; 402 gCtx.au64LastCpuLoad_Kernel[u32CpuId] = u64System; 403 gCtx.au64LastCpuLoad_User[u32CpuId] = u64User; 404 gCtx.au64LastCpuLoad_Nice[u32CpuId] = u64Nice; 361 405 362 406 req.guestStats.u32CpuId = u32CpuId; 363 407 req.guestStats.u32CpuLoad_Idle = (uint32_t)(u64DeltaIdle * 100 / u64DeltaAll); 364 408 req.guestStats.u32CpuLoad_Kernel = (uint32_t)(u64DeltaSystem * 100 / u64DeltaAll); 365 req.guestStats.u32CpuLoad_User = (uint32_t)((u64DeltaUser 409 req.guestStats.u32CpuLoad_User = (uint32_t)((u64DeltaUser 366 410 + u64DeltaNice) * 100 / u64DeltaAll); 367 411 req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_CPU_LOAD_IDLE \
Note:
See TracChangeset
for help on using the changeset viewer.