Skip to content

Commit

Permalink
Expose Resource Monitoring Snapshot API (#5392)
Browse files Browse the repository at this point in the history
* Expose Snapshot API

* Remove more unnecessary suppressions of S4049
  • Loading branch information
evgenyfedorov2 authored Aug 29, 2024
1 parent 8fa03a9 commit 135a94a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using Microsoft.Shared.DiagnosticIds;

namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;

/// <summary>
/// An interface to be implemented by a provider that represents an underlying system and gets resources data about it.
/// </summary>
internal interface ISnapshotProvider
[Experimental(diagnosticId: DiagnosticIds.Experiments.ResourceMonitoring, UrlFormat = DiagnosticIds.UrlFormat)]
public interface ISnapshotProvider
{
/// <summary>
/// Gets the static values of CPU and memory limitations defined by the system.
Expand All @@ -17,7 +21,5 @@ internal interface ISnapshotProvider
/// Get a snapshot of the resource utilization of the system.
/// </summary>
/// <returns>An appropriate sample.</returns>
#pragma warning disable S4049 // Properties should be preferred
Snapshot GetSnapshot();
#pragma warning restore S4049 // Properties should be preferred
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;

namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
Expand Down Expand Up @@ -41,7 +42,11 @@ public readonly struct ResourceUtilization
/// </summary>
public SystemResources SystemResources { get; }

internal Snapshot Snapshot { get; } = default;
/// <summary>
/// Gets the latest snapshot of the resource utilization of the system.
/// </summary>
[Experimental(diagnosticId: DiagnosticIds.Experiments.ResourceMonitoring, UrlFormat = DiagnosticIds.UrlFormat)]
public Snapshot Snapshot { get; } = default;

/// <summary>
/// Initializes a new instance of the <see cref="ResourceUtilization"/> struct.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;

namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
Expand All @@ -11,7 +12,8 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring;
/// A snapshot of CPU and memory usage taken periodically over time.
/// </summary>
[SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "Comparing instances is not an expected scenario")]
internal readonly struct Snapshot
[Experimental(diagnosticId: DiagnosticIds.Experiments.ResourceMonitoring, UrlFormat = DiagnosticIds.UrlFormat)]
public readonly struct Snapshot
{
/// <summary>
/// Gets the total CPU time that has elapsed since startup.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public static class NullConfigureContextualOptions
/// </summary>
/// <typeparam name="TOptions">The options type to configure.</typeparam>
/// <returns>A do-nothing instance of <see cref="IConfigureContextualOptions{TOptions}"/>.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Code Smell", "S4049:Properties should be preferred", Justification = "Not possible for generic methods.")]
public static IConfigureContextualOptions<TOptions> GetInstance<TOptions>()
where TOptions : class
=> NullConfigureContextualOptions<TOptions>.Instance;
Expand Down

0 comments on commit 135a94a

Please sign in to comment.