How to create performance counter that can be measured by process/instance?
-
Thursday, October 13, 2011 11:46 AM
Hi,
This is an x-post and I will update both in case of replies.I can't quite see how I can create a counter that measures a number - by process. I'm creating the counters in code usingPerformanceCounterCategory and CounterCreationData. This works and I'm adding a single "NumberOfItems64" counter.
But I can't measure this counter by process/instance. I'm only able to measure that number as a whole on my PC. How can I create the counter to give my per process counter?
Edit: No-one running terminal server with mulitple instances of your software? I have tried to set the "PerformanceCounterCategoryType.MultiInstance" type when creating the category but with the same results. I can't choose specific process/instance when adding the counter in Perfmon.
--
Werner- Edited by Werner Clausen Friday, October 14, 2011 11:59 AM
All Replies
-
Thursday, October 13, 2011 9:28 AM
Hi,
This is an x-post and I will update both in case of replies.
I can't quite see how I can create a counter that measures a number - by process. I'm creating the counters in code using PerformanceCounterCategory and CounterCreationData. This works and I'm adding a single "NumberOfItems64" counter.
But I can't measure this counter by process/instance. I'm only able to measure that number as a whole on my PC. How can I create the counter to give my per process counter?
Edit: No-one running terminal server with mulitple instances of your software? I have tried to set the "PerformanceCounterCategoryType.MultiInstance" type when creating the category but with the same results. I can't choose specific process/instance when adding the counter in Perfmon.
--
Werner
- Edited by Werner Clausen Thursday, October 13, 2011 10:09 AM
- Edited by Werner Clausen Thursday, October 13, 2011 11:46 AM
- Edited by Werner Clausen Friday, October 14, 2011 12:00 PM
- Merged by Yoyo JiangMicrosoft Contingent Staff Monday, October 17, 2011 7:32 AM
-
Monday, October 17, 2011 5:06 AM
Hi Werner,
Welcome to the MSDN forum!There is a project demonstrating how to use PerformanceCounter to get the CPU Usage of the following features:
1. The Total Processor Time.
2. The Processor time of a specific process.
3. Draw the CPU Usage History like Task Manager.Please go to the following link to get more details about it:
Track the system CPU usage (CSCpuUsage)
http://code.msdn.microsoft.com/CSCpuUsage-f009d9c1Meanwhile, there is another link for you to check out:
PerformanceCounters: single instance, multi-instance and WMI [David Gutierrez]
http://blogs.msdn.com/b/bclteam/archive/2004/10/29/249799.aspxHave a nice day!
Yoyo.
Yoyo Jiang[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

- Edited by Yoyo JiangMicrosoft Contingent Staff Monday, October 17, 2011 5:10 AM
-
Monday, October 17, 2011 7:33 AM
Hi Werner,
I am merging the threads to keep into the same topic for good discussion.Thank you for your understanding and have a nice day!
Yoyo.
Yoyo Jiang[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

- Edited by Yoyo JiangMicrosoft Contingent Staff Monday, October 17, 2011 7:33 AM
-
Monday, October 17, 2011 7:52 AM
Hi Yoyo,
Thanks for your reply. But I know all about consuming the system counters. My trouble is that I can't make my own counters apply for a specific process. Take the "CPU usage" counter for example. As you say, it is possible to specify what process the counter applies for. I need my own counter to give the same possibilities. But no matter how I create my counter is is not possible to select a specific process to monitor.
Hope it is clear what i'm trying to achieve :)
--
Werner -
Monday, October 17, 2011 9:17 AM
Got it:
- The Category must be created with "PerformanceCounterCategoryType = MultiInstance".
- The Counter must be created with "InstanceLifetime = PerformanceCounterInstanceLifetime.Process"
Then I'm able to select the process in Perfmon. I could have sworn that I have tried this combination, but today it works :)
--
Werner
- Edited by Werner Clausen Monday, October 17, 2011 9:18 AM
- Edited by Werner Clausen Monday, October 17, 2011 9:18 AM
- Marked As Answer by Paul ZhouModerator Monday, October 24, 2011 7:52 AM
-
Monday, October 17, 2011 9:58 AMCongratulations!
Yoyo Jiang[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.


