The next version of MbUnit (2.20) will have a new custom attribute that will let you assert on the values of PerformanceCounters: PerfCounterAttribute. (Idea suggested by ISerializable). This means that you can make an assertion an every perfomance counter on your machine!
Here's a sample fixture that shows how the attribute can be used:
using System; using MbUnit.Core.Framework; using MbUnit.Framework; namespace MbUnit.Demo { [TestFixture] public class PerfCounterDemo { [Test] [PerfCounter(".NET CLR Memory", "% Time in GC", 10)] public void AllocateALotOfObjects() { ... } [Test] [PerfCounter(".NET CLR Loading", "% Time Loading", 10)] [PerfCounter(".NET CLR Security", "% Time in RT checks", 10000)] [PerfCounter(".NET CLR Security", "% Time Sig. Authenticating", 10)] [PerfCounter(".NET CLR Memory", "# Bytes in all Heaps", 5000000, Relative =true)] [PerfCounter(".NET CLR Jit", "% Time in Jit", 10)] public void MonitorMultipleCounters() { ... } } }
Note that if you are too lazy to remember the names of the counters, I have written a CodeSmith template that creates a class filled with static helper methods for retreiving the counters. For example, the following class lets you write things like PerfCounterInfo.NetClrExceptions.NbofExcepsThrown.NextValue() using intellisense and without typing errors :)
using System; using System.Diagnostics; namespace MbUnit.Core.Framework { public class PerfCounterInfo { public sealed class NetClrExceptions { const string categoryName = @".NET CLR Exceptions"; public sealed class NbofExcepsThrown { const string counterName = @"# of Exceps Thrown"; public static float NextValue() { return NextValue(Process.GetCurrentProcess().ProcessName); } } ...
Page rendered at Thursday, July 24, 2008 5:06:04 AM UTC
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.