Hi Chris,
You can get the private working set using WMI classes, namely, Win32_PerfRawData_PerfProc_Process.WorkingSetPrivate.
function TestGetPrivateWorkingSet()
{
Log.Message("Notepad's private working set: " + GetPrivateWorkingSet("NOTEPAD") + " bytes");
}
// Returns the private working set, in bytes, of the specified process.
// Parameter:
// ProcessName - the process name without the extension (case-insensitive). E.g. "notepad".
function GetPrivateWorkingSet(ProcessName)
{
var oWMI = GetObject("winmgmts:");
var oPerfData = oWMI.Get("Win32_PerfRawData_PerfProc_Process.Name='" + ProcessName + "'");
return oPerfData.WorkingSetPrivate;
}
If you need to query memory several times throughout your test, you can use the following code with a
WMI refresher. This should work faster than calling GetObject("winmgmts:") multiple times:
function Test()
{
InitCounters("notepad");
// Do something
Log.Message(GetPrivateWorkingSet());
// Do something else
Log.Message(GetPrivateWorkingSet());
}
var oCounter;
function InitCounters(ProcessName)
{
var oRefresher = new ActiveXObject("WbemScripting.SWbemRefresher");
var oWMI = GetObject("winmgmts:");
oCounter = oRefresher.Add(oWMI, "Win32_PerfRawData_PerfProc_Process.Name='" + ProcessName + "'");
}
function GetPrivateWorkingSet()
{
oCounter.Refresher.Refresh();
return oCounter.Object.WorkingSetPrivate;
}