Skip to content

Commit cb6d4b0

Browse files
RakeshwarKRakeshwar Reddy Kambaiahgari
andauthored
WindowsPerformanceCounterMonitor fix (#718)
* remove WMI auto-switch * remove WMI auto-switch * UpVersion --------- Co-authored-by: Rakeshwar Reddy Kambaiahgari <rkambaiahgar@microsoft.com>
1 parent b96a4d2 commit cb6d4b0

5 files changed

Lines changed: 17 additions & 24 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.2.9
1+
3.3.0

src/VirtualClient/VirtualClient.Main/profiles/MONITORS-COUNTERS.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
"Counters10": "Memory=Faults/sec",
5656
"Counters11": "Memory=(Page Reads/sec|Page Writes/sec|Pages/sec|Pages Input/sec|Pages Output/sec)",
5757
"Counters12": "PhysicalDisk=\\(_Total\\)",
58-
"Counters13": "Processor=\\(_Total\\)",
59-
"Counters14": "Processor=\\([0-9,]+\\)\\\\% (C[0-9]+|Idle|Interrupt|Privileged|Processor|User) Time",
58+
"Counters13": "Processor Information=\\(_Total\\)",
59+
"Counters14": "Processor Information=\\([0-9,]+\\)\\\\% (C[0-9]+|Idle|Interrupt|Privileged|Processor|User) Time",
6060
"Counters15": "System=.",
6161
"Comments": "The counters defined are formatted as {category}={counter_match_expression}. The match expression is a regular expression to allow for handling variability of counters available on different systems. JSON content has eccentricities. Use 4-backslashes to represent a single backslash and 2-backslashes to represent a regular expression character escape."
6262
}

src/VirtualClient/VirtualClient.Main/profiles/MONITORS-DEFAULT.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@
154154
"Counters10": "Memory=Faults/sec",
155155
"Counters11": "Memory=(Page Reads/sec|Page Writes/sec|Pages/sec|Pages Input/sec|Pages Output/sec)",
156156
"Counters12": "PhysicalDisk=\\(_Total\\)",
157-
"Counters13": "Processor=\\(_Total\\)",
158-
"Counters14": "Processor=\\([0-9,]+\\)\\\\% (C[0-9]+|Idle|Interrupt|Privileged|Processor|User) Time",
157+
"Counters13": "Processor Information=\\(_Total\\)",
158+
"Counters14": "Processor Information=\\([0-9,]+\\)\\\\% (C[0-9]+|Idle|Interrupt|Privileged|Processor|User) Time",
159159
"Counters15": "System=.",
160160
"Comments": "The counters defined are formatted as {category}={counter_match_expression}. The match expression is a regular expression to allow for handling variability of counters available on different systems. JSON content has eccentricities. Use 4-backslashes to represent a single backslash and 2-backslashes to represent a regular expression character escape."
161161
}

src/VirtualClient/VirtualClient.Monitors/PerformanceCounters/WindowsPerformanceCounterMonitor.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ public TimeSpan CounterDiscoveryInterval
7373

7474
/// <summary>
7575
/// Defines the counter provider to use. Supported values: "Default" and "WMI".
76-
/// When set to "Default", the monitor auto-selects WMI on systems with more than
77-
/// 64 logical processors where the legacy .NET PerformanceCounter API fails.
78-
/// When set to "WMI", the WMI provider is always used regardless of LP count.
76+
/// When set to "Default" (or any value other than "WMI"), the .NET PerformanceCounter
77+
/// API is used. When set to "WMI", the WMI provider is used. The provider is selected
78+
/// strictly from this parameter; the monitor does not infer a provider from system
79+
/// characteristics such as logical processor count.
7980
/// </summary>
8081
public string CounterProvider
8182
{
@@ -91,21 +92,14 @@ public string CounterProvider
9192
protected virtual string CounterProviderName => this.UseWmiProvider ? "WMI" : ".NET SDK";
9293

9394
/// <summary>
94-
/// Returns true when the WMI provider should be used, based on the CounterProvider
95-
/// parameter and the system's logical processor count.
95+
/// Returns true only when the <see cref="CounterProvider"/> parameter is explicitly
96+
/// set to "WMI". No implicit/automatic selection is performed.
9697
/// </summary>
9798
protected bool UseWmiProvider
9899
{
99100
get
100101
{
101-
if (string.Equals(this.CounterProvider, "WMI", StringComparison.OrdinalIgnoreCase))
102-
{
103-
return true;
104-
}
105-
106-
// Auto-select WMI when the system has >64 logical processors.
107-
// The legacy .NET PerformanceCounter API fails on these systems.
108-
return Environment.ProcessorCount > 64;
102+
return string.Equals(this.CounterProvider, "WMI", StringComparison.OrdinalIgnoreCase);
109103
}
110104
}
111105

src/VirtualClient/VirtualClient.Monitors/PerformanceCounters/WindowsWmiPerformanceCounterMonitor.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ namespace VirtualClient.Monitors
1414

1515
/// <summary>
1616
/// Monitor captures performance counters from Windows systems using WMI
17-
/// (CimSession querying Win32_PerfFormattedData_* classes). Required on
18-
/// bare-metal systems with more than 64 logical processors where the legacy
19-
/// .NET PerformanceCounter API fails.
17+
/// (CimSession querying Win32_PerfFormattedData_* classes). Opt-in alternative
18+
/// to the default .NET PerformanceCounter API path.
2019
/// </summary>
2120
/// <remarks>
2221
/// This subclass always uses the WMI provider regardless of the CounterProvider
23-
/// parameter or logical processor count. It can be referenced directly in profiles
24-
/// as an alternative to setting CounterProvider=WMI on the base class.
22+
/// parameter. It can be referenced directly in profiles as an alternative to
23+
/// setting CounterProvider=WMI on the base class.
2524
/// </remarks>
2625
public class WindowsWmiPerformanceCounterMonitor : WindowsPerformanceCounterMonitor
2726
{
@@ -37,7 +36,7 @@ public WindowsWmiPerformanceCounterMonitor(IServiceCollection dependencies, IDic
3736
protected override string CounterProviderName => "WMI";
3837

3938
/// <summary>
40-
/// Always uses WMI for counter discovery, bypassing the auto-detection logic.
39+
/// Always uses WMI for counter discovery.
4140
/// </summary>
4241
protected override void LoadCounters(EventContext telemetryContext, CancellationToken cancellationToken)
4342
{

0 commit comments

Comments
 (0)