How to get the amount of memory used by an application?

Ask general questions here.
User avatar
CARAT
Posts: 2
Joined: Mon Mar 27, 2017 1:55 pm

How to get the amount of memory used by an application?

Post by CARAT » Wed Mar 17, 2021 1:02 pm

Hi,
we try this:
how-to-get-the-amount-of-memory-used-by ... t1559.html

But error is shown:
Der Index war außerhalb des Arraybereichs.

The EXE / AUT is running but this code does not work?
System.Diagnostics.Process[] proc = System.Diagnostics.Process.GetProcessesByName("aut.exe");
Console.WriteLine("Memory used: {0}.", proc[0].PrivateMemorySize.ToString());

User avatar
Mike K
Certified Professional
Certified Professional
Posts: 28
Joined: Wed Jun 28, 2017 5:58 pm

Re: How to get the amount of memory used by an application?

Post by Mike K » Fri Mar 19, 2021 12:07 pm

Hi,

This is generally outside the scope of Ranorex since you are writing custom code and not targeting the Ranorex API. One approach would be to record steps to open Task Manager and grab memory information this way. I tried different code and got it to work. Make sure to only use the name of the AUT and not AUT.exe.

double f = 1024.0;
System.Diagnostics.Process[] localByName = System.Diagnostics.Process.GetProcessesByName("aut");
foreach (System.Diagnostics.Process p in localByName)
{
Report.Info("Private memory size64: {0}", (p.PrivateMemorySize64 / f).ToString("#,##0"));
Report.Info("Working Set size64: {0}", (p.WorkingSet64/f).ToString("#,##0"));
Report.Info("Peak virtual memory size64: {0}", (p.PeakVirtualMemorySize64 / f).ToString("#,##0"));
Report.Info("Peak paged memory size64: {0}", (p.PeakPagedMemorySize64 / f).ToString("#,##0"));
Report.Info("Paged system memory size64: {0}", (p.PagedSystemMemorySize64 / f).ToString("#,##0"));
Report.Info("Paged memory size64: {0}", (p.PagedMemorySize64 / f).ToString("#,##0"));
Report.Info("Nonpaged system memory size64: {0}", (p.NonpagedSystemMemorySize64 / f).ToString("#,##0"));
}
Last edited by Mike K on Mon Mar 22, 2021 8:49 pm, edited 1 time in total.

User avatar
CARAT
Posts: 2
Joined: Mon Mar 27, 2017 1:55 pm

Re: How to get the amount of memory used by an application?

Post by CARAT » Fri Mar 19, 2021 12:28 pm

Hi,
thank you for your advice.
We will check this.

Note:
Taskmanager is lying - VMMap is the truth.
https://docs.microsoft.com/en-us/sysint ... oads/vmmap