Jump to content

Process Memory Counter


nashie

Recommended Posts

Okay, firstly I'm not a coder! So why am I in this forum you may ask?

Well, I need an app that will calculate how much memory a particular application is using (such as pslist.exe etc.) when running in volatile memory.

I have looked all over the place and found some C# code which I tried in vain to compile only to receive millions (okay 10) errors.

I'm not expecting anyone to write it for me but just to point me in the right direction please.

Any ideas on the subject would be gratefully received.

Apologies if I shouldn't be asking this of you...

Thanks in advance.

Link to comment
Share on other sites

Task manager can show you how much memory a proccess is using.

Thanks SomethingToChatWith. I did consider this but as I need to test memory usage by pslist, tlist and a host of other apps, either they simply don't show up in process manager or appear so quicly, I can't screen print the details which I need for a paper. I am using XP rather than Vista. The latter shows much more in Task Manager but again it is not always possible to capture the data.

I have code for a Process Memory Counter, but it will not complie correctly and unfortunately I don't know enough to figure out what the problems are.

This is the code I have:

#include <windows.h>

#include <stdio.h>

#include <psapi.h>

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( )

{

// 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 );

return 0;

}

Anyone have any ideas please?

Thanks for looking...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...