15,473
社区成员




void CKIS1Dlg::MyRecycleRecord()
{
HANDLE handle = GetCurrentProcess();
if(handle)
{
PROCESS_MEMORY_COUNTERS pmc;
GetProcessMemoryInfo(handle,&pmc,sizeof(pmc));
TRACE1("Process cost %dk",pmc.WorkingSetSize/1000);
}
else
TRACE1("Failed to get process handle with err %d\n",GetLastError());
}
#include <psapi.h>
#pragma comment(lib, "psapi.lib")
void CDlg1Dlg::OnTimer(UINT_PTR nIDEvent)
{
HANDLE hProcess = GetCurrentProcess();
PROCESS_MEMORY_COUNTERS pmc = {0};
pmc.cb = sizeof(pmc);
if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) )
{
TRACE( _T("\n") );
TRACE( _T("\tPageFaultCount: %.3fK\n"), pmc.PageFaultCount/1024.0 );
TRACE( _T("\tPeakWorkingSetSize: %.3fK\n"), pmc.PeakWorkingSetSize/1024.0 );
TRACE( _T("\tWorkingSetSize: %.3fK\n"), pmc.WorkingSetSize/1024.0 );
TRACE( _T("\tQuotaPeakPagedPoolUsage: %.3fK\n"), pmc.QuotaPeakPagedPoolUsage/1024.0 );
TRACE( _T("\tQuotaPagedPoolUsage: %.3fK\n"), pmc.QuotaPagedPoolUsage/1024.0 );
TRACE( _T("\tQuotaPeakNonPagedPoolUsage: %.3fK\n"), pmc.QuotaPeakNonPagedPoolUsage/1024.0 );
TRACE( _T("\tQuotaNonPagedPoolUsage: %.3fK\n"), pmc.QuotaNonPagedPoolUsage/1024.0 );
TRACE( _T("\tPagefileUsage: %.3fK\n"), pmc.PagefileUsage/1024.0 );
TRACE( _T("\tPeakPagefileUsage: %.3fK\n"), pmc.PeakPagefileUsage/1024.0 );
}
}
//MSDN注解//
/*
typedef struct _SYSTEM_PROCESS_INFORMATION {
ULONG NextEntryOffset;
ULONG NumberOfThreads;
BYTE Reserved1[48];
PVOID Reserved2[3];
HANDLE UniqueProcessId;
PVOID Reserved3;
ULONG HandleCount;
BYTE Reserved4[4];
PVOID Reserved5[11];
SIZE_T PeakPagefileUsage;
SIZE_T PrivatePageCount;
LARGE_INTEGER Reserved6[6];
} SYSTEM_PROCESS_INFORMATION;
The NumberOfThreads member contains the total number of currently running threads in the process.
The HandleCount member contains the total number of handles being used by the process in question; use GetProcessHandleCount to retrieve this information instead.
The PeakPagefileUsage member contains the maximum number of bytes of page-file storage used by the process, and the PrivatePageCount member contains the number of memory pages allocated for the use of this process.
You can also retrieve this information using either the GetProcessMemoryInfo function or the Win32_Process class.
The other members of the structure are reserved for internal use by the operating system.
*/
PSYSTEM_PROCESS_INFORMATION pSS = new SYSTEM_PROCESS_INFORMATION[30000];
ZeroMemory(pSS,sizeof(SYSTEM_PROCESS_INFORMATION)*30000);
DWORD len3 = 0;
DWORD ret = NtmyQ(SystemProcessInformation,pSS,sizeof(SYSTEM_PROCESS_INFORMATION)*30000,&len3);
len3 = len3/sizeof(SYSTEM_PROCESS_INFORMATION);
double vv = 0;
for(int i=0;i<len3;i++)
{
vv = double(pSS[i].PeakPagefileUsage)/1024/1024;
if(vv<0.02)
continue;
TRACE2("PID %d --> Memory %.2lfMB\n",pSS[i].UniqueProcessId,vv);
}
hNtDll = LoadLibrary(L"NtDll.dll");
NtmyQ = (pNTFunc)GetProcAddress(hNtDll,"NtQuerySystemInformation");
SYSTEM_PROCESS_INFORMATION mDB[100];
ZeroMemory(mDB,sizeof(SYSTEM_PROCESS_INFORMATION)*100);
DWORD len3 = 0;
NTSTATUS ret = NtmyQ(SystemProcessInformation,mDB,sizeof(SYSTEM_PROCESS_INFORMATION)*100,&len3);