-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support metrics in ResourceMonitoring for Windows (#5290)
Fixes #4477 Support metrics in ResourceMonitoring for Windows
- Loading branch information
1 parent
ff43443
commit c016405
Showing
7 changed files
with
698 additions
and
245 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/Interop/BOOL.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Interop; | ||
|
||
/// <summary> | ||
/// Blittable version of Windows BOOL type. It is convenient in situations where | ||
/// manual marshalling is required, or to avoid overhead of regular bool marshalling. | ||
/// </summary> | ||
/// <remarks> | ||
/// Some Windows APIs return arbitrary integer values although the return type is defined | ||
/// as BOOL. It is best to never compare BOOL to TRUE. Always use bResult != BOOL.FALSE | ||
/// or bResult == BOOL.FALSE . | ||
/// </remarks> | ||
#pragma warning disable S1939 // Inheritance list should not be redundant | ||
internal enum BOOL : int | ||
#pragma warning restore S1939 // Inheritance list should not be redundant | ||
{ | ||
FALSE = 0, | ||
TRUE = 1, | ||
} | ||
|
34 changes: 34 additions & 0 deletions
34
.../Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/Interop/MemoryInfo.Native.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.InteropServices; | ||
using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Interop; | ||
|
||
#if NET8_0_OR_GREATER | ||
using DllImportAttr = System.Runtime.InteropServices.LibraryImportAttribute; // We trigger source-gen on .NET 7 and above | ||
#else | ||
using DllImportAttr = System.Runtime.InteropServices.DllImportAttribute; | ||
#endif | ||
|
||
namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Interop; | ||
|
||
internal sealed partial class MemoryInfo | ||
{ | ||
private static partial class SafeNativeMethods | ||
{ | ||
/// <summary> | ||
/// GlobalMemoryStatusEx. | ||
/// </summary> | ||
/// <param name="memoryStatus">Memory Status structure.</param> | ||
/// <returns>Success or failure.</returns> | ||
[DllImportAttr("kernel32.dll", SetLastError = true)] | ||
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)] | ||
public static unsafe | ||
#if NET8_0_OR_GREATER | ||
partial | ||
#else | ||
extern | ||
#endif | ||
BOOL GlobalMemoryStatusEx(MEMORYSTATUSEX* memoryStatus); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.