static DWORD WINAPI ProcessPageRefreshThread(void *lpParameter) { ULONG OldProcessorUsage = 0; ULONG OldProcessCount = 0; WCHAR wszCPU_Usage[255]; WCHAR wszProcesses[255]; LoadStringW(hInst, IDS_STATUS_BAR_CPU_USAGE, wszCPU_Usage, sizeof(wszCPU_Usage)/sizeof(WCHAR)); LoadStringW(hInst, IDS_STATUS_BAR_PROCESSES, wszProcesses, sizeof(wszProcesses)/sizeof(WCHAR)); /* Create the event */ hProcessPageEvent = CreateEventW(NULL, TRUE, TRUE, NULL); /* If we couldn't create the event then exit the thread */ if (!hProcessPageEvent) return 0; while (1) { DWORD dwWaitVal; /* Wait on the event */ dwWaitVal = WaitForSingleObject(hProcessPageEvent, INFINITE); /* If the wait failed then the event object must have been */ /* closed and the task manager is exiting so exit this thread */ if (dwWaitVal == WAIT_FAILED) return 0; if (dwWaitVal == WAIT_OBJECT_0) { WCHAR text[256]; /* Reset our event */ ResetEvent(hProcessPageEvent); if (SendMessageW(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0) != PerfDataGetProcessCount()) SendMessageW(hProcessPageListCtrl, LVM_SETITEMCOUNT, PerfDataGetProcessCount(), /*LVSICF_NOINVALIDATEALL|*/LVSICF_NOSCROLL); if (IsWindowVisible(hProcessPage)) InvalidateRect(hProcessPageListCtrl, NULL, FALSE); if (OldProcessorUsage != PerfDataGetProcessorUsage()) { OldProcessorUsage = PerfDataGetProcessorUsage(); wsprintfW(text, wszCPU_Usage, OldProcessorUsage); SendMessageW(hStatusWnd, SB_SETTEXTW, 1, (LPARAM)text); } if (OldProcessCount != PerfDataGetProcessCount()) { OldProcessCount = PerfDataGetProcessCount(); wsprintfW(text, wszProcesses, OldProcessCount); SendMessageW(hStatusWnd, SB_SETTEXTW, 0, (LPARAM)text); } } } return 0; }
void UpdateProcesses() { int i; ULONG l; LV_ITEM item; LPPROCESS_PAGE_LIST_ITEM pData; SendMessage(hProcessPageListCtrl, WM_SETREDRAW, FALSE, 0); /* Remove old processes */ for (i = 0; i < ListView_GetItemCount(hProcessPageListCtrl); i++) { memset(&item, 0, sizeof (LV_ITEM)); item.mask = LVIF_PARAM; item.iItem = i; (void)ListView_GetItem(hProcessPageListCtrl, &item); pData = (LPPROCESS_PAGE_LIST_ITEM)item.lParam; if (!ProcessRunning(pData->ProcessId)) { (void)ListView_DeleteItem(hProcessPageListCtrl, i); HeapFree(GetProcessHeap(), 0, pData); } } /* Check for difference in listview process and performance process counts */ if (ListView_GetItemCount(hProcessPageListCtrl) != PerfDataGetProcessCount()) { /* Add new processes by checking against the current items */ for (l = 0; l < PerfDataGetProcessCount(); l++) { AddProcess(l); } } if (TaskManagerSettings.SortColumn != -1) { (void)ListView_SortItems(hProcessPageListCtrl, ProcessPageCompareFunc, NULL); } SendMessage(hProcessPageListCtrl, WM_SETREDRAW, TRUE, 0); /* Select first item if any */ if ((ListView_GetNextItem(hProcessPageListCtrl, -1, LVNI_FOCUSED | LVNI_SELECTED) == -1) && (ListView_GetItemCount(hProcessPageListCtrl) > 0) && !bProcessPageSelectionMade) { ListView_SetItemState(hProcessPageListCtrl, 0, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); bProcessPageSelectionMade = TRUE; } /* else { bProcessPageSelectionMade = FALSE; } */ }
static DWORD WINAPI ProcessPageRefreshThread(void *lpParameter) { ULONG OldProcessorUsage = 0; ULONG OldProcessCount = 0; /* Create the event */ hProcessPageEvent = CreateEvent(NULL, TRUE, TRUE, NULL); /* If we couldn't create the event then exit the thread */ if (!hProcessPageEvent) return 0; while (1) { DWORD dwWaitVal; /* Wait on the event */ dwWaitVal = WaitForSingleObject(hProcessPageEvent, INFINITE); /* If the wait failed then the event object must have been */ /* closed and the task manager is exiting so exit this thread */ if (dwWaitVal == WAIT_FAILED) return 0; if (dwWaitVal == WAIT_OBJECT_0) { TCHAR text[260]; /* Reset our event */ ResetEvent(hProcessPageEvent); if ((ULONG)SendMessage(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0) != PerfDataGetProcessCount()) SendMessage(hProcessPageListCtrl, LVM_SETITEMCOUNT, PerfDataGetProcessCount(), /*LVSICF_NOINVALIDATEALL|*/LVSICF_NOSCROLL); if (IsWindowVisible(hProcessPage)) InvalidateRect(hProcessPageListCtrl, NULL, FALSE); if (OldProcessorUsage != PerfDataGetProcessorUsage()) { OldProcessorUsage = PerfDataGetProcessorUsage(); wsprintf(text, _T("CPU Usage: %3d%%"), OldProcessorUsage); SendMessage(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text); } if (OldProcessCount != PerfDataGetProcessCount()) { OldProcessCount = PerfDataGetProcessCount(); wsprintf(text, _T("Processes: %d"), OldProcessCount); SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text); } } } return 0; }
ULONG DisplayPerfGetProcessIdAndCPUMemoryUsage() { //First get the number of process ULONG iNum = PerfDataGetProcessCount(); ULONG i = 0; ULONG iProcCount = 0; char szProcessName[MAX_PATH + 10] = {0}; char szProcess[MAX_PATH + 10] = {0}; printf("\n%-25s%-15s%-15s%15s","Image Name","PID","CPU","Mem Usage"); printf("\n%-25s%-15s%-15s%15s","----------","---","---","---------"); for(i = 0; i < iNum; ++i) { memset(szProcessName,NULL,(MAX_PATH + 10)); PerfDataGetImageName(i,szProcessName,MAX_PATH); printf("\n%-25s%-15ld%-15ld%15ld K", szProcessName, PerfDataGetProcessId(i), PerfDataGetCPUUsage(i), (PerfDataGetWorkingSetSizeBytes(i)/1024)); } printf("\n\nTotal Processes %ld\n\n",iNum); return iProcCount; }
static void TaskManager_OnExitMenuLoop(HWND hWnd) { RECT rc; int nParts[3]; WCHAR text[256]; WCHAR wszCPU_Usage[255]; WCHAR wszProcesses[255]; LoadStringW(hInst, IDS_STATUS_BAR_CPU_USAGE, wszCPU_Usage, sizeof(wszCPU_Usage)/sizeof(WCHAR)); LoadStringW(hInst, IDS_STATUS_BAR_PROCESSES, wszProcesses, sizeof(wszProcesses)/sizeof(WCHAR)); bInMenuLoop = FALSE; /* Update the status bar pane sizes */ GetClientRect(hWnd, &rc); nParts[0] = 100; nParts[1] = 210; nParts[2] = rc.right; SendMessageW(hStatusWnd, SB_SETPARTS, 3, (LPARAM)nParts); SendMessageW(hStatusWnd, SB_SETTEXTW, 0, 0); wsprintfW(text, wszCPU_Usage, PerfDataGetProcessorUsage()); SendMessageW(hStatusWnd, SB_SETTEXTW, 1, (LPARAM)text); wsprintfW(text, wszProcesses, PerfDataGetProcessCount()); SendMessageW(hStatusWnd, SB_SETTEXTW, 0, (LPARAM)text); }
DWORD WINAPI ProcessPageRefreshThread(void *lpParameter) { ULONG OldProcessorUsage = 0; ULONG OldProcessCount = 0; WCHAR szCpuUsage[256], szProcesses[256]; MSG msg; LoadStringW(hInst, IDS_STATUS_CPUUSAGE, szCpuUsage, 256); LoadStringW(hInst, IDS_STATUS_PROCESSES, szProcesses, 256); while (1) { /* Wait for an the event or application close */ if (GetMessage(&msg, NULL, 0, 0) <= 0) return 0; if (msg.message == WM_TIMER) { WCHAR text[260]; UpdateProcesses(); if (IsWindowVisible(hProcessPage)) InvalidateRect(hProcessPageListCtrl, NULL, FALSE); if (OldProcessorUsage != PerfDataGetProcessorUsage()) { OldProcessorUsage = PerfDataGetProcessorUsage(); wsprintfW(text, szCpuUsage, OldProcessorUsage); SendMessageW(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text); } if (OldProcessCount != PerfDataGetProcessCount()) { OldProcessCount = PerfDataGetProcessCount(); wsprintfW(text, szProcesses, OldProcessCount); SendMessageW(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text); } } } return 0; }
void TaskManager_OnExitMenuLoop(HWND hWnd) { RECT rc; int nParts[3]; WCHAR text[260]; WCHAR szCpuUsage[256], szProcesses[256]; LoadStringW(hInst, IDS_STATUS_CPUUSAGE, szCpuUsage, 256); LoadStringW(hInst, IDS_STATUS_PROCESSES, szProcesses, 256); bInMenuLoop = FALSE; /* Update the status bar pane sizes */ GetClientRect(hWnd, &rc); nParts[0] = STATUS_SIZE1; nParts[1] = STATUS_SIZE2; nParts[2] = rc.right; SendMessageW(hStatusWnd, SB_SETPARTS, 3, (LPARAM) (LPINT) nParts); SendMessageW(hStatusWnd, SB_SETTEXT, 0, (LPARAM)L""); wsprintfW(text, szCpuUsage, PerfDataGetProcessorUsage()); SendMessageW(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text); wsprintfW(text, szProcesses, PerfDataGetProcessCount()); SendMessageW(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text); }
ULONG PerfGetProcessIdAndCPUMemoryUsage(LPTSTR lpImageName, ULONG* plProcId, ULONG* plCPUUsage, ULONG* plMemoryUsage) { ULONG iProcCount = 0; try { //First get the number of process ULONG iNum = PerfDataGetProcessCount(); ULONG i = 0; char szProcessName[MAX_PATH + 10] = {0}; char szProcess[MAX_PATH + 10] = {0}; char* pszFindChar = NULL; pszFindChar = strchr(lpImageName,'.'); if(NULL != pszFindChar) { *pszFindChar = NULL; lstrcpy(szProcess,lpImageName); *pszFindChar = '.'; } for(i = 0; i < iNum; ++i) { memset(szProcessName,NULL,(MAX_PATH + 10)); PerfDataGetImageName(i,szProcessName,MAX_PATH); if(0 == lstrcmpi(lpImageName,szProcessName)) { plProcId[iProcCount] = PerfDataGetProcessId(i); plCPUUsage[iProcCount] = PerfDataGetCPUUsage(i); plMemoryUsage[iProcCount] = PerfDataGetWorkingSetSizeBytes(i); ++iProcCount; } else { if(NULL != szProcess[0]) { if(0 == lstrcmpi(szProcess,szProcessName)) { plProcId[iProcCount] = PerfDataGetProcessId(i); plCPUUsage[iProcCount] = PerfDataGetCPUUsage(i); plMemoryUsage[iProcCount] = PerfDataGetWorkingSetSizeBytes(i); ++iProcCount; } else { pszFindChar = strchr(szProcessName,'.'); if(NULL != pszFindChar) { *pszFindChar = NULL; if(0 == lstrcmpi(szProcess,szProcessName)) { plProcId[iProcCount] = PerfDataGetProcessId(i); plCPUUsage[iProcCount] = PerfDataGetCPUUsage(i); plMemoryUsage[iProcCount] = PerfDataGetWorkingSetSizeBytes(i); ++iProcCount; } } } } } } } catch(...) { } return iProcCount; }
static DWORD WINAPI PerformancePageRefreshThread(void *lpParameter) { ULONG CommitChargeTotal; ULONG CommitChargeLimit; ULONG CommitChargePeak; ULONG KernelMemoryTotal; ULONG KernelMemoryPaged; ULONG KernelMemoryNonPaged; ULONG PhysicalMemoryTotal; ULONG PhysicalMemoryAvailable; ULONG PhysicalMemorySystemCache; ULONG TotalHandles; ULONG TotalThreads; ULONG TotalProcesses; TCHAR Text[260]; /* Create the event */ hPerformancePageEvent = CreateEvent(NULL, TRUE, TRUE, NULL); /* If we couldn't create the event then exit the thread */ if (!hPerformancePageEvent) return 0; while (1) { DWORD dwWaitVal; /* Wait on the event */ dwWaitVal = WaitForSingleObject(hPerformancePageEvent, INFINITE); /* If the wait failed then the event object must have been */ /* closed and the task manager is exiting so exit this thread */ if (dwWaitVal == WAIT_FAILED) return 0; if (dwWaitVal == WAIT_OBJECT_0) { ULONG CpuUsage; ULONG CpuKernelUsage; int nBarsUsed1; int nBarsUsed2; /* Reset our event */ ResetEvent(hPerformancePageEvent); /* * Update the commit charge info */ CommitChargeTotal = PerfDataGetCommitChargeTotalK(); CommitChargeLimit = PerfDataGetCommitChargeLimitK(); CommitChargePeak = PerfDataGetCommitChargePeakK(); _ultoa(CommitChargeTotal, Text, 10); SetWindowText(hPerformancePageCommitChargeTotalEdit, Text); _ultoa(CommitChargeLimit, Text, 10); SetWindowText(hPerformancePageCommitChargeLimitEdit, Text); _ultoa(CommitChargePeak, Text, 10); SetWindowText(hPerformancePageCommitChargePeakEdit, Text); wsprintf(Text, _T("Mem Usage: %dK / %dK"), CommitChargeTotal, CommitChargeLimit); SendMessage(hStatusWnd, SB_SETTEXT, 2, (LPARAM)Text); /* * Update the kernel memory info */ KernelMemoryTotal = PerfDataGetKernelMemoryTotalK(); KernelMemoryPaged = PerfDataGetKernelMemoryPagedK(); KernelMemoryNonPaged = PerfDataGetKernelMemoryNonPagedK(); _ultoa(KernelMemoryTotal, Text, 10); SetWindowText(hPerformancePageKernelMemoryTotalEdit, Text); _ultoa(KernelMemoryPaged, Text, 10); SetWindowText(hPerformancePageKernelMemoryPagedEdit, Text); _ultoa(KernelMemoryNonPaged, Text, 10); SetWindowText(hPerformancePageKernelMemoryNonPagedEdit, Text); /* * Update the physical memory info */ PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK(); PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK(); PhysicalMemorySystemCache = PerfDataGetPhysicalMemorySystemCacheK(); _ultoa(PhysicalMemoryTotal, Text, 10); SetWindowText(hPerformancePagePhysicalMemoryTotalEdit, Text); _ultoa(PhysicalMemoryAvailable, Text, 10); SetWindowText(hPerformancePagePhysicalMemoryAvailableEdit, Text); _ultoa(PhysicalMemorySystemCache, Text, 10); SetWindowText(hPerformancePagePhysicalMemorySystemCacheEdit, Text); /* * Update the totals info */ TotalHandles = PerfDataGetSystemHandleCount(); TotalThreads = PerfDataGetTotalThreadCount(); TotalProcesses = PerfDataGetProcessCount(); _ultoa(TotalHandles, Text, 10); SetWindowText(hPerformancePageTotalsHandleCountEdit, Text); _ultoa(TotalThreads, Text, 10); SetWindowText(hPerformancePageTotalsThreadCountEdit, Text); _ultoa(TotalProcesses, Text, 10); SetWindowText(hPerformancePageTotalsProcessCountEdit, Text); /* * Redraw the graphs */ InvalidateRect(hPerformancePageCpuUsageGraph, NULL, FALSE); InvalidateRect(hPerformancePageMemUsageGraph, NULL, FALSE); /* * Get the CPU usage */ CpuUsage = PerfDataGetProcessorUsage(); CpuKernelUsage = PerfDataGetProcessorSystemUsage(); /* * Get the memory usage */ CommitChargeTotal = (ULONGLONG)PerfDataGetCommitChargeTotalK(); CommitChargeLimit = (ULONGLONG)PerfDataGetCommitChargeLimitK(); nBarsUsed1 = CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0; PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK(); PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK(); nBarsUsed2 = PhysicalMemoryTotal ? ((PhysicalMemoryAvailable * 100) / PhysicalMemoryTotal) : 0; GraphCtrl_AppendPoint(&PerformancePageCpuUsageHistoryGraph, CpuUsage, CpuKernelUsage, 0.0, 0.0); GraphCtrl_AppendPoint(&PerformancePageMemUsageHistoryGraph, nBarsUsed1, nBarsUsed2, 0.0, 0.0); /* PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ; */ InvalidateRect(hPerformancePageMemUsageHistoryGraph, NULL, FALSE); InvalidateRect(hPerformancePageCpuUsageHistoryGraph, NULL, FALSE); } } return 0; }
DWORD WINAPI PerformancePageRefreshThread(void *lpParameter) { ULONGLONG CommitChargeTotal; ULONGLONG CommitChargeLimit; ULONGLONG CommitChargePeak; ULONG CpuUsage; ULONG CpuKernelUsage; ULONGLONG KernelMemoryTotal; ULONGLONG KernelMemoryPaged; ULONGLONG KernelMemoryNonPaged; ULONGLONG PhysicalMemoryTotal; ULONGLONG PhysicalMemoryAvailable; ULONGLONG PhysicalMemorySystemCache; ULONG TotalHandles; ULONG TotalThreads; ULONG TotalProcesses; WCHAR Text[260]; WCHAR szMemUsage[256]; MSG msg; LoadStringW(hInst, IDS_STATUS_MEMUSAGE, szMemUsage, 256); while (1) { int nBarsUsed1; int nBarsUsed2; WCHAR szChargeTotalFormat[256]; WCHAR szChargeLimitFormat[256]; /* Wait for an the event or application close */ if (GetMessage(&msg, NULL, 0, 0) <= 0) return 0; if (msg.message == WM_TIMER) { /* * Update the commit charge info */ CommitChargeTotal = PerfDataGetCommitChargeTotalK(); CommitChargeLimit = PerfDataGetCommitChargeLimitK(); CommitChargePeak = PerfDataGetCommitChargePeakK(); _ultow(CommitChargeTotal, Text, 10); SetWindowTextW(hPerformancePageCommitChargeTotalEdit, Text); _ultow(CommitChargeLimit, Text, 10); SetWindowTextW(hPerformancePageCommitChargeLimitEdit, Text); _ultow(CommitChargePeak, Text, 10); SetWindowTextW(hPerformancePageCommitChargePeakEdit, Text); StrFormatByteSizeW(CommitChargeTotal * 1024, szChargeTotalFormat, sizeof(szChargeTotalFormat)); StrFormatByteSizeW(CommitChargeLimit * 1024, szChargeLimitFormat, sizeof(szChargeLimitFormat)); wsprintfW(Text, szMemUsage, szChargeTotalFormat, szChargeLimitFormat, (CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0)); SendMessageW(hStatusWnd, SB_SETTEXT, 2, (LPARAM)Text); /* * Update the kernel memory info */ KernelMemoryTotal = PerfDataGetKernelMemoryTotalK(); KernelMemoryPaged = PerfDataGetKernelMemoryPagedK(); KernelMemoryNonPaged = PerfDataGetKernelMemoryNonPagedK(); _ultow(KernelMemoryTotal, Text, 10); SetWindowTextW(hPerformancePageKernelMemoryTotalEdit, Text); _ultow(KernelMemoryPaged, Text, 10); SetWindowTextW(hPerformancePageKernelMemoryPagedEdit, Text); _ultow(KernelMemoryNonPaged, Text, 10); SetWindowTextW(hPerformancePageKernelMemoryNonPagedEdit, Text); /* * Update the physical memory info */ PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK(); PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK(); PhysicalMemorySystemCache = PerfDataGetPhysicalMemorySystemCacheK(); _ultow(PhysicalMemoryTotal, Text, 10); SetWindowTextW(hPerformancePagePhysicalMemoryTotalEdit, Text); _ultow(PhysicalMemoryAvailable, Text, 10); SetWindowTextW(hPerformancePagePhysicalMemoryAvailableEdit, Text); _ultow(PhysicalMemorySystemCache, Text, 10); SetWindowTextW(hPerformancePagePhysicalMemorySystemCacheEdit, Text); /* * Update the totals info */ TotalHandles = PerfDataGetSystemHandleCount(); TotalThreads = PerfDataGetTotalThreadCount(); TotalProcesses = PerfDataGetProcessCount(); _ultow(TotalHandles, Text, 10); SetWindowTextW(hPerformancePageTotalsHandleCountEdit, Text); _ultow(TotalThreads, Text, 10); SetWindowTextW(hPerformancePageTotalsThreadCountEdit, Text); _ultow(TotalProcesses, Text, 10); SetWindowTextW(hPerformancePageTotalsProcessCountEdit, Text); /* * Redraw the graphs */ InvalidateRect(hPerformancePageCpuUsageGraph, NULL, FALSE); InvalidateRect(hPerformancePageMemUsageGraph, NULL, FALSE); /* * Get the CPU usage */ CpuUsage = PerfDataGetProcessorUsage(); if (CpuUsage <= 0 ) CpuUsage = 0; if (CpuUsage > 100) CpuUsage = 100; if (TaskManagerSettings.ShowKernelTimes) { CpuKernelUsage = PerfDataGetProcessorSystemUsage(); if (CpuKernelUsage <= 0) CpuKernelUsage = 0; if (CpuKernelUsage > 100) CpuKernelUsage = 100; } else { CpuKernelUsage = 0; } /* * Get the memory usage */ CommitChargeTotal = PerfDataGetCommitChargeTotalK(); CommitChargeLimit = PerfDataGetCommitChargeLimitK(); nBarsUsed1 = CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0; PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK(); PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK(); nBarsUsed2 = PhysicalMemoryTotal ? ((PhysicalMemoryAvailable * 100) / PhysicalMemoryTotal) : 0; GraphCtrl_AppendPoint(&PerformancePageCpuUsageHistoryGraph, CpuUsage, CpuKernelUsage, 0.0, 0.0); GraphCtrl_AppendPoint(&PerformancePageMemUsageHistoryGraph, nBarsUsed1, nBarsUsed2, 0.0, 0.0); /* PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ; */ InvalidateRect(hPerformancePageMemUsageHistoryGraph, NULL, FALSE); InvalidateRect(hPerformancePageCpuUsageHistoryGraph, NULL, FALSE); } } return 0; }
static DWORD WINAPI PerformancePageRefreshThread(void *lpParameter) { ULONG CommitChargeTotal; ULONG CommitChargeLimit; ULONG CommitChargePeak; ULONG KernelMemoryTotal; ULONG KernelMemoryPaged; ULONG KernelMemoryNonPaged; ULONG PhysicalMemoryTotal; ULONG PhysicalMemoryAvailable; ULONG PhysicalMemorySystemCache; ULONG TotalHandles; ULONG TotalThreads; ULONG TotalProcesses; WCHAR Text[256]; static const WCHAR wszFormatDigit[] = {'%','u',0}; WCHAR wszMemUsage[255]; LoadStringW(hInst, IDS_STATUS_BAR_MEMORY_USAGE, wszMemUsage, sizeof(wszMemUsage)/sizeof(WCHAR)); /* Create the event */ hPerformancePageEvent = CreateEventW(NULL, TRUE, TRUE, NULL); /* If we couldn't create the event then exit the thread */ if (!hPerformancePageEvent) return 0; while (1) { DWORD dwWaitVal; /* Wait on the event */ dwWaitVal = WaitForSingleObject(hPerformancePageEvent, INFINITE); /* If the wait failed then the event object must have been */ /* closed and the task manager is exiting so exit this thread */ if (dwWaitVal == WAIT_FAILED) return 0; if (dwWaitVal == WAIT_OBJECT_0) { ULONG CpuUsage; ULONG CpuKernelUsage; int nBarsUsed1, nBarsUsed2; DWORD_PTR args[2]; /* Reset our event */ ResetEvent(hPerformancePageEvent); /* * Update the commit charge info */ CommitChargeTotal = PerfDataGetCommitChargeTotalK(); CommitChargeLimit = PerfDataGetCommitChargeLimitK(); CommitChargePeak = PerfDataGetCommitChargePeakK(); wsprintfW(Text, wszFormatDigit, CommitChargeTotal); SetWindowTextW(hPerformancePageCommitChargeTotalEdit, Text); wsprintfW(Text, wszFormatDigit, CommitChargeLimit); SetWindowTextW(hPerformancePageCommitChargeLimitEdit, Text); wsprintfW(Text, wszFormatDigit, CommitChargePeak); SetWindowTextW(hPerformancePageCommitChargePeakEdit, Text); args[0] = CommitChargeTotal; args[1] = CommitChargeLimit; FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY, wszMemUsage, 0, 0, Text, sizeof(Text)/sizeof(*Text), (__ms_va_list*)args); SendMessageW(hStatusWnd, SB_SETTEXTW, 2, (LPARAM)Text); /* * Update the kernel memory info */ KernelMemoryTotal = PerfDataGetKernelMemoryTotalK(); KernelMemoryPaged = PerfDataGetKernelMemoryPagedK(); KernelMemoryNonPaged = PerfDataGetKernelMemoryNonPagedK(); wsprintfW(Text, wszFormatDigit, KernelMemoryTotal); SetWindowTextW(hPerformancePageKernelMemoryTotalEdit, Text); wsprintfW(Text, wszFormatDigit, KernelMemoryPaged); SetWindowTextW(hPerformancePageKernelMemoryPagedEdit, Text); wsprintfW(Text, wszFormatDigit, KernelMemoryNonPaged); SetWindowTextW(hPerformancePageKernelMemoryNonPagedEdit, Text); /* * Update the physical memory info */ PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK(); PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK(); PhysicalMemorySystemCache = PerfDataGetPhysicalMemorySystemCacheK(); wsprintfW(Text, wszFormatDigit, PhysicalMemoryTotal); SetWindowTextW(hPerformancePagePhysicalMemoryTotalEdit, Text); wsprintfW(Text, wszFormatDigit, PhysicalMemoryAvailable); SetWindowTextW(hPerformancePagePhysicalMemoryAvailableEdit, Text); wsprintfW(Text, wszFormatDigit, PhysicalMemorySystemCache); SetWindowTextW(hPerformancePagePhysicalMemorySystemCacheEdit, Text); /* * Update the totals info */ TotalHandles = PerfDataGetSystemHandleCount(); TotalThreads = PerfDataGetTotalThreadCount(); TotalProcesses = PerfDataGetProcessCount(); wsprintfW(Text, wszFormatDigit, TotalHandles); SetWindowTextW(hPerformancePageTotalsHandleCountEdit, Text); wsprintfW(Text, wszFormatDigit, TotalThreads); SetWindowTextW(hPerformancePageTotalsThreadCountEdit, Text); wsprintfW(Text, wszFormatDigit, TotalProcesses); SetWindowTextW(hPerformancePageTotalsProcessCountEdit, Text); /* * Redraw the graphs */ InvalidateRect(hPerformancePageCpuUsageGraph, NULL, FALSE); InvalidateRect(hPerformancePageMemUsageGraph, NULL, FALSE); /* * Get the CPU usage */ CpuUsage = PerfDataGetProcessorUsage(); CpuKernelUsage = PerfDataGetProcessorSystemUsage(); /* * Get the memory usage */ CommitChargeTotal = (ULONGLONG)PerfDataGetCommitChargeTotalK(); CommitChargeLimit = (ULONGLONG)PerfDataGetCommitChargeLimitK(); nBarsUsed1 = CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0; PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK(); PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK(); nBarsUsed2 = PhysicalMemoryTotal ? ((PhysicalMemoryAvailable * 100) / PhysicalMemoryTotal) : 0; GraphCtrl_AppendPoint(&PerformancePageCpuUsageHistoryGraph, CpuUsage, CpuKernelUsage, 0.0, 0.0); GraphCtrl_AppendPoint(&PerformancePageMemUsageHistoryGraph, nBarsUsed1, nBarsUsed2, 0.0, 0.0); /* PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ; */ InvalidateRect(hPerformancePageMemUsageHistoryGraph, NULL, FALSE); InvalidateRect(hPerformancePageCpuUsageHistoryGraph, NULL, FALSE); } } return 0; }