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
1 change: 1 addition & 0 deletions opentelemetry-dotnet-contrib.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
<File Path="src/Shared/SqlParameterProcessor.cs" />
<File Path="src/Shared/SqlProcessor.cs" />
<File Path="src/Shared/SqlStatementInfo.cs" />
<File Path="src/Shared/StopwatchExtensions.cs" />
<File Path="src/Shared/UriHelper.cs" />
</Folder>
<Folder Name="/src/Shared/AWS/">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,5 @@ public static TagList GetTagListFromConnectionInfo(string? dataSource, string? d
}

internal static double CalculateDurationFromTimestamp(long begin)
{
#if NET
var duration = Stopwatch.GetElapsedTime(begin);
#else
var end = Stopwatch.GetTimestamp();
var timestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency;
var delta = end - begin;
var ticks = (long)(timestampToTicks * delta);
var duration = new TimeSpan(ticks);
#endif

return duration.TotalSeconds;
}
=> Stopwatch.GetElapsedTime(begin).TotalSeconds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<Compile Include="$(RepoRoot)\src\Shared\SqlParameterProcessor.cs" Link="Includes\SqlParameterProcessor.cs" />
<Compile Include="$(RepoRoot)\src\Shared\SqlProcessor.cs" Link="Includes\SqlProcessor.cs" />
<Compile Include="$(RepoRoot)\src\Shared\SqlStatementInfo.cs" Link="Includes\SqlStatementInfo.cs" />
<Compile Include="$(RepoRoot)\src\Shared\StopwatchExtensions.cs" Link="Includes\StopwatchExtensions.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
25 changes: 25 additions & 0 deletions src/Shared/StopwatchExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#if !NET

namespace System.Diagnostics;

internal static class StopwatchExtensions
{
extension(Stopwatch)
{
public static TimeSpan GetElapsedTime(long begin)
{
var end = Stopwatch.GetTimestamp();

var timestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency;
var delta = end - begin;
var ticks = (long)(timestampToTicks * delta);

return new TimeSpan(ticks);
}
Comment thread
martincostello marked this conversation as resolved.
}
}

#endif
Loading