Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding the memory usage of a particular application

Status
Not open for further replies.

glathaa

Programmer
Aug 21, 2002
21
0
0
IN
Hi,

I am testing the performance of one of my application. Is there any built-in command line utility available in Windows (98/XP) to find the memory usage of an application? I want to have it in a batch file such that I can automate my testing.

What are the functions in VC++ used to find the CPU usage, memory usage programmatically?

Thanks for responses.

Regards,
Latha
 
Lot of method avalible to find the %CPU& memory useage.
Just find these funtion usage in MSDN. U can get all process counters. Any way u have to use Psapi.dll for this methods.
U can also read cpu/mem infromation form registrey.

If U Need look at the sample code which i have given. if u ahve any query , let me know.

EmptyWorkingSet
EnumDeviceDrivers
EnumPageFiles
EnumProcesses
EnumProcessModules
GetDeviceDriverBaseName
GetDeviceDriverFileName
GetMappedFileName
GetModuleBaseName
GetModuleFileNameEx
GetModuleInformation
GetPerformanceInfo
GetProcessMemoryInfo
GetWsChanges
InitializeProcessForWsWatch
QueryWorkingSet



include <windows.h>
#include <stdio.h>
#include &quot;psapi.h&quot;

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

// Print the process identifier.

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

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

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

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

CloseHandle( hProcess );
}

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

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

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

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



Bye,
VC-Lover

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top