Skip to content

Reported durations are 100x too large on Linux #597

@benbryant0

Description

@benbryant0

The durations reported by MiniProfiler when run on Linux are 100x larger than they should be.

This is caused by the change here which was released as 4.2.43.

Stopwatch ticks are not the same as DateTime or TimeSpan ticks (because that's not going to confuse anyone 🙄) so using TimeSpan.TicksPerMillisecond to convert is not reliable. Previous versions of MiniProfiler correctly used Stopwatch.Frequency to account for this. See this doc page for an explanation: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.stopwatch.elapsedticks?view=net-6.0#remarks

Simple example comparing Ubuntu & Windows output:

image

using StackExchange.Profiling;
using System.Diagnostics;

var stopwatch = Stopwatch.StartNew();
Thread.Sleep(1000);
stopwatch.Stop();

Console.WriteLine(@$"Running under: {System.Runtime.InteropServices.RuntimeInformation.RuntimeIdentifier}
Stopwatch:
    ElapsedTicks: {stopwatch.ElapsedTicks}
    ElapsedMilliseconds: {stopwatch.ElapsedMilliseconds}
TimeSpan.TicksPerMillisecond: {TimeSpan.TicksPerMillisecond}");

var profiler = new MiniProfiler("", new());

using (var _ = profiler.Step("")) {
    Thread.Sleep(1000);
}

profiler.Stop();

Console.WriteLine($"Profiler duration ms: {profiler.DurationMilliseconds}");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions