Search code examples
c#processperformancecountersystem.diagnostics

Which PerformanceCounter in "Process" category return memory size for instance of process?


I wrote app that monitors currently running processes.

In the following snippet I get all instances in "Process" category.

   var category = new PerformanceCounterCategory("Process");
   var instanceNames = category.GetInstanceNames();

A little later, I get all categories for single instance. It looks like this.

   var counters = category.GetCounters(instanse);

I see that evry instance in this category contains 28 counters. Below the counters list.

% Processor Time
% User Time
% Privileged Time
Virtual Bytes Peak
Virtual Bytes
Page Faults/sec
Working Set Peak
Working Set
Page File Bytes Peak
Page File Bytes
Private Bytes
Thread Count
Priority Base
Elapsed Time
ID Process
Creating Process ID
Pool Paged Bytes
Pool Nonpaged Bytes
Handle Count
IO Read Operations/sec
IO Write Operations/sec
IO Data Operations/sec
IO Other Operations/sec
IO Read Bytes/sec
IO Write Bytes/sec
IO Data Bytes/sec
IO Other Bytes/sec
Working Set - Private

So question. Which counter provides information about the memory bused by the current instance?
I think it's a simple question, but I can not find an answer. I would be grateful if someone will tell.

If we assume that this "Working Set":

ProcessName: SkypeC2CPNRSvc | ProcessId: 2500 Process:
Group: Process | Process: SkypeC2CPNRSvc | Name: Working Set | Value: 311296

This value is calculated in the following way: prfc.NextValue()/1024
In task manaker for this process i see 316K


Solution

  • "Working Set". "Working Set - Private" and "Private Bytes" are all counters that describe the memory used by the current process.

    You can see this link for a good discussion on the differences:

    What is private bytes, virtual bytes, working set?