Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/visualeyes/budgerigar
Browse files Browse the repository at this point in the history
  • Loading branch information
johncmckim committed Feb 5, 2016
2 parents 4cfc639 + 06573a1 commit 93616e0
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Timing\MiniProfilerTimerProvider.cs" />
<Compile Include="Timing\MiniProfilerTimerMonitor.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Budgerigar.MiniProfiler.nuspec">
Expand Down
41 changes: 41 additions & 0 deletions src/Budgerigar.MiniProfiler/Timing/MiniProfilerTimerMonitor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Budgerigar.Timing;
using StackExchange.Profiling;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Budgerigar.MiniProfilerProvider.Timing {
public class MiniProfilerTimerMonitor : IPerformanceTimerMonitor {
private readonly string name;
private readonly MiniProfiler profiler;

public MiniProfilerTimerMonitor(string name) {
this.name = name;

profiler = new MiniProfiler(name);
}

public string Name { get { return this.name; } }

public IDisposable Step(string name) {
return this.profiler.Step(name);
}

public PerformanceTimerResult Stop() {
profiler.Root.Stop();

decimal? duration = profiler.Root.DurationMilliseconds;

if(!duration.HasValue) {
return null;
}

var stepResults = profiler.GetTimingHierarchy()
.Select(t => new PerformanceStepResult(t.Name, t.DurationMilliseconds));

return new PerformanceTimerResult(duration.Value, stepResults);
}
}
}
33 changes: 3 additions & 30 deletions src/Budgerigar.MiniProfiler/Timing/MiniProfilerTimerProvider.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,14 @@
using Budgerigar.Timing;
using StackExchange.Profiling;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Budgerigar.MiniProfilerProvider.Timing {
public class MiniProfilerTimerProvider : IPerformanceTimerMonitor {
private readonly string name;
private readonly MiniProfiler profiler;

public MiniProfilerTimerProvider(string name) {
this.name = name;

profiler = new MiniProfiler(name);
}

public string Name { get { return this.name; } }

public IDisposable Step(string name) {
return this.profiler.Step(name);
}

public PerformanceTimerResult Stop() {
profiler.Root.Stop();

decimal? duration = profiler.Root.DurationMilliseconds;

if(!duration.HasValue) {
return null;
}

var stepResults = profiler.GetTimingHierarchy()
.Select(t => new PerformanceStepResult(t.Name, t.DurationMilliseconds));

return new PerformanceTimerResult(duration.Value, stepResults);
public class MiniProfilerTimerProvider : IPerformanceTimerProvider {
public IPerformanceTimerMonitor Start(string name) {
return new MiniProfilerTimerMonitor(name);
}
}
}
6 changes: 6 additions & 0 deletions src/Budgerigar.Tests/Budgerigar.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
<Compile Include="Budgetting\PerformanceBudgetResultFacts.cs" />
<Compile Include="Budgetting\PerformanceBudgetterExtensionFacts.cs" />
<Compile Include="Budgetting\PerformanceBudgetterFacts.cs" />
<Compile Include="MiniProfiler\MiniProfilerTimerMonitorFacts.cs" />
<Compile Include="MiniProfiler\MiniProfilerTimerProviderFacts.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Timing\PerformanceStepResultFacts.cs" />
<Compile Include="Timing\PerformanceTimerExtensionsFacts.cs" />
Expand All @@ -78,6 +80,10 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Budgerigar.MiniProfiler\Budgerigar.MiniProfilerProvider.csproj">
<Project>{478dfd9a-a74a-44a3-afed-6217017f213d}</Project>
<Name>Budgerigar.MiniProfilerProvider</Name>
</ProjectReference>
<ProjectReference Include="..\Budgerigar\Budgerigar.csproj">
<Project>{38317b4a-7a62-48ec-8945-5205e0e9b4d0}</Project>
<Name>Budgerigar</Name>
Expand Down
57 changes: 57 additions & 0 deletions src/Budgerigar.Tests/MiniProfiler/MiniProfilerTimerMonitorFacts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Budgerigar.MiniProfilerProvider.Timing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Budgerigar.Tests.MiniProfiler {
public class MiniProfilerTimerMonitorFacts {

[Fact]
public void Create_Monitor() {
string name = "test";
var timer = new MiniProfilerTimerMonitor(name);
Assert.Equal(name, timer.Name);
}

[Fact]
public void Step_Returns() {
string name = "test";
var timer = new MiniProfilerTimerMonitor(name);

var step = timer.Step("test");

Assert.NotNull(step);
}

[Fact]
public void Stop_Returns_Result() {
string name = "test";
var timer = new MiniProfilerTimerMonitor(name);

var result = timer.Stop();

Assert.NotNull(result);
Assert.NotNull(result.Steps);
Assert.Equal(1, result.Steps.Count());
}

[Fact]
public void Stop_With_Steps_Returns_Result() {
string name = "test";
var timer = new MiniProfilerTimerMonitor(name);

using (timer.Step("test")) {
// do nothing
}

var result = timer.Stop();

Assert.NotNull(result);
Assert.NotNull(result.Steps);
Assert.Equal(2, result.Steps.Count());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Budgerigar.MiniProfilerProvider.Timing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Budgerigar.Tests.MiniProfiler {
public class MiniProfilerTimerProviderFacts {

[Fact]
public void Creates_Timer() {
string name = "test";

var provider = new MiniProfilerTimerProvider();
var timer = provider.Start(name) as MiniProfilerTimerMonitor;

Assert.NotNull(timer);
Assert.Equal(name, timer.Name);
}
}
}

0 comments on commit 93616e0

Please sign in to comment.