int cm_get_host_stat (T_CM_HOST_STAT * stat, T_CM_ERROR * err_buf) { __int64 kernel, user, idle; PERFORMANCE_INFORMATION pi; if (get_cpu_time (&kernel, &user, &idle) != 0) { return 1; } stat->cpu_kernel = kernel; stat->cpu_user = user; stat->cpu_idle = idle; stat->cpu_iowait = 0; memset (&pi, 0, sizeof (pi)); pi.cb = sizeof (pi); if (!GetPerformanceInfo (&pi, sizeof (pi))) { return 1; } stat->mem_physical_total = ((__int64) pi.PhysicalTotal) * pi.PageSize; stat->mem_physical_free = ((__int64) pi.PhysicalAvailable) * pi.PageSize; stat->mem_swap_total = ((__int64) pi.CommitLimit) * pi.PageSize; stat->mem_swap_free = ((__int64) (pi.CommitLimit - pi.CommitTotal)) * pi.PageSize; return 0; }
// FIX ME: win2k+ so should do version checks really. static int Win32_GetPerformanceInfo(Jim_Interp *interp, int objc, Jim_Obj * const *objv) { Jim_Obj *a[26]; size_t n = 0; PERFORMANCE_INFORMATION pi; if (!GetPerformanceInfo(&pi, sizeof(pi))) { Jim_SetResult(interp, Win32ErrorObj(interp, "GetPerformanceInfo", GetLastError())); return JIM_ERR; } #define JIMADD(name) \ a[n++] = Jim_NewStringObj(interp, #name, -1); \ a[n++] = Jim_NewIntObj(interp, pi. name ) JIMADD(CommitTotal); JIMADD(CommitLimit); JIMADD(CommitPeak); JIMADD(PhysicalTotal); JIMADD(PhysicalAvailable); JIMADD(SystemCache); JIMADD(KernelTotal); JIMADD(KernelPaged); JIMADD(KernelNonpaged); JIMADD(PageSize); JIMADD(HandleCount); JIMADD(ProcessCount); JIMADD(ThreadCount); #undef JIMADD Jim_SetResult(interp, Jim_NewListObj(interp, a, n)); return JIM_OK; }
APR_DECLARE(size_t) port_vmem_max_size(){ PERFORMANCE_INFORMATION pi; if ( GetPerformanceInfo( &pi, sizeof(pi)) ) { return (pi.CommitLimit - pi.CommitTotal) * pi.PageSize + port_vmem_committed_size(); } else { return (size_t)0; } }
void PrintMemInfo(int id){ LPBYTE currAddress = 0; PSAPI_WORKING_SET_INFORMATION wsi; PSAPI_WORKING_SET_BLOCK* wsb; PERFORMANCE_INFORMATION pi; MEMORYSTATUSEX ms; PROCESS_MEMORY_COUNTERS pmc; PROCESS_MEMORY_COUNTERS_EX pmcex; DWORD countPrivatePages = 0; MEMORY_BASIC_INFORMATION mbi; LPBYTE regionNonFree = 0; ms.dwLength = sizeof (ms); _tprintf(_T("Informacao do sistema\n")); GetPerformanceInfo(&pi , sizeof(PERFORMANCE_INFORMATION)); _tprintf(_T("\nTotal Memoria existente fisica em paginas->%d\n"),pi.PhysicalTotal); _tprintf(_T("Total Memoria ocupada fisica em paginas->%d\n"), (pi.PhysicalTotal - pi.PhysicalAvailable)); GlobalMemoryStatusEx(&ms); _tprintf(_T("Total Memoria existente virtual em kb->%d\n"),ms.ullTotalPageFile / 1024); _tprintf(_T("Total Memoria ocupada virtual em kb->%d\n"),(ms.ullTotalPageFile - ms.ullAvailVirtual) / 1024); _tprintf(_T("\nInformacao do processo\n")); HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, id ); if(!hProcess) return ; QueryWorkingSet(hProcess,&wsi,sizeof(wsi)); wsb = wsi.WorkingSetInfo; _tprintf(_T("Dimensão do working set ->%d\n"),sizeof(wsb)*wsi.NumberOfEntries); GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)); _tprintf(_T("Page fault count ->%d\n"),pmc.PageFaultCount); while (VirtualQueryEx( hProcess, currAddress, &mbi, sizeof(mbi)) > 0) { if (mbi.State != MEM_FREE) regionNonFree += mbi.RegionSize; currAddress += mbi.RegionSize; } _tprintf(_T("Total de espaço de endereçamento existente->%d\n"),currAddress-hProcess); _tprintf(_T("Total de espaço de endereçamento ocupado ->%d\n"),regionNonFree); for(int i = 0 ; i<sizeof(wsi) ; ++i){ if(!(wsb+i)->Shared){ countPrivatePages++; } } _tprintf(_T("Total de private pages->%d\n"),countPrivatePages); }
static ULONGLONG query_commit_limit() { PERFORMANCE_INFORMATION perf_info; perf_info.cb = sizeof(perf_info); auto success = GetPerformanceInfo(&perf_info, sizeof(perf_info)); if (!success) w32util::throw_windows_error(); lbx_log_debug("Queried commit limit: %lu, page_size: %lu\n", (long unsigned) perf_info.CommitLimit, (long unsigned) perf_info.PageSize); return ((ULONGLONG) perf_info.CommitLimit * (ULONGLONG) perf_info.PageSize); }
int getrusage(int who, rusage *usage) { HANDLE proc_hand; file_t c_time, x_time, s_time, u_time; int cb = 0, err = -1; if(who != RUSAGE_SELF) { errno = (who == RUSAGE_CHILDREN ? ENODATA : EINVAL); return err; } proc_hand = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, GetCurrentProcessId()); if(GetProcessTimes(proc_hand, &(c_time.ft), &(x_time.ft), &(s_time.ft), &(u_time.ft))) { PROCESS_MEMORY_COUNTERS ctrs; /* The units returned by GetProcessTimes are 100 nanoseconds */ u_time.lt = (u_time.lt + 5) / 10; s_time.lt = (s_time.lt + 5) / 10; usage->ru_utime.tv_sec = (long)(u_time.lt / 1000000ll); usage->ru_stime.tv_sec = (long)(s_time.lt / 1000000ll); usage->ru_utime.tv_usec = (long)(u_time.lt % 1000000ll); usage->ru_stime.tv_usec = (long)(s_time.lt % 1000000ll); if(GetProcessMemoryInfo(proc_hand, &ctrs, sizeof(ctrs))) { PERFORMANCE_INFORMATION perf_info; GetPerformanceInfo(&perf_info, sizeof(perf_info)); usage->ru_maxrss = (DWORD) (ctrs.WorkingSetSize / perf_info.PageSize); usage->ru_majflt = ctrs.PageFaultCount; err = 0; } } if(err) errno = EACCES; CloseHandle(proc_hand); return err; }
BOOL MEMINFO_API C_GetSystemMemInfo(_Out_ PSYSMEMINFO_C pSysMemInfo){ PPERFORMACE_INFORMATION ppinfo = malloc(sizeof(PERFORMACE_INFORMATION)); ULONGLONG totalVirtualMem, totalVirtualMemAvail, totalPhysMem, totalPhysMemAvail; printf("~~~~ INFORMACAO GLOBAL ~~~~~"); if (GetPerformanceInfo(ppinfo, sizeof(PERFORMACE_INFORMATION)) == FALSE) return FALSE; totalVirtualMem = ppinfo->PageSize * (ULONGLONG)ppinfo->CommitLimit; totalVirtualMemAvail = ppinfo->PageSize * (ULONGLONG)ppinfo->CommitTotal; totalPhysMem = ppinfo->PageSize*ppinfo->PhysicalTotal; totalPhysMemAvail = ppinfo->PageSize*ppinfo->PhysicalAvailable; printf("\nTotal de memoria fisica existente: %llu KiB = %llu MiB = %.2f GiB", totalPhysMem / KiloB, totalPhysMem / MegaB, totalPhysMem / GigaB); printf("\nTotal de memoria fisica disponivel: %llu KiB = %llu MiB = %.2f GiB", totalPhysMemAvail / KiloB, totalPhysMemAvail / MegaB, totalPhysMemAvail / GigaB); printf("\nTotal de memoria virtual existente (fisica + page file): %llu KiB = %llu MiB = %.2f GiB", totalVirtualMem / KiloB, totalVirtualMem / MegaB, totalVirtualMem / GigaB); printf("\nTotal de memoria virtual disponivel: %llu KiB = %llu MiB = %.2f GiB", totalVirtualMemAvail / KiloB, totalVirtualMemAvail / MegaB, totalVirtualMemAvail / GigaB); printf("\nClique em qualquer tecla para ver a informação local do processo..."); getchar(); return TRUE; }
void ShowMemoryInfo() { auto localMemory = GetLocalMemoryInfo(); auto nonLocalMemory = GetNonLocalMemoryInfo(); ImGui::BulletText("Device memory"); ImGui::Indent(); ImGui::Text("Local memory"); ImGui::Text("Budget:\nCurrent usage:"); ImGui::SameLine(); ImGui::Text("%llu Mb\n%llu Mb", Megabytes(localMemory.Budget), Megabytes(localMemory.CurrentUsage)); ImGui::Text("Non-Local memory"); ImGui::Text("Budget:\nCurrent usage:"); ImGui::SameLine(); ImGui::Text("%llu Mb\n%llu Mb", Megabytes(nonLocalMemory.Budget), Megabytes(nonLocalMemory.CurrentUsage)); ImGui::Unindent(); ImGui::Separator(); ImGui::BulletText("Process memory"); PROCESS_MEMORY_COUNTERS pmc; verify(GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))); ImGui::Indent(); ImGui::Text("Working set:\nPagefile:"); ImGui::SameLine(); ImGui::Text("%llu Mb\n%llu Mb", Megabytes(pmc.WorkingSetSize), Megabytes(pmc.PagefileUsage)); ImGui::Unindent(); ImGui::Separator(); ImGui::BulletText("System memory"); PERFORMANCE_INFORMATION perfInfo; verify(GetPerformanceInfo(&perfInfo, sizeof(perfInfo))); ImGui::Indent(); ImGui::Text("Commited total:\nPhysical total:\nPhysical available:"); ImGui::SameLine(); ImGui::Text("%llu Mb\n%llu Mb\n%llu Mb" , Megabytes(perfInfo.CommitTotal * perfInfo.PageSize) , Megabytes(perfInfo.PhysicalTotal * perfInfo.PageSize) , Megabytes(perfInfo.PhysicalAvailable * perfInfo.PageSize)); ImGui::Unindent(); }
//---------------------------------------------------------------------------- // Function: SystemInfo // // Description: // Returns the resource information about the machine // // Returns: // EXIT_SUCCESS: On success // EXIT_FAILURE: otherwise int SystemInfo() { size_t vmemSize, vmemFree, memSize, memFree; PERFORMANCE_INFORMATION memInfo; SYSTEM_INFO sysInfo; FILETIME idleTimeFt, kernelTimeFt, userTimeFt; ULARGE_INTEGER idleTime, kernelTime, userTime; ULONGLONG cpuTimeMs; size_t size; LPBYTE pBuffer; PROCESSOR_POWER_INFORMATION const *ppi; ULONGLONG cpuFrequencyKhz; NTSTATUS status; ZeroMemory(&memInfo, sizeof(PERFORMANCE_INFORMATION)); memInfo.cb = sizeof(PERFORMANCE_INFORMATION); if(!GetPerformanceInfo(&memInfo, sizeof(PERFORMANCE_INFORMATION))) { ReportErrorCode(L"GetPerformanceInfo", GetLastError()); return EXIT_FAILURE; } vmemSize = memInfo.CommitLimit*memInfo.PageSize; vmemFree = vmemSize - memInfo.CommitTotal*memInfo.PageSize; memSize = memInfo.PhysicalTotal*memInfo.PageSize; memFree = memInfo.PhysicalAvailable*memInfo.PageSize; GetSystemInfo(&sysInfo); if(!GetSystemTimes(&idleTimeFt, &kernelTimeFt, &userTimeFt)) { ReportErrorCode(L"GetSystemTimes", GetLastError()); return EXIT_FAILURE; } idleTime.HighPart = idleTimeFt.dwHighDateTime; idleTime.LowPart = idleTimeFt.dwLowDateTime; kernelTime.HighPart = kernelTimeFt.dwHighDateTime; kernelTime.LowPart = kernelTimeFt.dwLowDateTime; userTime.HighPart = userTimeFt.dwHighDateTime; userTime.LowPart = userTimeFt.dwLowDateTime; cpuTimeMs = (kernelTime.QuadPart - idleTime.QuadPart + userTime.QuadPart)/10000; // allocate buffer to get info for each processor size = sysInfo.dwNumberOfProcessors * sizeof(PROCESSOR_POWER_INFORMATION); pBuffer = (BYTE*) LocalAlloc(LPTR, size); if(!pBuffer) { ReportErrorCode(L"LocalAlloc", GetLastError()); return EXIT_FAILURE; } status = CallNtPowerInformation(ProcessorInformation, NULL, 0, pBuffer, (long)size); if(0 != status) { fwprintf_s(stderr, L"Error in CallNtPowerInformation. Err:%d\n", status); LocalFree(pBuffer); return EXIT_FAILURE; } ppi = (PROCESSOR_POWER_INFORMATION const *)pBuffer; cpuFrequencyKhz = ppi->MaxMhz*1000; LocalFree(pBuffer); fwprintf_s(stdout, L"%Iu,%Iu,%Iu,%Iu,%u,%I64u,%I64u\n", vmemSize, memSize, vmemFree, memFree, sysInfo.dwNumberOfProcessors, cpuFrequencyKhz, cpuTimeMs); return EXIT_SUCCESS; }