This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Port System.Diagnostics.PerformanceCounters to .NET Core #24579
Merged
michellemcdaniel
merged 1 commit into
dotnet:master
from
michellemcdaniel:addPerformanceCounters
Oct 11, 2017
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
20 changes: 20 additions & 0 deletions
20
...c/Interop/Windows/advapi32/Interop.ConvertStringSecurityDescriptorToSecurityDescriptor.cs
This file contains hidden or 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,20 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.Win32.SafeHandles; | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
internal partial class Interop | ||
{ | ||
internal partial class Advapi32 | ||
{ | ||
[DllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)] | ||
internal static extern unsafe bool ConvertStringSecurityDescriptorToSecurityDescriptor( | ||
string StringSecurityDescriptor, | ||
int StringSDRevision, | ||
out SafeLocalMemHandle pSecurityDescriptor, | ||
IntPtr SecurityDescriptorSize); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
16 changes: 16 additions & 0 deletions
16
src/Common/src/Interop/Windows/kernel32/Interop.LoadLibrary.cs
This file contains hidden or 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,16 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
internal partial class Interop | ||
{ | ||
internal partial class Kernel32 | ||
{ | ||
[DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true)] | ||
public static extern IntPtr LoadLibrary(string libFilename); | ||
} | ||
} | ||
|
387 changes: 387 additions & 0 deletions
387
src/Common/src/Interop/Windows/kernel32/Interop.PerformanceCounterOptions.cs
Large diffs are not rendered by default.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
src/Common/src/Interop/Windows/kernel32/Interop.ProcessWaitHandle.cs
This file contains hidden or 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,37 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.Win32.SafeHandles; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
|
||
internal partial class Interop | ||
{ | ||
internal partial class Kernel32 | ||
{ | ||
internal sealed class ProcessWaitHandle : WaitHandle | ||
{ | ||
internal ProcessWaitHandle(SafeProcessHandle processHandle) | ||
{ | ||
SafeWaitHandle waitHandle = null; | ||
SafeProcessHandle currentProcHandle = Interop.Kernel32.GetCurrentProcess(); | ||
bool succeeded = Interop.Kernel32.DuplicateHandle( | ||
currentProcHandle, | ||
processHandle, | ||
currentProcHandle, | ||
out waitHandle, | ||
0, | ||
false, | ||
Interop.Kernel32.HandleOptions.DUPLICATE_SAME_ACCESS); | ||
|
||
if (!succeeded) | ||
{ | ||
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); | ||
} | ||
|
||
this.SetSafeWaitHandle(waitHandle); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or 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
23 changes: 23 additions & 0 deletions
23
src/Common/src/Interop/Windows/perfcounter/Interop.FormatFromRawValue.cs
This file contains hidden or 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,23 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
internal partial class Interop | ||
{ | ||
internal partial class PerfCounter | ||
{ | ||
#pragma warning disable BCL0015 // Invalid Pinvoke call | ||
[DllImport(Libraries.PerfCounter, CharSet = CharSet.Unicode)] | ||
public static unsafe extern int FormatFromRawValue( | ||
uint dwCounterType, | ||
uint dwFormat, | ||
ref long pTimeBase, | ||
Interop.Kernel32.PerformanceCounterOptions.PDH_RAW_COUNTER pRawValue1, | ||
Interop.Kernel32.PerformanceCounterOptions.PDH_RAW_COUNTER pRawValue2, | ||
Interop.Kernel32.PerformanceCounterOptions.PDH_FMT_COUNTERVALUE pFmtValue | ||
); | ||
#pragma warning restore BCL0015 | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Common/src/Microsoft/Win32/SafeHandles/SafeLocalMemHandle.cs
This file contains hidden or 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,23 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
|
||
namespace Microsoft.Win32.SafeHandles | ||
{ | ||
internal sealed class SafeLocalMemHandle : SafeHandleZeroOrMinusOneIsInvalid | ||
{ | ||
internal SafeLocalMemHandle() : base(true) { } | ||
|
||
internal SafeLocalMemHandle(IntPtr existingHandle, bool ownsHandle) : base(ownsHandle) | ||
{ | ||
SetHandle(existingHandle); | ||
} | ||
|
||
protected override bool ReleaseHandle() | ||
{ | ||
return Interop.Kernel32.LocalFree(handle) == IntPtr.Zero; | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Instead of adding this new overload that takes a
StringBuilder
forlpBuffer
, why not use the existing internal helper method below that returns a string (and avoids theStringBuilder
allocation and marshaling costs)? Then update the calling code in PerformanceCounterLib.cs to something like the following:Note that the above maintains the previous behavior of setting
s_computerName
to an empty string if the call toGetComputerName
fails, which could happen previously whenStringBuilder.ToString()
is called on an empty builder.