PHenningsen
asked on
Monitor Memory Usage of my own Process
How do I Monitor Memory Usage of my own Process?
I'm interested in things like Virtual Memory (Current & Peak) and Working Set Size (Current & Peak). All the sort of things that TaskManager shows. Only just for my own process.
I'm interested in things like Virtual Memory (Current & Peak) and Working Set Size (Current & Peak). All the sort of things that TaskManager shows. Only just for my own process.
Also, you may want to look into the GetHeapStatus function (used in the GetCurrentSize function). This returns a structure detailing current memory usage for the delphi process.
type
THeapStatus = record
TotalAddrSpace: Cardinal;s
TotalUncommitted: Cardinal;
TotalCommitted: Cardinal;
TotalAllocated: Cardinal;
TotalFree: Cardinal;
FreeSmall: Cardinal;
FreeBig: Cardinal;
Unused: Cardinal;
Overhead: Cardinal;
HeapErrorCode: Cardinal;
end;
Also, there is AllocMemCount/AllocMemSize that can return the number of allocated memory blocks, and the size of the allocated memory blocks (respectively)
Russell
type
THeapStatus = record
TotalAddrSpace: Cardinal;s
TotalUncommitted: Cardinal;
TotalCommitted: Cardinal;
TotalAllocated: Cardinal;
TotalFree: Cardinal;
FreeSmall: Cardinal;
FreeBig: Cardinal;
Unused: Cardinal;
Overhead: Cardinal;
HeapErrorCode: Cardinal;
end;
Also, there is AllocMemCount/AllocMemSize
Russell
ASKER
As I understand it, Min & Max Working Set Size are "desired" limits. I'd like to find Current & Peak Working Set Size. I believe that it is these two values that Task Manager calls "Mem Usage"
I'll have to experiment with the numbers from THeapStatus. Delphi's help info did not clarify it.
AllocMemSize does not measure Current Working Set Size
I'll have to experiment with the numbers from THeapStatus. Delphi's help info did not clarify it.
AllocMemSize does not measure Current Working Set Size
My misunderstanding on what you were after....
Check GetProcessMemoryInfo which is available from the psapi.pas unit. The GetProcessMemoryInfo function will return the following information in a record structure.
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;
This will return the peak and current working set size for the process. If you need an example of usage, just ask.
Regards,
Russell
ASKER
I would love an example. Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much!
My EE-display has changed like to "inquiry only" and I can't find the "Accept" button.
I'll try harder in a few minutes...
My EE-display has changed like to "inquiry only" and I can't find the "Accept" button.
I'll try harder in a few minutes...
Here are some functions that should give you what you are after:
// Get minimum working set size
function GetMinWorkingSetSize: DWORD;
var dwTemp: DWORD;
begin
if not(GetProcessWorkingSetSi
end;
// Get maximum working set size
function GetMaxWorkingSetSize: DWORD;
var dwTemp: DWORD;
begin
if not(GetProcessWorkingSetSi
end;
// Get number of bytes allocated for delphi's heap manager
function GetCurrentSetSize: DWORD;
var lpHeapStatus: THeapStatus;
begin
lpHeapStatus:=GetHeapStatu
result:=lpHeapStatus.Total
end;
procedure TForm1.Button1Click(Sender
begin
ShowMessage(IntToStr(GetMi
ShowMessage(IntToStr(GetMa
ShowMessage(IntToStr(GetCu
end;
Regards,
Russell