Skip to content

Commit 6964aea

Browse files
committed
Fix measuring duration of processor and command
## Processor Although the log outputs `Duration` of the processor activity, this is always zero. Its because `Duration` is not dynamic – it does not return real current duration. Its value is calculated and updated only when `Stop()` is called. ## Command base Basically the same problem as in `Processor`, but from the other side. The activity is stopped immediately after it is started, so it reports zero duration at the end. Even when the telemetry is disabled, there is no need to not measure duration of the command. Because even wihout telemetry, we want to see duration in the log outputs. And `Stop()` basically does nothing just updates duration.
1 parent 9a8779e commit 6964aea

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/MigrationTools.Host/Commands/CommandBase.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public sealed override async Task<int> ExecuteAsync(CommandContext context, TSet
6565
{
6666
Log.Debug("Disabling Telemetry {CommandName}", this.GetType().Name);
6767
CommandActivity.AddTag("DisableTelemetry", settings.DisableTelemetry);
68-
CommandActivity.Stop();
6968
ActivitySourceProvider.DisableActivitySource();
7069
}
7170
//Enable Debug Trace
@@ -105,7 +104,7 @@ public sealed override async Task<int> ExecuteAsync(CommandContext context, TSet
105104

106105
internal virtual Task<int> ExecuteInternalAsync(CommandContext context, TSettings settings)
107106
{
108-
return Task.FromResult( 0);
107+
return Task.FromResult(0);
109108
}
110109

111110
public void RunStartupLogic(TSettings settings)

src/MigrationTools/Processors/Infrastructure/Processor.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.ComponentModel.Design;
43
using System.Diagnostics;
54
using System.Linq;
65
using Microsoft.Extensions.DependencyInjection;
76
using Microsoft.Extensions.Logging;
87
using Microsoft.Extensions.Options;
9-
using MigrationTools._EngineV1.Configuration;
108
using MigrationTools.Endpoints;
11-
using MigrationTools.Endpoints.Infrastructure;
129
using MigrationTools.Enrichers;
1310
using MigrationTools.Exceptions;
1411
using MigrationTools.Services;
@@ -139,6 +136,7 @@ public void Execute()
139136
}
140137
finally
141138
{
139+
ProcessorActivity.Stop();
142140
Log.LogInformation("{ProcessorName} completed in {ProcessorDuration} ", Name, ProcessorActivity.Duration.ToString("c"));
143141
}
144142

@@ -172,4 +170,4 @@ protected static void AddParameter(string name, IDictionary<string, string> stor
172170
if (!store.ContainsKey(name)) store.Add(name, value);
173171
}
174172
}
175-
}
173+
}

0 commit comments

Comments
 (0)