PerformanceCounters Class

MSBuild Extension Pack

PerformanceCounters Class MSBuild Extension Pack Help 4.0.12.0
Valid TaskActions are:

Add (Required: CategoryName, CounterList, CategoryHelp Optional: MultiInstance, KeepExistingCounters)

CheckCategoryExists (Required: CategoryName Optional: MachineName)

CheckCounterExists (Required: CategoryName, CounterName Optional: MachineName)

GetValue (Required: CategoryName, CounterName Output: Value, MachineName)

Remove (Required: CategoryName)

Remote Execution Support: Partial

Inheritance Hierarchy

SystemObject  Microsoft.Build.UtilitiesTask
    MSBuild.ExtensionPackBaseTask
      MSBuild.ExtensionPack.ComputerPerformanceCounters

Namespace: MSBuild.ExtensionPack.Computer
Assembly: MSBuild.ExtensionPack (in MSBuild.ExtensionPack.dll) Version: 4.0.0.0

The PerformanceCounters type exposes the following members.

Constructors

  NameDescription
Public methodPerformanceCounters
Top
Properties

  NameDescription
Public propertyCategoryHelp
Sets the description of the custom category.
Public propertyCategoryName
Sets the CategoryName
Public propertyCounterList
Sets the TaskItem[] that specifies the counters to create as part of the new category.
Public propertyCounterName
Sets the name of the counter.
Public propertyExists
Gets whether the item exists
Public propertyKeepExistingCounters
Sets a value whether existing performance counters of the given category should be preserved when adding new ones.
Public propertyMultiInstance
Sets a value indicating whether to create a multiple instance performance counter. Default is false
Public propertyValue
Gets the value of the counter
Top
Examples

<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <TPath>$(MSBuildProjectDirectory)\..\MSBuild.ExtensionPack.tasks</TPath>
        <TPath Condition="Exists('$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks')">$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks</TPath>
    </PropertyGroup>
    <Import Project="$(TPath)"/>
    <Target Name="Default">
        <ItemGroup>
            <!-- Configure some perf counters -->
            <CounterList Include="foobar.A">
                <CounterName>ACounter</CounterName>
                <CounterHelp>A Custom Counter</CounterHelp>
                <CounterType>CounterTimer</CounterType>
            </CounterList>
            <CounterList Include="foobar.A">
                <CounterName>AnotherCounter</CounterName>
                <CounterHelp>Another Custom Counter</CounterHelp>
                <CounterType>CounterTimer</CounterType>
            </CounterList>
        </ItemGroup>
        <!-- Add a Performance Counter -->
        <MSBuild.ExtensionPack.Computer.PerformanceCounters TaskAction="Add" CategoryName="YourCustomCategory" CategoryHelp="This is a custom performance counter category" CounterList="@(CounterList)" MultiInstance="true" />
        <!-- Check whether a Category Exists -->
        <MSBuild.ExtensionPack.Computer.PerformanceCounters TaskAction="CheckCategoryExists" CategoryName="aYourCustomCategory">
            <Output TaskParameter="Exists" PropertyName="DoesExist"/>
        </MSBuild.ExtensionPack.Computer.PerformanceCounters>
        <Message Text="aYourCustomCategory - $(DoesExist)"/>
        <!-- Check whether a Counter Exists -->
        <MSBuild.ExtensionPack.Computer.PerformanceCounters TaskAction="CheckCounterExists" CategoryName="aYourCustomCategory" CounterName="AnotherCounter">
            <Output TaskParameter="Exists" PropertyName="DoesExist"/>
        </MSBuild.ExtensionPack.Computer.PerformanceCounters>
        <Message Text="AnotherCounter - $(DoesExist)"/>
        <!-- Remove a Performance Counter -->
        <MSBuild.ExtensionPack.Computer.PerformanceCounters TaskAction="Remove" CategoryName="YourCustomCategory"/>
        <!-- Get a Performance Counter value-->
        <MSBuild.ExtensionPack.Computer.PerformanceCounters TaskAction="GetValue" CategoryName="Memory" CounterName="Available MBytes">
            <Output PropertyName="TheValue" TaskParameter="Value"/>
        </MSBuild.ExtensionPack.Computer.PerformanceCounters>
        <Message Text="Available MBytes: $(TheValue)"/>
    </Target>
</Project>
See Also

Reference