Skip to content
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 @@ -7,6 +7,7 @@ namespace System.Diagnostics
// hardware supports it. Otherwise, the class will fall back to DateTime
// and uses ticks as a measurement.

[DebuggerDisplay("{DebuggerDisplay,nq}")]
public partial class Stopwatch
{
private const long TicksPerMillisecond = 10000;
Expand Down Expand Up @@ -150,5 +151,7 @@ private long GetElapsedDateTimeTicks()
// convert high resolution perf counter to DateTime ticks
return unchecked((long)(GetRawElapsedTicks() * s_tickFrequency));
}

private string DebuggerDisplay => $"{Elapsed} (IsRunning = {_isRunning})";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@

<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetHostName.cs" Condition="'$(TargetPlatformIdentifier)' == 'Unix' or '$(TargetPlatformIdentifier)' == 'Browser'" Link="Common\Interop\Unix\System.Native\Interop.GetHostName.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.Libraries.cs" Link="Common\Interop\Unix\Interop.Libraries.cs" />
<Compile Include="$(CommonTestPath)System\Diagnostics\DebuggerAttributes.cs" Link="Common\System\Diagnostics\DebuggerAttributes.cs" />
<Compile Include="$(CommonTestPath)System\IO\PathFeatures.cs" Link="Common\System\IO\PathFeatures.cs" />
<Compile Include="$(CommonTestPath)System\ShouldNotBeInvokedException.cs" Link="Common\System\ShouldNotBeInvokedException.cs" />
<Compile Include="$(CommonTestPath)System\Security\Cryptography\ByteUtils.cs" Link="Common\System\Security\Cryptography\ByteUtils.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using Xunit;

Expand Down Expand Up @@ -95,6 +96,27 @@ public static void StartNewAndRestart()
}
}

[Fact]
public static void DebuggerAttributesValid()
{
DebuggerAttributes.ValidateDebuggerDisplayReferences(new Stopwatch());

Stopwatch watch = new Stopwatch();
Assert.Equal("00:00:00 (IsRunning = False)", GetDebuggerDisplayProperty(watch));
watch.Start();
Thread.Sleep(10);
Assert.Contains("(IsRunning = True)", GetDebuggerDisplayProperty(watch));
Assert.DoesNotContain("00:00:00 ", GetDebuggerDisplayProperty(watch));
watch.Stop();
Assert.Contains("(IsRunning = False)", GetDebuggerDisplayProperty(watch));
Assert.DoesNotContain("00:00:00 ", GetDebuggerDisplayProperty(watch));

static string GetDebuggerDisplayProperty(Stopwatch value)
{
return (string)typeof(Stopwatch).GetProperty("DebuggerDisplay", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(value);
}
}

[OuterLoop("Sleeps for relatively long periods of time")]
[Fact]
public static void ElapsedMilliseconds_WithinExpectedWindow()
Expand Down