Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For future users, here is what I had to do to make sure to get the Private Working Set for processes that might have multiple instances. I call <code>CurrentMemoryUsage</code>, which gets the appropriate process name from <code>GetNameToUseForMemory</code>. I found this loop to be slow, even with filtering down the results where I could. So, that is why you see <code>GetNameToUseForMemory</code> using a dictionary for caching the name.</p> <pre><code>private static long CurrentMemoryUsage(Process proc) { long currentMemoryUsage; var nameToUseForMemory = GetNameToUseForMemory(proc); using (var procPerfCounter = new PerformanceCounter("Process", "Working Set - Private", nameToUseForMemory)) { //KB is standard currentMemoryUsage = procPerfCounter.RawValue/1024; } return currentMemoryUsage; } private static string GetNameToUseForMemory(Process proc) { if (processId2MemoryProcessName.ContainsKey(proc.Id)) return processId2MemoryProcessName[proc.Id]; var nameToUseForMemory = String.Empty; var category = new PerformanceCounterCategory("Process"); var instanceNames = category.GetInstanceNames().Where(x =&gt; x.Contains(proc.ProcessName)); foreach (var instanceName in instanceNames) { using (var performanceCounter = new PerformanceCounter("Process", "ID Process", instanceName, true)) { if (performanceCounter.RawValue != proc.Id) continue; nameToUseForMemory = instanceName; break; } } if(!processId2MemoryProcessName.ContainsKey(proc.Id)) processId2MemoryProcessName.Add(proc.Id, nameToUseForMemory); return nameToUseForMemory; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload