码迷,mamicode.com
首页 > 其他好文 > 详细

PROCESS_MEMORY_COUNTERS

时间:2015-01-24 10:09:40      阅读:341      评论:0      收藏:0      [点我收藏+]

标签:

typedef struct _PROCESS_MEMORY_COUNTERS {
  DWORD cb;
  DWORD PageFaultCount;
  SIZE_T PeakWorkingSetSize;           //峰值内存使用
  SIZE_T WorkingSetSize;               //内存使用
  SIZE_T QuotaPeakPagedPoolUsage;
  SIZE_T QuotaPagedPoolUsage;
  SIZE_T QuotaPeakNonPagedPoolUsage;
  SIZE_T QuotaNonPagedPoolUsage;
  SIZE_T PagefileUsage;               //虚拟内存使用
  SIZE_T PeakPagefileUsage;           //峰值虚拟内存使用
} PROCESS_MEMORY_COUNTERS, 
*PPROCESS_MEMORY_COUNTERS;

 以下摘自MSDN

Members

cb
The size of the structure, in bytes.
PageFaultCount The number of page faults.
PeakWorkingSetSize The peak working
set size, in bytes.
WorkingSetSize The current working
set size, in bytes.
QuotaPeakPagedPoolUsage The peak paged pool usage,
in bytes.
QuotaPagedPoolUsage The current paged pool usage,
in bytes.
QuotaPeakNonPagedPoolUsage The peak nonpaged pool usage,
in bytes.
QuotaNonPagedPoolUsage The current nonpaged pool usage,
in bytes.
PagefileUsage The Commit Charge value
in bytes for this process. Commit Charge is the total amount of memory that the memory manager has committed for a running process.
PeakPagefileUsage The peak value
in bytes of the Commit Charge during the lifetime of this process.

Collecting Memory Usage Information For a Process

#include <windows.h>
#include <stdio.h>
#include <psapi.h>

// To ensure correct resolution of symbols, add Psapi.lib to TARGETLIBS
// and compile with -DPSAPI_VERSION=1

void PrintMemoryInfo( DWORD processID )
{
    HANDLE hProcess;
    PROCESS_MEMORY_COUNTERS pmc;

    // Print the process identifier.

    printf( "\nProcess ID: %u\n", processID );

    // Print information about the memory usage of the process.

    hProcess = OpenProcess(  PROCESS_QUERY_INFORMATION |
                                    PROCESS_VM_READ,
                                    FALSE, processID );
    if (NULL == hProcess)
        return;

    if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) )
    {
        printf( "\tPageFaultCount: 0x%08X\n", pmc.PageFaultCount );
        printf( "\tPeakWorkingSetSize: 0x%08X\n", 
                  pmc.PeakWorkingSetSize );
        printf( "\tWorkingSetSize: 0x%08X\n", pmc.WorkingSetSize );
        printf( "\tQuotaPeakPagedPoolUsage: 0x%08X\n", 
                  pmc.QuotaPeakPagedPoolUsage );
        printf( "\tQuotaPagedPoolUsage: 0x%08X\n", 
                  pmc.QuotaPagedPoolUsage );
        printf( "\tQuotaPeakNonPagedPoolUsage: 0x%08X\n", 
                  pmc.QuotaPeakNonPagedPoolUsage );
        printf( "\tQuotaNonPagedPoolUsage: 0x%08X\n", 
                  pmc.QuotaNonPagedPoolUsage );
        printf( "\tPagefileUsage: 0x%08X\n", pmc.PagefileUsage ); 
        printf( "\tPeakPagefileUsage: 0x%08X\n", 
                  pmc.PeakPagefileUsage );
    }

    CloseHandle( hProcess );
}

int main( void )
{
    // Get the list of process identifiers.

    DWORD aProcesses[1024], cbNeeded, cProcesses;
    unsigned int i;

    if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
    {
        return 1;
    }

    // Calculate how many process identifiers were returned.

    cProcesses = cbNeeded / sizeof(DWORD);

    // Print the memory usage for each process

    for ( i = 0; i < cProcesses; i++ )
    {
        PrintMemoryInfo( aProcesses[i] );
    }

    return 0;
}

 

PROCESS_MEMORY_COUNTERS

标签:

原文地址:http://www.cnblogs.com/Lthis/p/4245456.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!