Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Resource Monitoring Snapshot API #5392

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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