From 8997e8600fa2bceb0f122f7a5d2d90a1268cfcc1 Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Wed, 24 Nov 2021 14:36:32 +0300 Subject: [PATCH] Use separate partials for iOS&tvOS instead of UnknowUnix in System.Diagnostics.Process (#61871) --- .../src/System.Diagnostics.Process.csproj | 10 ++- .../System/Diagnostics/Process.UnknownUnix.cs | 10 --- .../src/System/Diagnostics/Process.cs | 2 + .../src/System/Diagnostics/Process.iOS.cs | 89 +++++++++++++++++++ .../Diagnostics/ProcessManager.UnknownUnix.cs | 4 - .../System/Diagnostics/ProcessManager.iOS.cs | 39 ++++++++ .../Diagnostics/ProcessThread.UnknownUnix.cs | 8 -- .../System/Diagnostics/ProcessThread.iOS.cs | 56 ++++++++++++ 8 files changed, 192 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.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 fd1f50ccd4323..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 @@ -16,6 +16,56 @@ 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. + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + 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 +74,45 @@ 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..8faa430900aab --- /dev/null +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.iOS.cs @@ -0,0 +1,56 @@ +// 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(); } + set { throw new PlatformNotSupportedException(); } + } + + /// + /// 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(); } + } + + 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 + /// System.Diagnostics.ProcessThread.PrivilegedProcessorTime. + /// + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] + public TimeSpan TotalProcessorTime + { + get { throw new PlatformNotSupportedException(); } + } + + /// + /// 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(); } + } + } +}