Bug 7323 - System.Diagnostics.PerformanceCounterCategory Exception while accessing user defined performanceCounters
Summary: System.Diagnostics.PerformanceCounterCategory Exception while accessing user ...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-09-20 05:54 UTC by Herwig
Modified: 2012-09-20 05:55 UTC (History)
2 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:

source code and sample output of execution in windows and linux (6.76 KB, application/zip)
2012-09-20 05:54 UTC, Herwig

Description Herwig 2012-09-20 05:54:57 UTC
Created attachment 2578 [details]
source code and sample output of execution in windows and linux

I wrote a code that lists all performanceCounters for a specific category and displays their results.

This works fine for all pre-defined PerformanceCounterCategories.
With user-defined counter categories, this does not work.

In the attachment you find a modified version of the code from:

(Here you can also see the bug that was reported with ID 7322, I wrote two reports as I think that they are different)

part of code:
SetupCategory(categoryName);  //creates a new category
CreateCounters(categoryName); //creates counters for the new category
CollectSamples(samplesList);  //stores values to the counters
CalculateResults(samplesList);  //calculates results - bug-id7322
printCountersForCategory(categoryName);  //see description 1
printCountersForCategoryPerNames(categoryName, new string[]{"AverageCounter64Sample", "AverageCounter64SampleBase"});

The two methods "printCountersForCategory" and "printCountersForCategoryPerNames"
both try to print all counters for a specific category.  In the first case, the Method
PerformanceCounterCategory.GetCounters(...) is used.  This throws an exception in (I guess line 109 of https://github.com/mono/mono/blob/fe8bdbcef723fc8c92afcc822aa4c12e34c21c0b/mcs/class/System/System.Diagnostics/PerformanceCounter.cs)
This problem seams to be caused by (I guess line 256 of https://github.com/mono/mono/blob/fe8bdbcef723fc8c92afcc822aa4c12e34c21c0b/mcs/class/System/System.Diagnostics/PerformanceCounterCategory.cs).
The method GetCounterNames seams to return at least one value "" -> which then throws the exception as described above.

If the names are known, the performanceCounters can be accessed as wished (showed in "printCountersForCategoryPerNames").

by the way, PerformanceCounter.RemoveInstance throws an notImplementedException. It would be good if at least the comment could state why this method is not important or why it is not implemented yet.

Note You need to log in before you can comment on or make changes to this bug.