Skip to content

Commit 135a94a

Browse files
Expose Resource Monitoring Snapshot API (#5392)
* Expose Snapshot API * Remove more unnecessary suppressions of S4049
1 parent 8fa03a9 commit 135a94a

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics.CodeAnalysis;
5+
using Microsoft.Shared.DiagnosticIds;
6+
47
namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
58

69
/// <summary>
710
/// An interface to be implemented by a provider that represents an underlying system and gets resources data about it.
811
/// </summary>
9-
internal interface ISnapshotProvider
12+
[Experimental(diagnosticId: DiagnosticIds.Experiments.ResourceMonitoring, UrlFormat = DiagnosticIds.UrlFormat)]
13+
public interface ISnapshotProvider
1014
{
1115
/// <summary>
1216
/// Gets the static values of CPU and memory limitations defined by the system.
@@ -17,7 +21,5 @@ internal interface ISnapshotProvider
1721
/// Get a snapshot of the resource utilization of the system.
1822
/// </summary>
1923
/// <returns>An appropriate sample.</returns>
20-
#pragma warning disable S4049 // Properties should be preferred
2124
Snapshot GetSnapshot();
22-
#pragma warning restore S4049 // Properties should be preferred
2325
}

src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilization.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Diagnostics.CodeAnalysis;
6+
using Microsoft.Shared.DiagnosticIds;
67
using Microsoft.Shared.Diagnostics;
78

89
namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
@@ -41,7 +42,11 @@ public readonly struct ResourceUtilization
4142
/// </summary>
4243
public SystemResources SystemResources { get; }
4344

44-
internal Snapshot Snapshot { get; } = default;
45+
/// <summary>
46+
/// Gets the latest snapshot of the resource utilization of the system.
47+
/// </summary>
48+
[Experimental(diagnosticId: DiagnosticIds.Experiments.ResourceMonitoring, UrlFormat = DiagnosticIds.UrlFormat)]
49+
public Snapshot Snapshot { get; } = default;
4550

4651
/// <summary>
4752
/// Initializes a new instance of the <see cref="ResourceUtilization"/> struct.

src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Snapshot.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Diagnostics.CodeAnalysis;
6+
using Microsoft.Shared.DiagnosticIds;
67
using Microsoft.Shared.Diagnostics;
78

89
namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
@@ -11,7 +12,8 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
1112
/// A snapshot of CPU and memory usage taken periodically over time.
1213
/// </summary>
1314
[SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "Comparing instances is not an expected scenario")]
14-
internal readonly struct Snapshot
15+
[Experimental(diagnosticId: DiagnosticIds.Experiments.ResourceMonitoring, UrlFormat = DiagnosticIds.UrlFormat)]
16+
public readonly struct Snapshot
1517
{
1618
/// <summary>
1719
/// Gets the total CPU time that has elapsed since startup.

src/Libraries/Microsoft.Extensions.Options.Contextual/Provider/NullConfigureContextualOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public static class NullConfigureContextualOptions
1313
/// </summary>
1414
/// <typeparam name="TOptions">The options type to configure.</typeparam>
1515
/// <returns>A do-nothing instance of <see cref="IConfigureContextualOptions{TOptions}"/>.</returns>
16-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Code Smell", "S4049:Properties should be preferred", Justification = "Not possible for generic methods.")]
1716
public static IConfigureContextualOptions<TOptions> GetInstance<TOptions>()
1817
where TOptions : class
1918
=> NullConfigureContextualOptions<TOptions>.Instance;

0 commit comments

Comments
 (0)