Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -27,6 +27,8 @@ internal DateTime StartTimeCore
/// It is the sum of the <see cref='System.Diagnostics.Process.UserProcessorTime'/> and
/// <see cref='System.Diagnostics.Process.PrivilegedProcessorTime'/>.
/// </summary>
/// <remarks>The value is unavailable after the process exits.</remarks>
Comment thread
adamsitnik marked this conversation as resolved.
Outdated
/// <exception cref="InvalidOperationException">No process is associated with this object, or the process has exited.</exception>
Comment thread
adamsitnik marked this conversation as resolved.
Outdated
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand All @@ -49,6 +51,8 @@ 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).
/// </summary>
/// <remarks>The value is unavailable after the process exits.</remarks>
/// <exception cref="InvalidOperationException">No process is associated with this object, or the process has exited.</exception>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand All @@ -69,6 +73,8 @@ public TimeSpan UserProcessorTime
}

/// <summary>Gets the amount of time the process has spent running code inside the operating system core.</summary>
/// <remarks>The value is unavailable after the process exits.</remarks>
/// <exception cref="InvalidOperationException">No process is associated with this object, or the process has exited.</exception>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace System.Diagnostics
public partial class Process : IDisposable
{
/// <summary>Gets the amount of time the process has spent running code inside the operating system core.</summary>
/// <remarks>The value is unavailable after the process exits.</remarks>
/// <exception cref="InvalidOperationException">No process is associated with this object, or the process has exited.</exception>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand Down Expand Up @@ -88,6 +90,8 @@ private static DateTime BootTime
/// It is the sum of the <see cref='System.Diagnostics.Process.UserProcessorTime'/> and
/// <see cref='System.Diagnostics.Process.PrivilegedProcessorTime'/>.
/// </summary>
/// <remarks>The value is unavailable after the process exits.</remarks>
/// <exception cref="InvalidOperationException">No process is associated with this object, or the process has exited.</exception>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand All @@ -109,6 +113,8 @@ 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).
/// </summary>
/// <remarks>The value is unavailable after the process exits.</remarks>
/// <exception cref="InvalidOperationException">No process is associated with this object, or the process has exited.</exception>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public partial class Process
private const int MicrosecondsToSecondsFactor = 1_000_000;

/// <summary>Gets the amount of time the process has spent running code inside the operating system core.</summary>
/// <remarks>The value is unavailable after the process exits.</remarks>
/// <exception cref="InvalidOperationException">No process is associated with this object, or the process has exited.</exception>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand Down Expand Up @@ -62,6 +64,8 @@ internal static string GetPathToOpenFile()
/// It is the sum of the <see cref='System.Diagnostics.Process.UserProcessorTime'/> and
/// <see cref='System.Diagnostics.Process.PrivilegedProcessorTime'/>.
/// </summary>
/// <remarks>The value is unavailable after the process exits.</remarks>
/// <exception cref="InvalidOperationException">No process is associated with this object, or the process has exited.</exception>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand All @@ -84,6 +88,8 @@ 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).
/// </summary>
/// <remarks>The value is unavailable after the process exits.</remarks>
/// <exception cref="InvalidOperationException">No process is associated with this object, or the process has exited.</exception>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ internal DateTime StartTimeCore
/// It is the sum of the <see cref='System.Diagnostics.Process.UserProcessorTime'/> and
/// <see cref='System.Diagnostics.Process.PrivilegedProcessorTime'/>.
/// </summary>
/// <remarks>The value is unavailable after the process exits.</remarks>
/// <exception cref="InvalidOperationException">No process is associated with this object, or the process has exited.</exception>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand All @@ -49,6 +51,8 @@ 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).
/// </summary>
/// <remarks>The value is unavailable after the process exits.</remarks>
/// <exception cref="InvalidOperationException">No process is associated with this object, or the process has exited.</exception>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand All @@ -69,6 +73,8 @@ public TimeSpan UserProcessorTime
}

/// <summary>Gets the amount of time the process has spent running code inside the operating system core.</summary>
/// <remarks>The value is unavailable after the process exits.</remarks>
/// <exception cref="InvalidOperationException">No process is associated with this object, or the process has exited.</exception>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ internal DateTime StartTimeCore
/// It is the sum of the <see cref='System.Diagnostics.Process.UserProcessorTime'/> and
/// <see cref='System.Diagnostics.Process.PrivilegedProcessorTime'/>.
/// </summary>
/// <remarks>The value is unavailable after the process exits.</remarks>
/// <exception cref="InvalidOperationException">No process is associated with this object, or the process has exited.</exception>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand All @@ -65,6 +67,8 @@ 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).
/// </summary>
/// <remarks>The value is unavailable after the process exits.</remarks>
/// <exception cref="InvalidOperationException">No process is associated with this object, or the process has exited.</exception>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand All @@ -83,6 +87,8 @@ public TimeSpan UserProcessorTime
/// Gets the amount of time the process has spent running code inside the operating
/// system core.
/// </summary>
/// <remarks>The value is unavailable after the process exits.</remarks>
/// <exception cref="InvalidOperationException">No process is associated with this object, or the process has exited.</exception>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ private DateTime ExitTimeCore
}

/// <summary>Gets the amount of time the process has spent running code inside the operating system core.</summary>
/// <remarks>The value can be retrieved after the process exits.</remarks>
/// <exception cref="InvalidOperationException">No process is associated with this object.</exception>
Comment thread
adamsitnik marked this conversation as resolved.
Outdated
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand All @@ -212,6 +214,8 @@ internal DateTime StartTimeCore
/// It is the sum of the <see cref='System.Diagnostics.Process.UserProcessorTime'/> and
/// <see cref='System.Diagnostics.Process.PrivilegedProcessorTime'/>.
/// </summary>
/// <remarks>The value can be retrieved after the process exits.</remarks>
/// <exception cref="InvalidOperationException">No process is associated with this object.</exception>
Comment thread
adamsitnik marked this conversation as resolved.
Outdated
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand All @@ -224,6 +228,8 @@ 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).
/// </summary>
/// <remarks>The value can be retrieved after the process exits.</remarks>
/// <exception cref="InvalidOperationException">No process is associated with this object.</exception>
Comment thread
adamsitnik marked this conversation as resolved.
Outdated
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ public bool HasExited
}

/// <summary>Gets the time the associated process was started.</summary>
/// <remarks>
/// On Windows, this property can be read after the process exits.
/// On Unix, accessing this property caches its value. A cached value can be read after the process exits,
/// but the first access after exit throws <see cref="InvalidOperationException"/>.
/// </remarks>
/// <exception cref="InvalidOperationException">
/// No process is associated with this object, or the process exited on Unix before the property was accessed.
/// </exception>
Comment thread
adamsitnik marked this conversation as resolved.
Comment thread
adamsitnik marked this conversation as resolved.
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
Expand All @@ -203,11 +211,8 @@ public DateTime StartTime
}
}

/// <devdoc>
/// <para>
/// Gets the time that the associated process exited.
/// </para>
/// </devdoc>
/// <summary>Gets the time that the associated process exited.</summary>
/// <exception cref="InvalidOperationException">The process has not exited.</exception>
Comment thread
adamsitnik marked this conversation as resolved.
Outdated
public DateTime ExitTime
{
get
Expand Down
30 changes: 30 additions & 0 deletions src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,36 @@ public void TestExitTime()
Assert.InRange(p.ExitTime.ToUniversalTime(), timeBeforeProcessStart, DateTime.MaxValue);
}

[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS, "Process timing information is not supported on iOS/tvOS")]
Comment thread
adamsitnik marked this conversation as resolved.
Outdated
public void TimingProperties_AfterProcessExit()
{
Process process = CreateProcess();
Comment thread
adamsitnik marked this conversation as resolved.
Outdated
process.Start();
Assert.True(process.WaitForExit(WaitInMS));

Assert.Equal(RemoteExecutor.SuccessExitCode, process.ExitCode);
Assert.NotEqual(default, process.ExitTime);

if (OperatingSystem.IsWindows())
{
// Windows process handles retain timing information after the process exits.
Assert.InRange(process.StartTime, DateTime.MinValue, process.ExitTime);
Assert.InRange(process.PrivilegedProcessorTime, TimeSpan.Zero, TimeSpan.MaxValue);
Comment thread
Copilot marked this conversation as resolved.
Assert.InRange(process.TotalProcessorTime, TimeSpan.Zero, TimeSpan.MaxValue);
Assert.InRange(process.UserProcessorTime, TimeSpan.Zero, TimeSpan.MaxValue);
}
else
{
// Unix reaps child processes after exit. Processor times are unavailable, and StartTime was not
// accessed before exit and therefore was not cached.
Assert.Throws<InvalidOperationException>(() => process.StartTime);
Assert.Throws<InvalidOperationException>(() => process.PrivilegedProcessorTime);
Assert.Throws<InvalidOperationException>(() => process.TotalProcessorTime);
Assert.Throws<InvalidOperationException>(() => process.UserProcessorTime);
}
Comment thread
adamsitnik marked this conversation as resolved.
}

[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS, "libproc is not supported on iOS/tvOS")]
public void StartTime_GetNotStarted_ThrowsInvalidOperationException()
Expand Down
Loading