Skip to content

Commit

Permalink
Improve ProcessManager.Win (dotnet#32010)
Browse files Browse the repository at this point in the history
* ---- Style changes start here ----

* Remove unnecessary using directives

* Remove unnecessary assignments

* Use IntPtr.Zero

* Replace magic numbers

* Remove unused parameters

* Replace constructor with initializer

* Simplify delegate interop

* Inline temporary variables

* Remove unnecessary checked keyword

* Remove unnecessary cast

* Introduce using statement

* ---- Style changes end here ----

* Remove magic sleep

* Prealloc list

* Reduce copying

* Use ArrayPool

* Support long path

* Improve P/Invoke signatures

* Optimize modules enumeration

* Rename and move HandleLastWin32Error

* while (true)

* Move comments near codes

* Revert "Support long path"

This reverts commit 1f06435.

* Revert "Introduce using statement"

This reverts commit e3d383a.

* Revert "Remove magic sleep"

This reverts commit d8bc001.

* Add braces

* Simplify initialization

* Fix last Win32 error

* Avoid reallocation if modules count decreased

* Nits

* Simplify codes
  • Loading branch information
nxtn authored Mar 11, 2020
1 parent 19400a4 commit 99af745
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ internal partial class Interop
internal partial class Kernel32
{
[DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, EntryPoint = "K32EnumProcessModules")]
internal static extern bool EnumProcessModules(SafeProcessHandle handle, IntPtr modules, int size, ref int needed);
internal static extern bool EnumProcessModules(SafeProcessHandle handle, IntPtr[]? modules, int size, out int needed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ internal partial class Interop
internal partial class Kernel32
{
[DllImport(Libraries.Kernel32, SetLastError = true)]
internal static extern bool IsWow64Process(SafeProcessHandle hProcess, ref bool Wow64Process);
internal static extern bool IsWow64Process(SafeProcessHandle hProcess, out bool Wow64Process);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.ComponentModel;

namespace System.Diagnostics
{
Expand All @@ -15,9 +14,9 @@ namespace System.Diagnostics
/// </summary>
internal sealed class ProcessInfo
{
internal readonly List<ThreadInfo> _threadInfoList = new List<ThreadInfo>();
internal readonly List<ThreadInfo> _threadInfoList;
internal int BasePriority { get; set; }
internal string ProcessName { get; set; }
internal string ProcessName { get; set; } = string.Empty;
internal int ProcessId { get; set; }
internal long PoolPagedBytes { get; set; }
internal long PoolNonPagedBytes { get; set; }
Expand All @@ -33,20 +32,12 @@ internal sealed class ProcessInfo

internal ProcessInfo()
{
BasePriority = 0;
ProcessName = "";
ProcessId = 0;
PoolPagedBytes = 0;
PoolNonPagedBytes = 0;
VirtualBytes = 0;
VirtualBytesPeak = 0;
WorkingSet = 0;
WorkingSetPeak = 0;
PageFileBytes = 0;
PageFileBytesPeak = 0;
PrivateBytes = 0;
SessionId = 0;
HandleCount = 0;
_threadInfoList = new List<ThreadInfo>();
}

internal ProcessInfo(int threadsNumber)
{
_threadInfoList = new List<ThreadInfo>(threadsNumber);
}
}
}
Loading

0 comments on commit 99af745

Please sign in to comment.