public void TestRates() { var time = new TimeProvider(); var r = new MultiIntervalStats( new[] { new NamedInterval { Name = "per second", TicksDuration = Stopwatch.Frequency, Unit = "second" } }, time.GetTimestamp); time.Timestamp = Stopwatch.Frequency * 2; Assert.True(r.Record(Stopwatch.Frequency + 10, 10)); Assert.True(r.Record(Stopwatch.Frequency + 30, 10)); Assert.True(r.Record(Stopwatch.Frequency + 10, 10)); time.Timestamp = Stopwatch.Frequency * 3; Assert.True(r.Record(Stopwatch.Frequency * 2 + 1, 20)); Assert.True(r.Record(Stopwatch.Frequency * 3 + 1, 10)); time.Timestamp = Stopwatch.Frequency * 10; Assert.True(r.Record(Stopwatch.Frequency * 9 + 1, 10)); Assert.Equal(70, r.RecordedTotal); var stat = r.GetStats().First(); Assert.Equal(0, stat.Min); //we skipped buckets // Assert.Equal(14, stat.Avg); //TODO: fix, unstable results, should not occur! Assert.Equal(30, stat.Max); }
public void MultiIntervalTest() { NamedInterval[] Intervals = { new NamedInterval { Unit = "second", Name = "Per Second", TicksDuration = Stopwatch.Frequency }, new NamedInterval { Unit = "minute", Name = "Per Minute", TicksDuration = Stopwatch.Frequency * 60 }, new NamedInterval { Unit = "15_mins", Name = "Per 15 Minutes", TicksDuration = Stopwatch.Frequency * 60 * 15 }, new NamedInterval { Unit = "hour", Name = "Per Hour", TicksDuration = Stopwatch.Frequency * 60 * 60 }, }; var s = new MultiIntervalStats(Intervals); for (long i = Stopwatch.Frequency * -1000; i < Stopwatch.Frequency * 5000; i += Stopwatch.Frequency / 2) { s.Record(i, 1); } }
public void JobComplete(IImageJobInstrumentation job) { IncrementCounter("image_jobs"); var timestamp = Stopwatch.GetTimestamp(); var s_w = job.SourceWidth.GetValueOrDefault(0); var s_h = job.SourceHeight.GetValueOrDefault(0); var f_w = job.FinalWidth.GetValueOrDefault(0); var f_h = job.FinalHeight.GetValueOrDefault(0); if (job.SourceWidth.HasValue && job.SourceHeight.HasValue) { var prefix = "source_multiple_"; if (s_w % 4 == 0 && s_h % 4 == 0) { counters.Increment(prefix + "4x4"); } if (s_w % 8 == 0 && s_h % 8 == 0) { counters.Increment(prefix + "8x8"); } if (s_w % 8 == 0) { counters.Increment(prefix + "8x"); } if (s_h % 8 == 0) { counters.Increment(prefix + "x8"); } if (s_w % 16 == 0 && s_h % 16 == 0) { counters.Increment(prefix + "16x16"); } } //(builder.SettingsModifier as PipelineConfig).GetImageBuilder var readPixels = job.SourceWidth.GetValueOrDefault(0) * job.SourceHeight.GetValueOrDefault(0); var wrotePixels = job.FinalWidth.GetValueOrDefault(0) * job.FinalHeight.GetValueOrDefault(0); if (readPixels > 0) { sourceMegapixels.Report(readPixels); sourceWidths.Report(s_w); sourceHeights.Report(s_h); sourceAspectRatios.Report(s_w * 100 / s_h); } if (wrotePixels > 0) { outputMegapixels.Report(wrotePixels); outputWidths.Report(f_w); outputHeights.Report(f_h); outputAspectRatios.Report(f_w * 100 / f_h); } if (readPixels > 0 && wrotePixels > 0) { scalingRatios.Report(s_w * 100 / f_w); scalingRatios.Report(s_h * 100 / f_h); } jobs.Record(timestamp, 1); decodedPixels.Record(timestamp, readPixels); encodedPixels.Record(timestamp, wrotePixels); job_times.Report(job.TotalTicks); decode_times.Report(job.DecodeTicks); encode_times.Report(job.EncodeTicks); job_other_time.Report(job.TotalTicks - job.DecodeTicks - job.EncodeTicks); if (job.SourceFileExtension != null) { var ext = job.SourceFileExtension.ToLowerInvariant().TrimStart('.'); counters.Increment("source_file_ext_" + ext); } PostJobQuery(job.FinalCommandKeys); NoticeDomains(job.ImageDomain, job.PageDomain); }