-
-
Notifications
You must be signed in to change notification settings - Fork 143
Add ExceptionlessWindowsEnvironmentInfoCollector #270
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9638a11
Add ExceptionlessWindowsEnvironmentInfoCollector to collect Handle, U…
elachlan e88d20d
Remove redundant white space
elachlan aeb7c15
Changes from review and other refactors
elachlan f6d7aae
changes from review
elachlan a1d3193
changes from review
elachlan 7fa800f
Include peak counts
elachlan a387a0b
changes from review
elachlan 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
74 changes: 74 additions & 0 deletions
74
src/Platforms/Exceptionless.Windows/ExceptionlessWindowsEnvironmentInfoCollector.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,74 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using Exceptionless.Logging; | ||
using Exceptionless.Models.Data; | ||
using Exceptionless.Services; | ||
|
||
namespace Exceptionless { | ||
public class ExceptionlessWindowsEnvironmentInfoCollector : DefaultEnvironmentInfoCollector { | ||
public ExceptionlessWindowsEnvironmentInfoCollector(ExceptionlessConfiguration config, IExceptionlessLog log) : base(config, log) { } | ||
|
||
public override EnvironmentInfo GetEnvironmentInfo() { | ||
EnvironmentInfo info = base.GetEnvironmentInfo(); | ||
PopulateHandleInfo(info); | ||
return info; | ||
} | ||
|
||
private void PopulateHandleInfo(EnvironmentInfo info) { | ||
try { | ||
using (Process currentProcess = Process.GetCurrentProcess()) { | ||
info.Data["Handles"] = currentProcess.HandleCount; | ||
info.Data["UserObjects"] = User32NativeMethods.GetGuiResources(currentProcess.Handle, (int)User32NativeMethods.UIFlags.UserObjectCount); | ||
info.Data["GDIObjects"] = User32NativeMethods.GetGuiResources(currentProcess.Handle, (int)User32NativeMethods.UIFlags.GDIObjectCount); | ||
info.Data["UserObjectsPeak"] = User32NativeMethods.GetGuiResources(currentProcess.Handle, (int)User32NativeMethods.UIFlags.UserObjectsPeakCount); | ||
info.Data["GDIObjectsPeak"] = User32NativeMethods.GetGuiResources(currentProcess.Handle, (int)User32NativeMethods.UIFlags.GDIObjectsPeakCount); | ||
} | ||
} | ||
catch (Exception ex) { | ||
Log.FormattedWarn(typeof(ExceptionlessWindowsEnvironmentInfoCollector), "Unable to get process handles, User objects, or GDI objects. Error message: {0}", ex.Message); | ||
} | ||
} | ||
|
||
private static class User32NativeMethods { | ||
#region User32 | ||
|
||
/// <summary> | ||
/// <para> | ||
/// Retrieves the count of handles to graphical user interface | ||
/// (GUI) objects in use by the specified process. | ||
/// </para> | ||
/// API reference: <see href="https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getguiresources"/> | ||
/// </summary> | ||
/// <param name="hProcess"></param> | ||
/// <param name="uiFlags"></param> | ||
/// <returns></returns> | ||
[System.Runtime.InteropServices.DllImport("User32.dll")] | ||
public static extern int GetGuiResources(IntPtr hProcess, uint uiFlags); | ||
|
||
#endregion | ||
|
||
/// <summary> | ||
/// Enum representing the possible values to pass to <see cref="GetGuiResources(IntPtr, UInt32)"/>. | ||
/// </summary> | ||
public enum UIFlags { | ||
/// <summary> | ||
/// Return the count of GDI objects. | ||
/// </summary> | ||
GDIObjectCount = 0, | ||
/// <summary> | ||
/// Return the count of USER objects. | ||
/// </summary> | ||
UserObjectCount = 1, | ||
/// <summary> | ||
/// Return the peak count of GDI objects. | ||
/// </summary> | ||
GDIObjectsPeakCount = 2, | ||
/// <summary> | ||
/// Return the peak count of USER objects. | ||
/// </summary> | ||
UserObjectsPeakCount = 4, | ||
} | ||
|
||
} | ||
} | ||
} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.