From a31ea472c916c957fc2e00f615a4b703bfd93294 Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Sat, 20 Nov 2021 14:46:42 +0300 Subject: [PATCH 1/3] Use separate partials for iOS&tvOS instead of UnknowUnix in System.Diagnostics.Process --- .../src/System.Diagnostics.Process.csproj | 10 ++- .../System/Diagnostics/Process.UnknownUnix.cs | 10 --- .../src/System/Diagnostics/Process.iOS.cs | 86 +++++++++++++++++++ .../Diagnostics/ProcessManager.UnknownUnix.cs | 4 - .../System/Diagnostics/ProcessManager.iOS.cs | 39 +++++++++ .../Diagnostics/ProcessThread.UnknownUnix.cs | 8 -- .../System/Diagnostics/ProcessThread.iOS.cs | 57 ++++++++++++ 7 files changed, 188 insertions(+), 26 deletions(-) create mode 100644 src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.iOS.cs create mode 100644 src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.iOS.cs diff --git a/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj b/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj index 27e7ac68e4af5..41548252d1f5e 100644 --- a/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj +++ b/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj @@ -340,14 +340,16 @@ - + + + + + + - - - diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.UnknownUnix.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.UnknownUnix.cs index 4b5f5116c14f4..897fde77e9a75 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.UnknownUnix.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.UnknownUnix.cs @@ -1,8 +1,6 @@ // 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.Versioning; - namespace System.Diagnostics { public partial class Process : IDisposable @@ -11,16 +9,12 @@ public partial class Process : IDisposable /// Creates an array of components that are associated with process resources on a /// remote computer. These process resources share the specified process name. /// - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public static Process[] GetProcessesByName(string? processName, string machineName) { throw new PlatformNotSupportedException(); } /// Gets the amount of time the process has spent running code inside the operating system core. - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public TimeSpan PrivilegedProcessorTime { get { throw new PlatformNotSupportedException(); } @@ -37,8 +31,6 @@ internal DateTime StartTimeCore /// It is the sum of the and /// . /// - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public TimeSpan TotalProcessorTime { get { throw new PlatformNotSupportedException(); } @@ -48,8 +40,6 @@ public TimeSpan TotalProcessorTime /// Gets the amount of time the associated process has spent running code /// inside the application portion of the process (not the operating system core). /// - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public TimeSpan UserProcessorTime { get { throw new PlatformNotSupportedException(); } diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.iOS.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.iOS.cs index fd1f50ccd4323..1a72a123f405c 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.iOS.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.iOS.cs @@ -16,6 +16,54 @@ public void Kill(bool entireProcessTree) throw new PlatformNotSupportedException(); } + /// + /// Creates an array of components that are associated with process resources on a + /// remote computer. These process resources share the specified process name. + /// + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static Process[] GetProcessesByName(string? processName, string machineName) + { + throw new PlatformNotSupportedException(); + } + + /// Gets the amount of time the process has spent running code inside the operating system core. + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public TimeSpan PrivilegedProcessorTime + { + get { throw new PlatformNotSupportedException(); } + } + + /// Gets the time the associated process was started. + internal DateTime StartTimeCore + { + get { throw new PlatformNotSupportedException(); } + } + + /// + /// Gets the amount of time the associated process has spent utilizing the CPU. + /// It is the sum of the and + /// . + /// + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public TimeSpan TotalProcessorTime + { + get { throw new PlatformNotSupportedException(); } + } + + /// + /// Gets the amount of time the associated process has spent running code + /// inside the application portion of the process (not the operating system core). + /// + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public TimeSpan UserProcessorTime + { + get { throw new PlatformNotSupportedException(); } + } + /// /// Returns all immediate child processes. /// @@ -24,6 +72,44 @@ private IReadOnlyList GetChildProcesses(Process[]? processes = null) throw new PlatformNotSupportedException(); } + /// Gets parent process ID + private int GetParentProcessId => + throw new PlatformNotSupportedException(); + + /// + /// Gets or sets which processors the threads in this process can be scheduled to run on. + /// + private IntPtr ProcessorAffinityCore + { + get { throw new PlatformNotSupportedException(); } + set { throw new PlatformNotSupportedException(); } + } + + /// + /// Make sure we have obtained the min and max working set limits. + /// + private void GetWorkingSetLimits(out IntPtr minWorkingSet, out IntPtr maxWorkingSet) + { + throw new PlatformNotSupportedException(); + } + + /// Sets one or both of the minimum and maximum working set limits. + /// The new minimum working set limit, or null not to change it. + /// The new maximum working set limit, or null not to change it. + /// The resulting minimum working set limit after any changes applied. + /// The resulting maximum working set limit after any changes applied. + private void SetWorkingSetLimitsCore(IntPtr? newMin, IntPtr? newMax, out IntPtr resultingMin, out IntPtr resultingMax) + { + throw new PlatformNotSupportedException(); + } + + /// Gets execution path + private string GetPathToOpenFile() + { + throw new PlatformNotSupportedException(); + } + private int ParentProcessId => throw new PlatformNotSupportedException(); + private static bool IsProcessInvalidException(Exception e) => // InvalidOperationException signifies conditions such as the process already being dead. // Win32Exception signifies issues such as insufficient permissions to get details on the process. diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.UnknownUnix.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.UnknownUnix.cs index 2fddb3b200e7e..aa08c5b591f35 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.UnknownUnix.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.UnknownUnix.cs @@ -1,8 +1,6 @@ // 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.Versioning; - namespace System.Diagnostics { internal static partial class ProcessManager @@ -16,8 +14,6 @@ public static int[] GetProcessIds() /// Gets process infos for each process on the specified machine. /// The target machine. /// An array of process infos, one per found process. - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public static ProcessInfo[] GetProcessInfos(string machineName) { throw new PlatformNotSupportedException(); diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.iOS.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.iOS.cs new file mode 100644 index 0000000000000..2fddb3b200e7e --- /dev/null +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.iOS.cs @@ -0,0 +1,39 @@ +// 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.Versioning; + +namespace System.Diagnostics +{ + internal static partial class ProcessManager + { + /// Gets the IDs of all processes on the current machine. + public static int[] GetProcessIds() + { + throw new PlatformNotSupportedException(); + } + + /// Gets process infos for each process on the specified machine. + /// The target machine. + /// An array of process infos, one per found process. + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public static ProcessInfo[] GetProcessInfos(string machineName) + { + throw new PlatformNotSupportedException(); + } + + /// Gets an array of module infos for the specified process. + /// The ID of the process whose modules should be enumerated. + /// The array of modules. + internal static ProcessModuleCollection GetModules(int processId) + { + return new ProcessModuleCollection(0); + } + + private static ProcessInfo CreateProcessInfo(int pid) + { + throw new PlatformNotSupportedException(); + } + } +} diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.UnknownUnix.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.UnknownUnix.cs index acb79218a5b27..6d947625ddd6b 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.UnknownUnix.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.UnknownUnix.cs @@ -1,8 +1,6 @@ // 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.Versioning; - namespace System.Diagnostics { public partial class ProcessThread @@ -22,8 +20,6 @@ private ThreadPriorityLevel PriorityLevelCore /// Returns the amount of time the thread has spent running code inside the operating /// system core. /// - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public TimeSpan PrivilegedProcessorTime { get { throw new PlatformNotSupportedException(); } // Not available on POSIX @@ -36,8 +32,6 @@ public TimeSpan PrivilegedProcessorTime /// It is the sum of the System.Diagnostics.ProcessThread.UserProcessorTime and /// System.Diagnostics.ProcessThread.PrivilegedProcessorTime. /// - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public TimeSpan TotalProcessorTime { get { throw new PlatformNotSupportedException(); } // Not available on POSIX @@ -47,8 +41,6 @@ public TimeSpan TotalProcessorTime /// Returns the amount of time the associated thread has spent running code /// inside the application (not the operating system core). /// - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public TimeSpan UserProcessorTime { get { throw new PlatformNotSupportedException(); } // Not available on POSIX diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.iOS.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.iOS.cs new file mode 100644 index 0000000000000..acb79218a5b27 --- /dev/null +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.iOS.cs @@ -0,0 +1,57 @@ +// 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.Versioning; + +namespace System.Diagnostics +{ + public partial class ProcessThread + { + /// + /// Returns or sets the priority level of the associated thread. The priority level is + /// not an absolute level, but instead contributes to the actual thread priority by + /// considering the priority class of the process. + /// + private ThreadPriorityLevel PriorityLevelCore + { + get { throw new PlatformNotSupportedException(); } // Not available on POSIX + set { throw new PlatformNotSupportedException(); } // Not available on POSIX + } + + /// + /// Returns the amount of time the thread has spent running code inside the operating + /// system core. + /// + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public TimeSpan PrivilegedProcessorTime + { + get { throw new PlatformNotSupportedException(); } // Not available on POSIX + } + + private DateTime GetStartTime() => throw new PlatformNotSupportedException(); // Not available on POSIX + + /// + /// Returns the amount of time the associated thread has spent utilizing the CPU. + /// It is the sum of the System.Diagnostics.ProcessThread.UserProcessorTime and + /// System.Diagnostics.ProcessThread.PrivilegedProcessorTime. + /// + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public TimeSpan TotalProcessorTime + { + get { throw new PlatformNotSupportedException(); } // Not available on POSIX + } + + /// + /// Returns the amount of time the associated thread has spent running code + /// inside the application (not the operating system core). + /// + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public TimeSpan UserProcessorTime + { + get { throw new PlatformNotSupportedException(); } // Not available on POSIX + } + } +} From b8970c64a0d19fea606297b976940a5baeaef6f6 Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Mon, 22 Nov 2021 13:35:51 +0300 Subject: [PATCH 2/3] clean up --- .../src/System/Diagnostics/Process.iOS.cs | 1 + .../src/System/Diagnostics/ProcessThread.iOS.cs | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.iOS.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.iOS.cs index 1a72a123f405c..2f484b3ed25f3 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.iOS.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.iOS.cs @@ -108,6 +108,7 @@ private string GetPathToOpenFile() { throw new PlatformNotSupportedException(); } + private int ParentProcessId => throw new PlatformNotSupportedException(); private static bool IsProcessInvalidException(Exception e) => diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.iOS.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.iOS.cs index acb79218a5b27..8faa430900aab 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.iOS.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.iOS.cs @@ -14,8 +14,8 @@ public partial class ProcessThread /// private ThreadPriorityLevel PriorityLevelCore { - get { throw new PlatformNotSupportedException(); } // Not available on POSIX - set { throw new PlatformNotSupportedException(); } // Not available on POSIX + get { throw new PlatformNotSupportedException(); } + set { throw new PlatformNotSupportedException(); } } /// @@ -26,11 +26,10 @@ private ThreadPriorityLevel PriorityLevelCore [UnsupportedOSPlatform("tvos")] public TimeSpan PrivilegedProcessorTime { - get { throw new PlatformNotSupportedException(); } // Not available on POSIX + get { throw new PlatformNotSupportedException(); } } - private DateTime GetStartTime() => throw new PlatformNotSupportedException(); // Not available on POSIX - + private DateTime GetStartTime() => throw new PlatformNotSupportedException(); /// /// Returns the amount of time the associated thread has spent utilizing the CPU. /// It is the sum of the System.Diagnostics.ProcessThread.UserProcessorTime and @@ -40,7 +39,7 @@ public TimeSpan PrivilegedProcessorTime [UnsupportedOSPlatform("tvos")] public TimeSpan TotalProcessorTime { - get { throw new PlatformNotSupportedException(); } // Not available on POSIX + get { throw new PlatformNotSupportedException(); } } /// @@ -51,7 +50,7 @@ public TimeSpan TotalProcessorTime [UnsupportedOSPlatform("tvos")] public TimeSpan UserProcessorTime { - get { throw new PlatformNotSupportedException(); } // Not available on POSIX + get { throw new PlatformNotSupportedException(); } } } } From 8bad5ea44d23cb7dc829fdd64520d0d41c75d969 Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Mon, 22 Nov 2021 15:12:53 +0300 Subject: [PATCH 3/3] Annotate StartTime/StartTimeCore --- .../src/System/Diagnostics/Process.cs | 2 ++ .../src/System/Diagnostics/Process.iOS.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs index 294ac4f2ac3f6..dab24936576a4 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs @@ -193,6 +193,8 @@ public bool HasExited } /// Gets the time the associated process was started. + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] public DateTime StartTime { get diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.iOS.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.iOS.cs index 2f484b3ed25f3..e3fa89f34ccd1 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.iOS.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.iOS.cs @@ -36,6 +36,8 @@ public TimeSpan PrivilegedProcessorTime } /// Gets the time the associated process was started. + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] internal DateTime StartTimeCore { get { throw new PlatformNotSupportedException(); }