%@ CodeTemplate Language="C#" TargetLanguage="C#" Description="Perf diag template." %>
<%@ Property Name="ClassName" Type="System.String" Default="PerfCounterInfo" Category="Options" Description="ClassName." %>
<%@ Import Namespace="System.Diagnostics" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>
using System;
using System.Diagnostics;
namespace MbUnit.Core.Framework
{
public class <%= ClassName %>
{
#region Constructors
private <%= ClassName %>() {}
#endregion
#region Categories
<% foreach(PerformanceCounterCategory cat in PerformanceCounterCategory.GetCategories()){
if (!this.categories.Contains(cat.CategoryName))
continue;
try
{
PerformanceCounter[] counters=null;
bool hasInstance = cat.GetInstanceNames().Length!=0;
if (!hasInstance)
counters = cat.GetCounters();
else
counters = cat.GetCounters(cat.GetInstanceNames()[0]);
foreach(PerformanceCounter counter in counters) {};
%>
#region <%= cat.CategoryName %>
///
/// <%= cat.CategoryHelp %>
///
public sealed class <%= GetCategoryClassName(cat) %>
{
public const string CategoryName = @"<%= cat.CategoryName %>";
#region Constructors
private <%= GetCategoryClassName(cat) %>(){}
#endregion
<%foreach(PerformanceCounter counter in counters) {%>
#region <%= counter.CounterName %>
///
/// <%= counter.CounterHelp %>
///
public sealed class <%= GetCounterClassName(counter)%>
{
public const string CounterName = @"<%= counter.CounterName%>";
private <%= GetCounterClassName(counter)%>(){}
<% if (hasInstance){%>
///
/// Gets the value of the .
///
///
/// Value returned by
/// for the current instance.
///
public static float NextValue()
{
return NextValue(Process.GetCurrentProcess().ProcessName);
}
public static float NextValue(string instanceName)
{
return PerfCounterAssert.NextValue(
<%= GetCategoryClassName(cat) %>.CategoryName,
CounterName,
instanceName
);
}
<%}else{%>
///
/// Gets the value of the .
///
///
/// Value returned by .
///
public static float NextValue()
{
return PerfCounterAssert.NextValue(
<%= GetCategoryClassName(cat) %>.CategoryName,
CounterName,
null
);
}
<%}%>
}
#endregion
<%} // GetCounters %>
}
#endregion
<%
}catch(Exception)
{}
%>
<%} // GetCategories %>
#endregion
public static float NextValue(
string categoryName,
string counterName,
string instanceName
)
{
using (PerformanceCounter counter = new PerformanceCounter(
categoryName,
counterName,
instanceName,
true)
)
{
return counter.NextValue();
}
}
}
}