Skip to content
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

Annotate unsupported APIs in System.Diagnostics.Process #57120

Merged
merged 7 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public Process() { }
public long PrivateMemorySize64 { get { throw null; } }
public System.TimeSpan PrivilegedProcessorTime { get { throw null; } }
public string ProcessName { get { throw null; } }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
[System.Runtime.Versioning.SupportedOSPlatform("linux")]
public System.IntPtr ProcessorAffinity { get { throw null; } set { } }
public bool Responding { get { throw null; } }
public Microsoft.Win32.SafeHandles.SafeProcessHandle SafeHandle { get { throw null; } }
Expand Down Expand Up @@ -237,11 +239,13 @@ internal ProcessThread() { }
public int Id { get { throw null; } }
public int IdealProcessor { set { } }
public bool PriorityBoostEnabled { get { throw null; } set { } }
public System.Diagnostics.ThreadPriorityLevel PriorityLevel { get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } }
public System.Diagnostics.ThreadPriorityLevel PriorityLevel { [System.Runtime.Versioning.SupportedOSPlatform("windows")] [System.Runtime.Versioning.SupportedOSPlatform("linux")] [System.Runtime.Versioning.SupportedOSPlatform("freebsd")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } }
public System.TimeSpan PrivilegedProcessorTime { get { throw null; } }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public System.IntPtr ProcessorAffinity { set { } }
public System.IntPtr StartAddress { get { throw null; } }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
[System.Runtime.Versioning.SupportedOSPlatform("linux")]
public System.DateTime StartTime { get { throw null; } }
public System.Diagnostics.ThreadState ThreadState { get { throw null; } }
public System.TimeSpan TotalProcessorTime { get { throw null; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ public string ProcessName
/// or sets which processors the threads in this process can be scheduled to run on.
/// </para>
/// </devdoc>
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("linux")]
public IntPtr ProcessorAffinity
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,5 @@ internal static void ThrowIfRemoteMachine(string machineName)
throw new PlatformNotSupportedException(SR.RemoteMachinesNotSupported);
}
}
public static IntPtr GetMainWindowHandle(int processId)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as pointed by @buyaa-n in #57090 (comment) it turned out to be dead code

{
throw new PlatformNotSupportedException(); // Window handle is a Windows concept
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@ private ThreadPriorityLevel PriorityLevelCore
}
}

/// <summary>Returns the time the associated thread was started.</summary>
public DateTime StartTime
{
// kinfo_proc has one entry per thread but ki_start seems to be same for
// all threads e.g. reflects process start. This may be re-visited later.
get { throw new PlatformNotSupportedException(); }
}
// kinfo_proc has one entry per thread but ki_start seems to be same for
// all threads e.g. reflects process start. This may be re-visited later.
private DateTime GetStartTime() => throw new PlatformNotSupportedException();

/// <summary>
/// Returns the amount of time the associated thread has spent utilizing the CPU.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ public TimeSpan PrivilegedProcessorTime
}
}

/// <summary>Returns the time the associated thread was started.</summary>
public DateTime StartTime
{
get { return Process.BootTimeToDateTime(Process.TicksToTimeSpan(GetStat().starttime)); }
}
private DateTime GetStartTime() => Process.BootTimeToDateTime(Process.TicksToTimeSpan(GetStat().starttime));

/// <summary>
/// Returns the amount of time the associated thread has spent utilizing the CPU.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ private ThreadPriorityLevel PriorityLevelCore
/// </summary>
public TimeSpan PrivilegedProcessorTime => new TimeSpan((long)GetThreadInfo().pth_system_time);

/// <summary>Returns the time the associated thread was started.</summary>
public DateTime StartTime
{
get { throw new PlatformNotSupportedException(); } // macOS does not provide a way to get this data
}
private DateTime GetStartTime() => throw new PlatformNotSupportedException(); // macOS does not provide a way to get this data

/// <summary>
/// Returns the amount of time the associated thread has spent using the CPU.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ public TimeSpan PrivilegedProcessorTime
get { throw new PlatformNotSupportedException(); } // Not available on POSIX
}

/// <summary>Returns the time the associated thread was started.</summary>
public DateTime StartTime
{
get { throw new PlatformNotSupportedException(); } // Not available on POSIX
}
private DateTime GetStartTime() => throw new PlatformNotSupportedException(); // Not available on POSIX

/// <summary>
/// Returns the amount of time the associated thread has spent utilizing the CPU.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,7 @@ public TimeSpan PrivilegedProcessorTime
get { return GetThreadTimes().PrivilegedProcessorTime; }
}

/// <summary>Returns the time the associated thread was started.</summary>
public DateTime StartTime
{
get { return GetThreadTimes().StartTime; }
}
private DateTime GetStartTime() => GetThreadTimes().StartTime;

/// <summary>
/// Returns the amount of time the associated thread has spent utilizing the CPU.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public bool PriorityBoostEnabled
/// </devdoc>
public ThreadPriorityLevel PriorityLevel
{
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("freebsd")]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows, Linux and FreeBSD support it, everything else does not.

get
{
if (!_priorityLevel.HasValue)
Expand Down Expand Up @@ -136,6 +139,14 @@ public ThreadWaitReason WaitReason
}
}

/// <summary>Returns the time the associated thread was started.</summary>
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("linux")]
public DateTime StartTime
{
get => GetStartTime();
}

/// <devdoc>
/// Helper to check preconditions for property access.
/// </devdoc>
Expand Down