本文整理汇总了C#中System.Diagnostics.CounterCreationData类的典型用法代码示例。如果您正苦于以下问题:C# CounterCreationData类的具体用法?C# CounterCreationData怎么用?C# CounterCreationData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CounterCreationData类属于System.Diagnostics命名空间,在下文中一共展示了CounterCreationData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadTestStarting
private void LoadTestStarting(object sender, EventArgs e)
{
// Delete the category if already exists
if (PerformanceCounterCategory.Exists("AMSStressCounterSet"))
{
PerformanceCounterCategory.Delete("AMSStressCounterSet");
}
CounterCreationDataCollection counters = new CounterCreationDataCollection();
// 1. counter for counting totals: PerformanceCounterType.NumberOfItems32
CounterCreationData totalOps = new CounterCreationData();
totalOps.CounterName = "# operations executed";
totalOps.CounterHelp = "Total number of operations executed";
totalOps.CounterType = PerformanceCounterType.NumberOfItems32;
counters.Add(totalOps);
// 2. counter for counting operations per second:
// PerformanceCounterType.RateOfCountsPerSecond32
CounterCreationData opsPerSecond = new CounterCreationData();
opsPerSecond.CounterName = "# operations / sec";
opsPerSecond.CounterHelp = "Number of operations executed per second";
opsPerSecond.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
counters.Add(opsPerSecond);
// create new category with the counters above
PerformanceCounterCategory.Create("AMSStressCounterSet", "KeyDelivery Stress Counters", PerformanceCounterCategoryType.SingleInstance, counters);
}
示例2: GetOrCreateCounterCategory
/// <summary>
/// Gets the or create counter category.
/// </summary>
/// <param name="categoryInfo">The category information.</param>
/// <param name="counters">The counters.</param>
/// <returns>PerformanceCounterCategory.</returns>
private static PerformanceCounterCategory GetOrCreateCounterCategory(
PerformanceCounterCategoryInfo categoryInfo, CounterCreationData[] counters)
{
var creationPending = true;
var categoryExists = false;
var categoryName = categoryInfo.CategoryName;
var counterNames = new HashSet<string>(counters.Select(info => info.CounterName));
PerformanceCounterCategory category = null;
if (PerformanceCounterCategory.Exists(categoryName))
{
categoryExists = true;
category = new PerformanceCounterCategory(categoryName);
var counterList = category.GetCounters();
if (category.CategoryType == categoryInfo.CategoryType && counterList.Length == counterNames.Count)
{
creationPending = counterList.Any(x => !counterNames.Contains(x.CounterName));
}
}
if (!creationPending) return category;
if (categoryExists)
PerformanceCounterCategory.Delete(categoryName);
var counterCollection = new CounterCreationDataCollection(counters);
category = PerformanceCounterCategory.Create(
categoryInfo.CategoryName,
categoryInfo.CategoryHelp,
categoryInfo.CategoryType,
counterCollection);
return category;
}
示例3: SetupCategory
private static void SetupCategory()
{
if (PerformanceCounterCategory.Exists(CategoryName))
{
PerformanceCounterCategory.Delete(CategoryName);
}
if (!PerformanceCounterCategory.Exists(CategoryName))
{
CounterCreationDataCollection creationDataCollection =
new CounterCreationDataCollection();
CounterCreationData ctrCreationData = new CounterCreationData();
ctrCreationData.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
ctrCreationData.CounterName = SpeedCounterName;
creationDataCollection.Add(ctrCreationData);
CounterCreationData ctrCreationData2 = new CounterCreationData();
ctrCreationData2.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
ctrCreationData2.CounterName = SpeedBytesCounterName;
creationDataCollection.Add(ctrCreationData2);
PerformanceCounterCategory.Create(CategoryName,
"Sample TransVault category",
PerformanceCounterCategoryType.MultiInstance,
creationDataCollection);
}
}
示例4: InstallCounters
/// <summary>
/// install thge perfmon counters
/// </summary>
public static void InstallCounters()
{
if (!PerformanceCounterCategory.Exists(BabaluCounterDescriptions.CounterCategory))
{
//Create the collection that will hold
// the data for the counters we are
// creating.
CounterCreationDataCollection counterData = new CounterCreationDataCollection();
//Create the CreationData object.
foreach (string counter in BabaluCounterDescriptions.BabaluCounters)
{
CounterCreationData BabaluCounter = new CounterCreationData();
// Set the counter's type to NumberOfItems32
BabaluCounter.CounterType = PerformanceCounterType.NumberOfItems32;
//Set the counter's name
BabaluCounter.CounterName = counter;
//Add the CreationData object to our
//collection
counterData.Add(BabaluCounter);
}
//Create the counter in the system using the collection.
PerformanceCounterCategory.Create(BabaluCounterDescriptions.CounterCategory, BabaluCounterDescriptions.CategoryDescription,
PerformanceCounterCategoryType.SingleInstance, counterData);
}
}
示例5: InstallCounters
/// <summary>
/// Starts the install
/// </summary>
public static void InstallCounters()
{
Logger.Debug("Starting installation of PerformanceCounters ");
var categoryName = "NServiceBus";
var counterName = "Critical Time";
if (PerformanceCounterCategory.Exists(categoryName))
{
Logger.Warn("Category " + categoryName + " already exist, going to delete first");
PerformanceCounterCategory.Delete(categoryName);
}
var data = new CounterCreationDataCollection();
var c1 = new CounterCreationData(counterName, "Age of the oldest message in the queue",
PerformanceCounterType.NumberOfItems32);
data.Add(c1);
PerformanceCounterCategory.Create(categoryName, "NServiceBus statistics",
PerformanceCounterCategoryType.MultiInstance, data);
Logger.Debug("Installation of PerformanceCounters successful.");
}
示例6: CreateCounter
public static void CreateCounter()
{
CounterCreationDataCollection col = new CounterCreationDataCollection();
// Create two custom counter objects.
CounterCreationData addCounter = new CounterCreationData();
addCounter.CounterName = "AddCounter";
addCounter.CounterHelp = "Custom Add counter ";
addCounter.CounterType = PerformanceCounterType.NumberOfItemsHEX32;
// Add custom counter objects to CounterCreationDataCollection.
col.Add(addCounter);
// Bind the counters to a PerformanceCounterCategory
// Check if the category already exists or not.
if (!PerformanceCounterCategory.Exists("MyCategory"))
{
PerformanceCounterCategory category =
PerformanceCounterCategory.Create("MyCategory", "My Perf Category Description ", PerformanceCounterCategoryType.Unknown, col);
}
else
{
Console.WriteLine("Counter already exists");
}
}
示例7: InitializeClicked
private void InitializeClicked(object sender, RoutedEventArgs e)
{
if (PerformanceCounterCategory.Exists(CategoryName))
{
PerformanceCounterCategory.Delete(CategoryName);
}
if (!PerformanceCounterCategory.Exists(CategoryName))
{
CounterCreationDataCollection creationDataCollection =
new CounterCreationDataCollection();
CounterCreationData ctrCreationData = new CounterCreationData();
ctrCreationData.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
ctrCreationData.CounterName = SpeedCounterName;
creationDataCollection.Add(ctrCreationData);
CounterCreationData ctrCreationData2 = new CounterCreationData();
ctrCreationData2.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
ctrCreationData2.CounterName = SpeedBytesCounterName;
creationDataCollection.Add(ctrCreationData2);
PerformanceCounterCategory.Create(CategoryName,
"Sample Custom category",
PerformanceCounterCategoryType.MultiInstance,
creationDataCollection);
}
currentContainer = new CountersContainer()
{
BytesPerSecCounter = SetupCounter(CategoryName, SpeedCounterName, "Task " + currentTask),
ItemsPerSecCounter = SetupCounter(CategoryName, SpeedBytesCounterName, "Task " + currentTask)
};
}
示例8: CreateCounters
private static void CreateCounters(string groupName)
{
if (PerformanceCounterCategory.Exists(groupName))
{
PerformanceCounterCategory.Delete(groupName);
}
var counters = new CounterCreationDataCollection();
var totalOps = new CounterCreationData
{
CounterName = "Messages Read",
CounterHelp = "Total number of messages read",
CounterType = PerformanceCounterType.NumberOfItems32
};
counters.Add(totalOps);
var opsPerSecond = new CounterCreationData
{
CounterName = "Messages Read / Sec",
CounterHelp = "Messages read per second",
CounterType = PerformanceCounterType.RateOfCountsPerSecond32
};
counters.Add(opsPerSecond);
PerformanceCounterCategory.Create(groupName, "PVC", PerformanceCounterCategoryType.SingleInstance, counters);
}
示例9: CustomInstaller
public CustomInstaller()
{
string loadPerf = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\loadperf.dll";
if (File.Exists(loadPerf))
{
// add in a perf mon installer
PerformanceCounterInstaller p = new PerformanceCounterInstaller();
p.CategoryName = Resources.PerfMonCategoryName;
p.CategoryHelp = Resources.PerfMonCategoryHelp;
p.CategoryType = PerformanceCounterCategoryType.SingleInstance;
CounterCreationData ccd1 = new CounterCreationData(
Resources.PerfMonHardProcName,
Resources.PerfMonHardProcHelp,
PerformanceCounterType.NumberOfItems32);
CounterCreationData ccd2 = new CounterCreationData(
Resources.PerfMonSoftProcName,
Resources.PerfMonSoftProcHelp,
PerformanceCounterType.RateOfCountsPerSecond32);
p.Counters.Add(ccd1);
p.Counters.Add(ccd2);
perfMonIndex = Installers.Add(p);
}
}
示例10: AddRange
public void AddRange (CounterCreationData[] value)
{
foreach (CounterCreationData v in value)
{
Add (v);
}
}
示例11: SetupCategory
private bool SetupCategory()
{
// PerformanceCounterCategory.Delete("DCC2012");
if (!PerformanceCounterCategory.Exists(this.categoryName))
{
CounterCreationDataCollection counterDataCollection = new CounterCreationDataCollection();
// Add the counter.
CounterCreationData averageCount64 = new CounterCreationData();
averageCount64.CounterType = PerformanceCounterType.NumberOfItems32;
averageCount64.CounterName = "GetData Call Count";
counterDataCollection.Add(averageCount64);
CounterCreationData averageCount641 = new CounterCreationData();
averageCount641.CounterType = PerformanceCounterType.CounterTimer;
averageCount641.CounterName = "GetData Execution Time";
counterDataCollection.Add(averageCount641);
// Create the category.
PerformanceCounterCategory.Create("DCC2012", "Desert Code Camp.",
PerformanceCounterCategoryType.SingleInstance, counterDataCollection);
return (true);
}
else
{
Console.WriteLine("Category exists - AverageCounter64SampleCategory");
return (false);
}
}
示例12: Main
static void Main(string[] args)
{
if (PerformanceCounterCategory.Exists("DontStayIn"))
PerformanceCounterCategory.Delete("DontStayIn");
// Create the collection container
CounterCreationDataCollection counters = new CounterCreationDataCollection();
// Create counter #1 and add it to the collection
CounterCreationData dsiPages = new CounterCreationData();
dsiPages.CounterName = "DsiPages per sec";
dsiPages.CounterHelp = "Total number of dsi pages per second.";
dsiPages.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
counters.Add(dsiPages);
// Create counter #3 and add it to the collection
CounterCreationData genTime = new CounterCreationData();
genTime.CounterName = "DsiPage generation time";
genTime.CounterHelp = "Average time to generate a page.";
genTime.CounterType = PerformanceCounterType.AverageTimer32;
counters.Add(genTime);
CounterCreationData genTimeBase = new CounterCreationData();
genTimeBase.CounterName = "DsiPage generation time base";
genTimeBase.CounterHelp = "Average time to generate a page base.";
genTimeBase.CounterType = PerformanceCounterType.AverageBase;
counters.Add(genTimeBase);
// Create the category and all of the counters.
PerformanceCounterCategory.Create("DontStayIn", "Performance counters for DontStayIn.", PerformanceCounterCategoryType.SingleInstance, counters);
Console.WriteLine("Done!");
Console.ReadLine();
}
示例13: InitializeCounters
private static void InitializeCounters()
{
try
{
var counterDatas =
new CounterCreationDataCollection();
// Create the counters and set their properties.
var cdCounter1 =
new CounterCreationData();
var cdCounter2 =
new CounterCreationData();
cdCounter1.CounterName = "Total Requests Handled";
cdCounter1.CounterHelp = "Total number of requests handled";
cdCounter1.CounterType = PerformanceCounterType.NumberOfItems64;
cdCounter2.CounterName = "Requests Per Secpmd";
cdCounter2.CounterHelp = "Average number of requests per second.";
cdCounter2.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
// Add both counters to the collection.
counterDatas.Add(cdCounter1);
counterDatas.Add(cdCounter2);
// Create the category and pass the collection to it.
PerformanceCounterCategory.Create(
"Socket Service Data Stats", "Stats for the socket service.",
PerformanceCounterCategoryType.MultiInstance, counterDatas);
}
catch (Exception ex)
{
Logger.Error(ex.ToString());
}
}
示例14: CreatePerformanceCategory
public void CreatePerformanceCategory()
{
const string category = "MikePerfSpike";
if (!PerformanceCounterCategory.Exists(category))
{
var counters = new CounterCreationDataCollection();
// 1. counter for counting values
var totalOps = new CounterCreationData
{
CounterName = "# of operations executed",
CounterHelp = "Total number of operations that have been executed",
CounterType = PerformanceCounterType.NumberOfItems32
};
counters.Add(totalOps);
// 2. counter for counting operations per second
var opsPerSecond = new CounterCreationData
{
CounterName = "# of operations/second",
CounterHelp = "Number of operations per second",
CounterType = PerformanceCounterType.RateOfCountsPerSecond32
};
counters.Add(opsPerSecond);
PerformanceCounterCategory.Create(
category,
"An experiment",
PerformanceCounterCategoryType.MultiInstance,
counters);
}
}
示例15: InstallPerformanceCounters
private void InstallPerformanceCounters()
{
if (!PerformanceCounterCategory.Exists("nHydrate"))
{
var counters = new CounterCreationDataCollection();
// 1. counter for counting totals: PerformanceCounterType.NumberOfItems32
var totalAppointments = new CounterCreationData();
totalAppointments.CounterName = "# appointments processed";
totalAppointments.CounterHelp = "Total number of appointments processed.";
totalAppointments.CounterType = PerformanceCounterType.NumberOfItems32;
counters.Add(totalAppointments);
// 2. counter for counting operations per second:
// PerformanceCounterType.RateOfCountsPerSecond32
var appointmentsPerSecond = new CounterCreationData();
appointmentsPerSecond.CounterName = "# appointments / sec";
appointmentsPerSecond.CounterHelp = "Number of operations executed per second";
appointmentsPerSecond.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
counters.Add(appointmentsPerSecond);
// create new category with the counters above
PerformanceCounterCategory.Create("nHydrate", "nHydrate Category", counters);
}
}