-
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.
Create/apply aspect in order to measure execution time
- Loading branch information
1 parent
cb3628f
commit f235c9b
Showing
6 changed files
with
39 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using AspectInjector.Broker; | ||
using NLog; | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace Mycenae.Aspects | ||
{ | ||
[Aspect(Scope.PerInstance)] | ||
[Injection(typeof(ExecutionTimeMeasured))] | ||
public class ExecutionTimeMeasured : Attribute | ||
{ | ||
private readonly ILogger _logger = LogManager.GetCurrentClassLogger(); | ||
private Stopwatch _stopwatch; | ||
|
||
[Advice(Kind.Before)] | ||
public void StartMeasurement() | ||
{ | ||
_stopwatch = Stopwatch.StartNew(); | ||
} | ||
|
||
[Advice(Kind.After)] | ||
public void FinishMeasurement([Argument(Source.Name)] string name) | ||
{ | ||
_stopwatch.Stop(); | ||
|
||
_logger.Info($"Time elapsed ({name}): {_stopwatch.Elapsed.Hours}h:{_stopwatch.Elapsed.Minutes}m:" + | ||
$"{_stopwatch.Elapsed.Seconds}s:{_stopwatch.Elapsed.Milliseconds}ms"); | ||
} | ||
} | ||
} |
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
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
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
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
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