- Timestamp:
- Apr 1, 2010 3:16:14 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceStats.cpp
r27943 r27944 44 44 #include "VBoxServiceUtils.h" 45 45 46 #define NR_CPUS 32 47 46 48 typedef struct _VBOXSTATSCONTEXT 47 49 { 48 50 RTMSINTERVAL cMsStatInterval; 49 51 50 uint64_t ullLastCpuLoad_Idle; 51 uint64_t ullLastCpuLoad_Kernel; 52 uint64_t ullLastCpuLoad_User; 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]; 53 56 54 57 #ifdef RT_OS_WINDOWS … … 95 98 96 99 gCtx.cMsStatInterval = 0; /* default; update disabled */ 97 gCtx.ullLastCpuLoad_Idle = 0; 98 gCtx.ullLastCpuLoad_Kernel = 0; 99 gCtx.ullLastCpuLoad_User = 0; 100 RT_ZERO(gCtx.u64LastCpuLoad_Idle); 101 RT_ZERO(gCtx.u64LastCpuLoad_Kernel); 102 RT_ZERO(gCtx.u64LastCpuLoad_User); 103 RT_ZERO(gCtx.u64LastCpuLoad_Nice); 100 104 101 105 rc = VbglR3StatQueryInterval(&gCtx.cMsStatInterval); … … 211 215 && cbReturned == cbStruct) 212 216 { 213 if (gCtx.u llLastCpuLoad_Kernel == 0)217 if (gCtx.u64LastCpuLoad_Kernel == 0) 214 218 { 215 219 /* first time */ 216 gCtx.u llLastCpuLoad_Idle= pProcInfo->IdleTime.QuadPart;217 gCtx.u llLastCpuLoad_Kernel= pProcInfo->KernelTime.QuadPart;218 gCtx.u llLastCpuLoad_User= pProcInfo->UserTime.QuadPart;220 gCtx.u64LastCpuLoad_Idle[0] = pProcInfo->IdleTime.QuadPart; 221 gCtx.u64LastCpuLoad_Kernel[0] = pProcInfo->KernelTime.QuadPart; 222 gCtx.u64LastCpuLoad_User[0] = pProcInfo->UserTime.QuadPart; 219 223 220 224 Sleep(250); … … 224 228 } 225 229 226 uint64_t deltaIdle = (pProcInfo->IdleTime.QuadPart - gCtx.ullLastCpuLoad_Idle);227 uint64_t deltaKernel = (pProcInfo->KernelTime.QuadPart - gCtx.u llLastCpuLoad_Kernel);228 uint64_t deltaUser = (pProcInfo->UserTime.QuadPart - gCtx.ullLastCpuLoad_User);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]); 229 233 deltaKernel -= deltaIdle; /* idle time is added to kernel time */ 230 234 uint64_t ullTotalTime = deltaIdle + deltaKernel + deltaUser; … … 236 240 req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_CPU_LOAD_IDLE | VBOX_GUEST_STAT_CPU_LOAD_KERNEL | VBOX_GUEST_STAT_CPU_LOAD_USER; 237 241 238 gCtx.u llLastCpuLoad_Idle= pProcInfo->IdleTime.QuadPart;239 gCtx.u llLastCpuLoad_Kernel= pProcInfo->KernelTime.QuadPart;240 gCtx.u llLastCpuLoad_User= pProcInfo->UserTime.QuadPart;242 gCtx.u64LastCpuLoad_Idle[0] = pProcInfo->IdleTime.QuadPart; 243 gCtx.u64LastCpuLoad_Kernel[0] = pProcInfo->KernelTime.QuadPart; 244 gCtx.u64LastCpuLoad_User[0] = pProcInfo->UserTime.QuadPart; 241 245 } 242 246 … … 320 324 for (;;) 321 325 { 322 uint64_t u64CpuId, u64User = 0, u64Nice = 0, u64System = 0, u64Idle = 0; 326 uint32_t u32CpuId; 327 uint64_t u64User = 0, u64Nice = 0, u64System = 0, u64Idle = 0; 323 328 rc = RTStrmGetLine(pStrm, szLine, sizeof(szLine)); 324 329 if (RT_FAILURE(rc)) … … 328 333 && RT_C_IS_DIGIT(szLine[3])) 329 334 { 330 rc = RTStrToUInt64Ex(&szLine[3], &psz, 0, &u64CpuId); 331 if (RT_SUCCESS(rc)) 332 rc = RTStrToUInt64Ex(RTStrStripL(psz), &psz, 0, &u64User); 333 if (RT_SUCCESS(rc)) 334 rc = RTStrToUInt64Ex(RTStrStripL(psz), &psz, 0, &u64Nice); 335 if (RT_SUCCESS(rc)) 336 rc = RTStrToUInt64Ex(RTStrStripL(psz), &psz, 0, &u64System); 337 if (RT_SUCCESS(rc)) 338 rc = RTStrToUInt64Ex(RTStrStripL(psz), &psz, 0, &u64Idle); 339 uint64_t u64All = u64Idle + u64System + u64User + u64Nice; 340 req.guestStats.u32CpuId = u64CpuId; 341 req.guestStats.u32CpuLoad_Idle = (uint32_t)(u64Idle * 100 / u64All); 342 req.guestStats.u32CpuLoad_Kernel = (uint32_t)(u64System * 100 / u64All); 343 req.guestStats.u32CpuLoad_User = (uint32_t)((u64User + u64Nice) * 100 / u64All); 344 req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_CPU_LOAD_IDLE \ 345 | VBOX_GUEST_STAT_CPU_LOAD_KERNEL \ 346 | VBOX_GUEST_STAT_CPU_LOAD_USER; 347 rc = VbglR3StatReport(&req); 348 if (RT_SUCCESS(rc)) 349 VBoxServiceVerbose(3, "VBoxStatsReportStatistics: new statistics reported successfully!\n"); 350 else 351 VBoxServiceVerbose(3, "VBoxStatsReportStatistics: stats report failed with rc=%Rrc\n", rc); 335 rc = RTStrToUInt32Ex(&szLine[3], &psz, 0, &u32CpuId); 336 if (u32CpuId < NR_CPUS) 337 { 338 if (RT_SUCCESS(rc)) 339 rc = RTStrToUInt64Ex(RTStrStripL(psz), &psz, 0, &u64User); 340 if (RT_SUCCESS(rc)) 341 rc = RTStrToUInt64Ex(RTStrStripL(psz), &psz, 0, &u64Nice); 342 if (RT_SUCCESS(rc)) 343 rc = RTStrToUInt64Ex(RTStrStripL(psz), &psz, 0, &u64System); 344 if (RT_SUCCESS(rc)) 345 rc = RTStrToUInt64Ex(RTStrStripL(psz), &psz, 0, &u64Idle); 346 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]; 351 352 uint64_t u64DeltaAll = u64DeltaIdle 353 + u64DeltaSystem 354 + u64DeltaUser 355 + u64DeltaNice; 356 357 gCtx.u64LastCpuLoad_Idle[u32CpuId] = u64Idle; 358 gCtx.u64LastCpuLoad_Kernel[u32CpuId] = u64System; 359 gCtx.u64LastCpuLoad_User[u32CpuId] = u64User; 360 gCtx.u64LastCpuLoad_Nice[u32CpuId] = u64Nice; 361 362 req.guestStats.u32CpuId = u32CpuId; 363 req.guestStats.u32CpuLoad_Idle = (uint32_t)(u64DeltaIdle * 100 / u64DeltaAll); 364 req.guestStats.u32CpuLoad_Kernel = (uint32_t)(u64DeltaSystem * 100 / u64DeltaAll); 365 req.guestStats.u32CpuLoad_User = (uint32_t)((u64DeltaUser 366 + u64DeltaNice) * 100 / u64DeltaAll); 367 req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_CPU_LOAD_IDLE \ 368 | VBOX_GUEST_STAT_CPU_LOAD_KERNEL \ 369 | VBOX_GUEST_STAT_CPU_LOAD_USER; 370 rc = VbglR3StatReport(&req); 371 if (RT_SUCCESS(rc)) 372 VBoxServiceVerbose(3, "VBoxStatsReportStatistics: new statistics reported successfully!\n"); 373 else 374 VBoxServiceVerbose(3, "VBoxStatsReportStatistics: stats report failed with rc=%Rrc\n", rc); 375 } 352 376 } 353 377 }
Note:
See TracChangeset
for help on using the changeset viewer.