Skip to content

Commit 34811c1

Browse files
committed
Just copy StopwatchStruct instead of importing PerformanceTypes dependency.
1 parent 060a985 commit 34811c1

File tree

8 files changed

+86
-8
lines changed

8 files changed

+86
-8
lines changed

BosunReporter/BosunReporter.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
<SpecificVersion>False</SpecificVersion>
3535
<HintPath>..\packages\Jil.2.9.0\lib\net45\Jil.dll</HintPath>
3636
</Reference>
37-
<Reference Include="PerformanceTypes, Version=0.9.0.1, Culture=neutral, processorArchitecture=MSIL">
38-
<HintPath>..\packages\PerformanceTypes.0.9.1-unstable1\lib\net45\PerformanceTypes.dll</HintPath>
39-
<Private>True</Private>
40-
</Reference>
4137
<Reference Include="Sigil, Version=4.4.0.0, Culture=neutral, PublicKeyToken=2d06c3494341c8ab, processorArchitecture=MSIL">
4238
<SpecificVersion>False</SpecificVersion>
4339
<HintPath>..\packages\Sigil.4.4.0\lib\net45\Sigil.dll</HintPath>
@@ -53,6 +49,7 @@
5349
</ItemGroup>
5450
<ItemGroup>
5551
<Compile Include="Attributes.cs" />
52+
<Compile Include="Infrastructure\StopwatchStruct.cs" />
5653
<Compile Include="Metrics\AggregateGauge.cs" />
5754
<Compile Include="Metrics\EventGauge.cs" />
5855
<Compile Include="Infrastructure\MetaData.cs" />

BosunReporter/BosunReporter.nuspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<tags>Bosun Time Series Alerting</tags>
1515
<dependencies>
1616
<dependency id="Jil" version="2.9.0"/>
17-
<dependency id="PerformanceTypes" version="(,1.0)"/>
1817
</dependencies>
1918
</metadata>
2019
<files>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using System.Runtime.Versioning;
4+
5+
namespace BosunReporter.Infrastructure
6+
{
7+
internal struct StopwatchStruct
8+
{
9+
private long _startTimestamp;
10+
private long _elapsed;
11+
12+
public bool IsRunning { get; private set; }
13+
14+
public long ElapsedTicks
15+
{
16+
get
17+
{
18+
if (IsRunning)
19+
{
20+
long timestamp;
21+
QueryPerformanceCounter(out timestamp);
22+
return _elapsed + (timestamp - _startTimestamp);
23+
}
24+
25+
return _elapsed;
26+
}
27+
}
28+
29+
public void Start()
30+
{
31+
if (!IsRunning)
32+
{
33+
IsRunning = true;
34+
QueryPerformanceCounter(out _startTimestamp);
35+
}
36+
}
37+
38+
public void Stop()
39+
{
40+
if (IsRunning)
41+
{
42+
long timestamp;
43+
QueryPerformanceCounter(out timestamp);
44+
IsRunning = false;
45+
_elapsed += timestamp - _startTimestamp;
46+
}
47+
}
48+
49+
public double GetElapsedMilliseconds()
50+
{
51+
return (double)ElapsedTicks / TicksPerMillisecond;
52+
}
53+
54+
/****************************************************************************************
55+
*
56+
* Static Members
57+
*
58+
****************************************************************************************/
59+
60+
private const long TicksPerMillisecond = 10000;
61+
private const long TicksPerSecond = TicksPerMillisecond * 1000;
62+
63+
public static readonly bool IsHighResolution;
64+
public static readonly long Frequency;
65+
public static readonly double TickFrequency;
66+
67+
static StopwatchStruct()
68+
{
69+
var succeeded = QueryPerformanceFrequency(out Frequency);
70+
if (!succeeded)
71+
throw new Exception("Unable to use QueryPerformanceCounter. The StopwatchStruct only supports high-resolution timings currently.");
72+
73+
IsHighResolution = true;
74+
TickFrequency = (double)TicksPerSecond / Frequency;
75+
}
76+
77+
[DllImport("kernel32.dll")]
78+
[ResourceExposure(ResourceScope.None)]
79+
public static extern bool QueryPerformanceCounter(out long value);
80+
81+
[DllImport("kernel32.dll")]
82+
[ResourceExposure(ResourceScope.None)]
83+
public static extern bool QueryPerformanceFrequency(out long value);
84+
}
85+
}

BosunReporter/MetricsCollector.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using System.Threading;
1212
using BosunReporter.Infrastructure;
1313
using Jil;
14-
using PerformanceTypes;
1514

1615
namespace BosunReporter
1716
{

BosunReporter/packages.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Jil" version="2.9.0" targetFramework="net45" userInstalled="true" />
4-
<package id="PerformanceTypes" version="0.9.1-unstable1" targetFramework="net45" userInstalled="true" />
54
<package id="Sigil" version="4.4.0" targetFramework="net45" userInstalled="true" />
65
</packages>
Binary file not shown.

packages/PerformanceTypes.0.9.1-unstable1/[Content_Types].xml

Lines changed: 0 additions & 1 deletion
This file was deleted.
Binary file not shown.

0 commit comments

Comments
 (0)