LeeCampbell / HdrHistogram.NET

Port of the HdrHistorgram to .NET/C#
Other
18 stars 3 forks source link

Abstract recording precision from consumer #14

Closed LeeCampbell closed 7 years ago

LeeCampbell commented 8 years ago

Make it easy to measure with this as the default

void RecordLatencyInTicks(this HistogramBase histogram, Action action)
{
    var start = Stopwatch.GetTimestamp();
    action();
    var elapsedTicks = Stopwatch.GetTimestamp() - start;
    histogram.RecordValue(elapsedTicks);
}

Ideally we just want to get a Histogram

var histogram = Histogram.Create()
    .AsLong()   //WTF to I get from this? --Can I prove the tradeoffs? is short or int faster/Smaller? I hope not, then I can delete them.
    .WithTickPrecision()
    .AsThreadSafe()
    .Create()

then call

histogram.RecordLatency(()=>{...});

then output the results

historgram.OutputPercentileDistribution(Console.Out, OutputUnit.Milliseconds)

This allows consumers to not have to know about how it was constructed or how it will be charted

LeeCampbell commented 8 years ago

Make it easy for the default recording to be in Ticks, but if user's wanted to record values in different units then that should be easy too. I think that using ticks to measure over 2.5hrs could cause an overflow making a method like this inaccurate

public static void RecordLatency(this HistogramBase histogram, Action action)
{
    var start = Stopwatch.GetTimestamp();
    action();
    var elapsedTicks = (Stopwatch.GetTimestamp() - start);
    histogram.RecordValue(elapsedTicks);
}
LeeCampbell commented 8 years ago

Last comment is nonsense. The Stopwatch.GetTimestamp() returns ticks as a long. That give 29,000years of ticks.

LeeCampbell commented 8 years ago

Last comment is incorrect, Stopwatch.GetTimestamp(); returns a different type of Tick to TimeSpan.TicksPerSecond which is the ticks unit used in DateTime types.

Instead there are Stopwatch.Frequency ticks/units per second when using Stopwatch.GetTimestamp() which actually means we have up to ~88,000 years as a max value. Should be plenty.

LeeCampbell commented 7 years ago

Closed by https://github.com/HdrHistogram/HdrHistogram.NET/pull/32