From ee153bd274e112974490423c316898727f274380 Mon Sep 17 00:00:00 2001 From: Dan Moseley Date: Wed, 27 Oct 2021 21:26:39 -0600 Subject: [PATCH 1/3] Better perf ctr detail --- .../src/Resources/Strings.resx | 21 ++++++++----------- .../Diagnostics/PerformanceCounterLib.cs | 16 ++++++++------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/libraries/System.Diagnostics.PerformanceCounter/src/Resources/Strings.resx b/src/libraries/System.Diagnostics.PerformanceCounter/src/Resources/Strings.resx index 369fae29bf743..1a5909f5194cf 100644 --- a/src/libraries/System.Diagnostics.PerformanceCounter/src/Resources/Strings.resx +++ b/src/libraries/System.Diagnostics.PerformanceCounter/src/Resources/Strings.resx @@ -180,10 +180,7 @@ Instance '{0}' does not exist in the specified Category. - Could not Read Category Index: {0}. - - - Category does not exist. + Could not read Category Index '{0}'. The Counter layout for the Category specified is invalid, a counter of the type: AverageCount64, AverageTimer32, CounterMultiTimer, CounterMultiTimerInverse, CounterMultiTimer100Ns, CounterMultiTimer100NsInverse, RawFraction, or SampleFraction has to be immediately followed by any of the base counter types: AverageBase, CounterMultiBase, RawBase or SampleBase. @@ -194,17 +191,17 @@ Help Not Available - - Category {0} does not exist. + + Category '{0}' does not exist. - Counter {0} does not exist. + Counter '{0}' does not exist. Cannot create or delete the Performance Category '{0}' because access is denied. - Invalid value {1} for property {0}. + Invalid value '{1}' for property '{0}'. Category name property has not been set. @@ -228,7 +225,7 @@ Invalid empty or null string for counter name. - Cannot create Performance Category with counter name {0} because the name is a duplicate. + Cannot create Performance Category with counter name '{0}' because the name is a duplicate. Cannot delete Performance Category because this category is not registered or is a system category. @@ -237,7 +234,7 @@ Counter is not single instance, an instance name needs to be specified. - Instance {0} does not exist in category {1}. + Instance '{0}' does not exist in category '{1}'. The InstanceLifetime cannot be set after the instance has been initialized. You must use the default constructor and set the CategoryName, InstanceName, CounterName, InstanceLifetime and ReadOnly properties manually before setting the RawValue. @@ -279,13 +276,13 @@ Cannot initialize security descriptor initialized. - Cannot open registry key {0} on computer {1}. + Cannot open registry key '{0}' on computer '{1}' Cannot calculate the size of the file view. - Cannot read Category {0}. + Cannot read Category '{0}'. Performance Counters are not supported on this platform. diff --git a/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs b/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs index bdd47b922779d..59e03c196500f 100644 --- a/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs +++ b/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs @@ -369,8 +369,12 @@ internal static bool CounterExists(string machine, string category, string count if (!categoryExists) { - // Consider adding diagnostic logic here, may be we can dump the nameTable... - throw new InvalidOperationException(SR.MissingCategory); +#if DEBUG + string categories = "Categories: " + String.Join(GetCategories(), ';'); + throw new InvalidOperationException(SR.Format(SR.MissingCategory, category) + "\n" + categories); +#else + throw new InvalidOperationException(SR.Format(SR.MissingCategory, category)); +#endif } return counterExists; @@ -792,7 +796,7 @@ internal static string GetCategoryHelp(string machine, string category) help = library.GetCategoryHelp(category); if (help == null) - throw new InvalidOperationException(SR.MissingCategory); + throw new InvalidOperationException(SR.Format(SR.MissingCategory, category)); return help; } @@ -823,7 +827,7 @@ internal static CategorySample GetCategorySample(string machine, string category } } if (sample == null) - throw new InvalidOperationException(SR.MissingCategory); + throw new InvalidOperationException(SR.Format(SR.MissingCategory, category)); return sample; } @@ -864,7 +868,7 @@ internal static string[] GetCounters(string machine, string category) } if (!categoryExists) - throw new InvalidOperationException(SR.MissingCategory); + throw new InvalidOperationException(SR.Format(SR.MissingCategory, category)); return counters; } @@ -929,7 +933,7 @@ internal static string GetCounterHelp(string machine, string category, string co help = library.GetCounterHelp(category, counter, ref categoryExists); if (!categoryExists) - throw new InvalidOperationException(SR.Format(SR.MissingCategoryDetail, category)); + throw new InvalidOperationException(SR.Format(SR.MissingCategory, category)); return help; } From f3ca6f91ba9c758bb246be8ba26bd356d3f9dda6 Mon Sep 17 00:00:00 2001 From: Dan Moseley Date: Wed, 27 Oct 2021 21:41:18 -0600 Subject: [PATCH 2/3] ypot --- .../src/System/Diagnostics/PerformanceCounterLib.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs b/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs index 59e03c196500f..b79b660cf2ed7 100644 --- a/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs +++ b/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs @@ -370,7 +370,7 @@ internal static bool CounterExists(string machine, string category, string count if (!categoryExists) { #if DEBUG - string categories = "Categories: " + String.Join(GetCategories(), ';'); + string categories = "Categories: " + string.Join(';', library.GetCategories()); throw new InvalidOperationException(SR.Format(SR.MissingCategory, category) + "\n" + categories); #else throw new InvalidOperationException(SR.Format(SR.MissingCategory, category)); From 211853afea2a59ab951cdb8ff554a385f2a53353 Mon Sep 17 00:00:00 2001 From: Dan Moseley Date: Thu, 28 Oct 2021 23:26:05 -0600 Subject: [PATCH 3/3] Update src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs --- .../src/System/Diagnostics/PerformanceCounterLib.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs b/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs index b79b660cf2ed7..43d92d2c5729b 100644 --- a/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs +++ b/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/PerformanceCounterLib.cs @@ -371,7 +371,7 @@ internal static bool CounterExists(string machine, string category, string count { #if DEBUG string categories = "Categories: " + string.Join(';', library.GetCategories()); - throw new InvalidOperationException(SR.Format(SR.MissingCategory, category) + "\n" + categories); + throw new InvalidOperationException(SR.Format(SR.MissingCategory, category) + "\r\n" + categories); #else throw new InvalidOperationException(SR.Format(SR.MissingCategory, category)); #endif