Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/api-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-version: 10.0.x

- name: Install Microsoft.DotNet.ApiCompat.Tool
run: dotnet tool install --global Microsoft.DotNet.ApiCompat.Tool
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
dotnet-version: 10.0.x

- name: Build
run: dotnet build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
dotnet-version: 10.0.x

- name: Build
run: dotnet build
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,6 @@ UpgradeLog*.XML
project.lock.json
.vs/
.vscode/

# BenchmarkDotNet
BenchmarkDotNet.Artifacts/
7 changes: 7 additions & 0 deletions Spiffy.Monitoring.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spiffy.Monitoring.Aws", "sr
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestWebApp", "tests\TestWebApp\TestWebApp.csproj", "{4DF62688-C556-4439-93C1-2E4562E07F42}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmarks", "tests\Benchmarks\Benchmarks.csproj", "{B1A2C3D4-E5F6-7890-ABCD-EF1234567890}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -65,6 +67,10 @@ Global
{4DF62688-C556-4439-93C1-2E4562E07F42}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4DF62688-C556-4439-93C1-2E4562E07F42}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4DF62688-C556-4439-93C1-2E4562E07F42}.Release|Any CPU.Build.0 = Release|Any CPU
{B1A2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1A2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1A2C3D4-E5F6-7890-ABCD-EF1234567890}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1A2C3D4-E5F6-7890-ABCD-EF1234567890}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -77,5 +83,6 @@ Global
{9AD4DAE4-10DB-4933-9A28-6D0F994ADC17} = {8DEB13B2-A275-40CB-8D0F-AA672DB5717E}
{E7E90469-1E8B-4204-9990-48CD0C42E481} = {8DEB13B2-A275-40CB-8D0F-AA672DB5717E}
{4DF62688-C556-4439-93C1-2E4562E07F42} = {2DF31750-1635-4C57-980C-23EA82B2DE53}
{B1A2C3D4-E5F6-7890-ABCD-EF1234567890} = {2DF31750-1635-4C57-980C-23EA82B2DE53}
EndGlobalSection
EndGlobal
38 changes: 31 additions & 7 deletions src/Spiffy.Monitoring/AutoTimer.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System;
using System.Diagnostics;

namespace Spiffy.Monitoring
{
internal class AutoTimer : ITimedContext
{
readonly Stopwatch _stopwatch = new Stopwatch();
private long _startTimestamp;
private double _accumulatedMs;
private bool _running;

public int Count { get; private set;}

Expand All @@ -14,11 +16,26 @@ public AutoTimer()
Start();
}

public double ElapsedMilliseconds => _stopwatch.Elapsed.TotalMilliseconds;
public double ElapsedMilliseconds
{
get
{
var ms = _accumulatedMs;
if (_running)
{
ms += GetElapsedMs(_startTimestamp);
}
return ms;
}
}

public void Dispose()
{
_stopwatch.Stop();
if (_running)
{
_accumulatedMs += GetElapsedMs(_startTimestamp);
_running = false;
}
}

public void Resume()
Expand All @@ -28,19 +45,26 @@ public void Resume()

public void StartOver()
{
_stopwatch.Reset();
_accumulatedMs = 0;
Count = 0;
_running = false;
Start();
}

void Start()
{
if (_stopwatch.IsRunning)
if (_running)
{
return;
}
Count++;
_stopwatch.Start();
_startTimestamp = Stopwatch.GetTimestamp();
_running = true;
}

private static double GetElapsedMs(long startTimestamp)
{
return (Stopwatch.GetTimestamp() - startTimestamp) * 1000.0 / Stopwatch.Frequency;
}
}
}
Loading
Loading