diff --git a/Aspects/ExecutionTimeMeasured.cs b/Aspects/ExecutionTimeMeasured.cs new file mode 100644 index 0000000..8599ee8 --- /dev/null +++ b/Aspects/ExecutionTimeMeasured.cs @@ -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"); + } + } +} diff --git a/Mycenae.csproj b/Mycenae.csproj index 912bc5b..8736b36 100644 --- a/Mycenae.csproj +++ b/Mycenae.csproj @@ -6,6 +6,7 @@ + diff --git a/Tasks/EndToEnd.cs b/Tasks/EndToEnd.cs index 2da1fd4..1bdfe4f 100644 --- a/Tasks/EndToEnd.cs +++ b/Tasks/EndToEnd.cs @@ -1,4 +1,5 @@ using Cassandra; +using Mycenae.Aspects; using Mycenae.Models; using NLog; using System; @@ -11,6 +12,7 @@ internal class EndToEnd : MigrationTask { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + [ExecutionTimeMeasured] internal override void Execute() { Logger.Info("Starting end-to-end migration..."); diff --git a/Tasks/Extraction.cs b/Tasks/Extraction.cs index fc099fe..33a2530 100644 --- a/Tasks/Extraction.cs +++ b/Tasks/Extraction.cs @@ -1,4 +1,5 @@ using Cassandra; +using Mycenae.Aspects; using Mycenae.Models; using NLog; using System; @@ -13,6 +14,7 @@ internal class Extraction : MigrationTask { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + [ExecutionTimeMeasured] internal override void Execute() { Logger.Info("Starting extraction phase..."); diff --git a/Tasks/Insertion.cs b/Tasks/Insertion.cs index 6c278cb..113b8e5 100644 --- a/Tasks/Insertion.cs +++ b/Tasks/Insertion.cs @@ -1,5 +1,6 @@ using Cassandra; using CsvHelper; +using Mycenae.Aspects; using Mycenae.Converters; using Mycenae.Models; using NLog; @@ -16,6 +17,7 @@ internal class Insertion : MigrationTask { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + [ExecutionTimeMeasured] internal override void Execute() { Logger.Info("Starting insertion phase..."); diff --git a/Tasks/MigrationTask.cs b/Tasks/MigrationTask.cs index dde9ee3..995b533 100644 --- a/Tasks/MigrationTask.cs +++ b/Tasks/MigrationTask.cs @@ -1,4 +1,5 @@ using Cassandra; +using Mycenae.Aspects; using Mycenae.Models; using Mycenae.Policies; using NLog; @@ -112,6 +113,7 @@ protected static IList GetColumnsInfo(string keyspace, string table) return results.Columns.Select(column => new CColumn(column.Name, column.Type)).ToList(); } + [ExecutionTimeMeasured] protected static async Task ExecuteInsertAsync(IList insertStatements) { Logger.Info($"Inserting {insertStatements.Count} records into table...");