< Summary

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

Metrics

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

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    {
 214        private static readonly double TimestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency;
 15
 16        private long _startTimestamp;
 17
 30818        public bool IsActive => _startTimestamp != 0;
 19
 20        private ValueStopwatch(long startTimestamp)
 21        {
 34822            _startTimestamp = startTimestamp;
 34823        }
 24
 34825        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)
 30831            if (!IsActive)
 32            {
 033                throw new InvalidOperationException("An uninitialized, or 'default', ValueStopwatch cannot be used to ge
 34            }
 35
 30836            var end = Stopwatch.GetTimestamp();
 30837            var timestampDelta = end - _startTimestamp;
 30838            var ticks = (long)(TimestampToTicks * timestampDelta);
 30839            return new TimeSpan(ticks);
 40        }
 41    }
 42}