Added PerfCounterAverageAndDeviation method to Playback samples

This commit is contained in:
RuslanGabitov 2014-01-21 10:23:15 -08:00
Родитель 57e4894252
Коммит 8ebbc3902c
1 изменённых файлов: 40 добавлений и 0 удалений

Просмотреть файл

@ -27,6 +27,7 @@ namespace TxSamples
CountAllTwoFiles();
CountAcrossHierarchies();
Count5SecWindow();
PerfCounterAverageAndDeviation();
}
#region Structured Mode
@ -226,6 +227,45 @@ namespace TxSamples
playback.Run();
}
static void PerfCounterAverageAndDeviation()
{
var playback = new Playback();
playback.AddPerfCounterTraces(@"BasicPerfCounters.blg");
var procTimeTotal = from ps in playback.GetObservable<PerformanceSample>()
where ps.CounterSet == "Processor" && ps.CounterName == "% Processor Time" && ps.Instance == "_Total"
select ps;
var powerSumBases = from ps in procTimeTotal
select new
{
s0_base = 1,
s1_base = ps.Value,
s2_base = ps.Value * ps.Value
};
var powerSums =
from window in
powerSumBases.Window(TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1), playback.Scheduler)
from a in window.Aggregate(new { s0 = 0, s1 = 0.0, s2 = 0.1 }, (acc, point) => new
{
s0 = acc.s0 + point.s0_base,
s1 = acc.s1 + point.s1_base,
s2 = acc.s2 + point.s2_base
})
select a;
var avgAndDeviation = from ps in powerSums
select new
{
Average = ps.s1 / ps.s0,
Deviation = Math.Sqrt((ps.s0 * ps.s2 - ps.s1 * ps.s1) / (ps.s0 * ps.s0 - 1))
};
avgAndDeviation.Subscribe(value => Console.WriteLine("Average: {0}, Deviation: {1}", value.Average, value.Deviation));
playback.Run();
}
#endregion
}
}