Skip to content
Closed
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 @@ -7,11 +7,6 @@ namespace System.Diagnostics
{
public partial class ProcessThread
{
/// <summary>
/// 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.
/// </summary>
private ThreadPriorityLevel PriorityLevelCore
{
get
Expand All @@ -29,51 +24,16 @@ private ThreadPriorityLevel PriorityLevelCore
// all threads e.g. reflects process start. This may be re-visited later.
private static DateTime GetStartTime() => throw new PlatformNotSupportedException();

/// <summary>
/// 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.
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
public TimeSpan TotalProcessorTime
private TimeSpan GetTotalProcessorTime()
{
get
{
Interop.Process.proc_stats stat = Interop.Process.GetThreadInfo(_processId, Id);
return Process.TicksToTimeSpan(stat.userTime + stat.systemTime);
}
Interop.Process.proc_stats stat = Interop.Process.GetThreadInfo(_processId, Id);
return Process.TicksToTimeSpan(stat.userTime + stat.systemTime);
}

/// <summary>
/// Returns the amount of time the associated thread has spent running code
/// inside the application (not the operating system core).
/// </summary>
public TimeSpan UserProcessorTime
{
get
{
Interop.Process.proc_stats stat = Interop.Process.GetThreadInfo(_processId, Id);
return Process.TicksToTimeSpan(stat.userTime);
}
}

/// <summary>
/// Returns the amount of time the thread has spent running code inside the operating
/// system core.
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
public TimeSpan PrivilegedProcessorTime
{
get
{
Interop.Process.proc_stats stat = Interop.Process.GetThreadInfo(_processId, Id);
return Process.TicksToTimeSpan(stat.systemTime);
}
private TimeSpan GetUserProcessorTime()
=> Process.TicksToTimeSpan(Interop.Process.GetThreadInfo(_processId, Id).userTime);

}
private TimeSpan GetPrivilegedProcessorTime()
=> Process.TicksToTimeSpan(Interop.Process.GetThreadInfo(_processId, Id).systemTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ namespace System.Diagnostics
{
public partial class ProcessThread
{
/// <summary>
/// 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.
/// </summary>
private ThreadPriorityLevel PriorityLevelCore
{
// This mapping is relatively arbitrary. 0 is normal based on the man page,
Expand All @@ -29,56 +24,17 @@ private ThreadPriorityLevel PriorityLevelCore
}
}

/// <summary>
/// Returns the amount of time the thread has spent running code inside the operating
/// system core.
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
public TimeSpan PrivilegedProcessorTime
{
get
{
Interop.procfs.ParsedStat stat = GetStat();
return Process.TicksToTimeSpan(stat.stime);
}
}
private TimeSpan GetPrivilegedProcessorTime() => Process.TicksToTimeSpan(GetStat().stime);

private DateTime GetStartTime() => Process.BootTimeToDateTime(Process.TicksToTimeSpan(GetStat().starttime));

/// <summary>
/// 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.
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
public TimeSpan TotalProcessorTime
private TimeSpan GetTotalProcessorTime()
{
get
{
Interop.procfs.ParsedStat stat = GetStat();
return Process.TicksToTimeSpan(stat.utime + stat.stime);
}
Interop.procfs.ParsedStat stat = GetStat();
return Process.TicksToTimeSpan(stat.utime + stat.stime);
}

/// <summary>
/// Returns the amount of time the associated thread has spent running code
/// inside the application (not the operating system core).
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
public TimeSpan UserProcessorTime
{
get
{
Interop.procfs.ParsedStat stat = GetStat();
return Process.TicksToTimeSpan(stat.utime);
}
}
private TimeSpan GetUserProcessorTime() => Process.TicksToTimeSpan(GetStat().utime);

private Interop.procfs.ParsedStat GetStat()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ namespace System.Diagnostics
{
public partial class ProcessThread
{
/// <summary>
/// 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.
/// </summary>
private static ThreadPriorityLevel PriorityLevelCore
{
// Does not appear to be a POSIX API to do this on macOS.
Expand All @@ -21,42 +16,17 @@ private static ThreadPriorityLevel PriorityLevelCore
set { throw new PlatformNotSupportedException(SR.ThreadPriorityNotSupported); }
}

/// <summary>
/// Returns the amount of time the thread has spent running code inside the operating
/// system core.
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
public TimeSpan PrivilegedProcessorTime => new TimeSpan((long)GetThreadInfo().pth_system_time);
private TimeSpan GetPrivilegedProcessorTime() => new TimeSpan((long)GetThreadInfo().pth_system_time);

private static 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.
/// It is the sum of the System.Diagnostics.ProcessThread.UserProcessorTime and
/// System.Diagnostics.ProcessThread.PrivilegedProcessorTime.
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
public TimeSpan TotalProcessorTime
private TimeSpan GetTotalProcessorTime()
{
get
{
Interop.libproc.proc_threadinfo info = GetThreadInfo();
return new TimeSpan((long)(info.pth_user_time + info.pth_system_time));
}
Interop.libproc.proc_threadinfo info = GetThreadInfo();
return new TimeSpan((long)(info.pth_user_time + info.pth_system_time));
}

/// <summary>
/// Returns the amount of time the associated thread has spent running code
/// inside the application (not the operating system core).
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
public TimeSpan UserProcessorTime => new TimeSpan((long)GetThreadInfo().pth_user_time);
private TimeSpan GetUserProcessorTime() => new TimeSpan((long)GetThreadInfo().pth_user_time);

private Interop.libproc.proc_threadinfo GetThreadInfo()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,23 @@ namespace System.Diagnostics
{
public partial class ProcessThread
{
/// <summary>Sets the processor that this thread would ideally like to run on.</summary>
public int IdealProcessor
private static void SetIdealProcessor(int value)
{
set
{
// Nop. This is a hint, and there's no good match for the Windows concept.
}
// Nop. This is a hint, and there's no good match for the Windows concept.
}

/// <summary>
/// Resets the ideal processor so there is no ideal processor for this thread (e.g.
/// any processor is ideal).
/// </summary>
public void ResetIdealProcessor()
private static void ResetIdealProcessorCore()
{
// Nop. This is a hint, and there's no good match for the Windows concept.
// Nop. This is a hint, and there's no good match for the Windows concept.
}

/// <summary>
/// Returns or sets whether this thread would like a priority boost if the user interacts
/// with user interface associated with this thread.
/// </summary>
private static bool PriorityBoostEnabledCore
{
get { return false; }
set { } // Nop
}

/// <summary>
/// Sets which processors the associated thread is allowed to be scheduled to run on.
/// Each processor is represented as a bit: bit 0 is processor one, bit 1 is processor
/// two, etc. For example, the value 1 means run on processor one, 2 means run on
/// processor two, 3 means run on processor one or two.
/// </summary>
[SupportedOSPlatform("windows")]
public IntPtr ProcessorAffinity
{
set { throw new PlatformNotSupportedException(); } // No ability to change the affinity of a thread in an arbitrary process
}
private static void SetProcessorAffinity(IntPtr value)
=> throw new PlatformNotSupportedException(); // No ability to change the affinity of a thread in an arbitrary process
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,24 @@ namespace System.Diagnostics
{
public partial class ProcessThread
{
/// <summary>Sets the processor that this thread would ideally like to run on.</summary>
public int IdealProcessor
private void SetIdealProcessor(int value)
{
set
using (SafeThreadHandle threadHandle = OpenThreadHandle(Interop.Kernel32.ThreadOptions.THREAD_SET_INFORMATION))
{
using (SafeThreadHandle threadHandle = OpenThreadHandle(Interop.Kernel32.ThreadOptions.THREAD_SET_INFORMATION))
if (Interop.Kernel32.SetThreadIdealProcessor(threadHandle, value) < 0)
{
if (Interop.Kernel32.SetThreadIdealProcessor(threadHandle, value) < 0)
{
throw new Win32Exception();
}
throw new Win32Exception();
}
}
}

/// <summary>
/// Resets the ideal processor so there is no ideal processor for this thread (e.g.
/// any processor is ideal).
/// </summary>
public void ResetIdealProcessor()
private void ResetIdealProcessorCore()
{
// MAXIMUM_PROCESSORS == 32 on 32-bit or 64 on 64-bit, and means the thread has no preferred processor
int MAXIMUM_PROCESSORS = IntPtr.Size == 4 ? 32 : 64;
IdealProcessor = MAXIMUM_PROCESSORS;
}

/// <summary>
/// Returns or sets whether this thread would like a priority boost if the user interacts
/// with user interface associated with this thread.
/// </summary>
private bool PriorityBoostEnabledCore
{
get
Expand All @@ -63,11 +51,6 @@ private bool PriorityBoostEnabledCore
}
}

/// <summary>
/// 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.
/// </summary>
private ThreadPriorityLevel PriorityLevelCore
{
get
Expand All @@ -94,65 +77,24 @@ private ThreadPriorityLevel PriorityLevelCore
}
}

/// <summary>
/// Sets which processors the associated thread is allowed to be scheduled to run on.
/// Each processor is represented as a bit: bit 0 is processor one, bit 1 is processor
/// two, etc. For example, the value 1 means run on processor one, 2 means run on
/// processor two, 3 means run on processor one or two.
/// </summary>
[SupportedOSPlatform("windows")]
public IntPtr ProcessorAffinity
private void SetProcessorAffinity(IntPtr value)
{
set
using (SafeThreadHandle threadHandle = OpenThreadHandle(Interop.Kernel32.ThreadOptions.THREAD_SET_INFORMATION | Interop.Kernel32.ThreadOptions.THREAD_QUERY_INFORMATION))
{
using (SafeThreadHandle threadHandle = OpenThreadHandle(Interop.Kernel32.ThreadOptions.THREAD_SET_INFORMATION | Interop.Kernel32.ThreadOptions.THREAD_QUERY_INFORMATION))
if (Interop.Kernel32.SetThreadAffinityMask(threadHandle, value) == IntPtr.Zero)
{
if (Interop.Kernel32.SetThreadAffinityMask(threadHandle, value) == IntPtr.Zero)
{
throw new Win32Exception();
}
throw new Win32Exception();
}
}
}

/// <summary>
/// Returns the amount of time the thread has spent running code inside the operating
/// system core.
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
public TimeSpan PrivilegedProcessorTime
{
get { return GetThreadTimes().PrivilegedProcessorTime; }
}
private TimeSpan GetPrivilegedProcessorTime() => GetThreadTimes().PrivilegedProcessorTime;

private DateTime GetStartTime() => GetThreadTimes().StartTime;

/// <summary>
/// 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.
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
public TimeSpan TotalProcessorTime
{
get { return GetThreadTimes().TotalProcessorTime; }
}
private TimeSpan GetTotalProcessorTime() => GetThreadTimes().TotalProcessorTime;

/// <summary>
/// Returns the amount of time the associated thread has spent running code
/// inside the application (not the operating system core).
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
public TimeSpan UserProcessorTime
{
get { return GetThreadTimes().UserProcessorTime; }
}
private TimeSpan GetUserProcessorTime() => GetThreadTimes().UserProcessorTime;

/// <summary>Gets timing information for the thread.</summary>
private ProcessThreadTimes GetThreadTimes()
Expand Down
Loading