< Summary

Class:Azure.Core.Diagnostics.ValueStopwatch
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\ValueStopwatch.cs
Covered lines:0
Uncovered lines:11
Coverable lines:11
Total lines:42
Line coverage:0% (0 of 11)
Covered branches:0
Total branches:2
Branch coverage:0% (0 of 2)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-0%100%
get_IsActive()-0%100%
.ctor(...)-0%100%
StartNew()-0%100%
GetElapsedTime()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\Shared\ValueStopwatch.cs

#LineLine coverage
 1#pragma warning disable SA1636
 2// Copyright (c) .NET Foundation. All rights reserved.
 3// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 4#pragma warning restore SA1636
 5
 6using System;
 7using System.Diagnostics;
 8
 9namespace Azure.Core.Diagnostics
 10{
 11    // https://github.com/dotnet/aspnetcore/blob/master/src/Shared/ValueStopwatch/ValueStopwatch.cs
 12    internal struct ValueStopwatch
 13    {
 014        private static readonly double TimestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency;
 15
 16        private long _startTimestamp;
 17
 018        public bool IsActive => _startTimestamp != 0;
 19
 20        private ValueStopwatch(long startTimestamp)
 21        {
 022            _startTimestamp = startTimestamp;
 023        }
 24
 025        public static ValueStopwatch StartNew() => new ValueStopwatch(Stopwatch.GetTimestamp());
 26
 27        public TimeSpan GetElapsedTime()
 28        {
 29            // Start timestamp can't be zero in an initialized ValueStopwatch. It would have to be literally the first t
 30            // So it being 0 is a clear indication of default(ValueStopwatch)
 031            if (!IsActive)
 32            {
 033                throw new InvalidOperationException("An uninitialized, or 'default', ValueStopwatch cannot be used to ge
 34            }
 35
 036            var end = Stopwatch.GetTimestamp();
 037            var timestampDelta = end - _startTimestamp;
 038            var ticks = (long)(TimestampToTicks * timestampDelta);
 039            return new TimeSpan(ticks);
 40        }
 41    }
 42}