-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/visualeyes/budgerigar
- Loading branch information
Showing
6 changed files
with
131 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/Budgerigar.MiniProfiler/Timing/MiniProfilerTimerMonitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
33
src/Budgerigar.MiniProfiler/Timing/MiniProfilerTimerProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/Budgerigar.Tests/MiniProfiler/MiniProfilerTimerMonitorFacts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Budgerigar.Tests/MiniProfiler/MiniProfilerTimerProviderFacts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |