本文整理汇总了C#中System.Diagnostics.CounterCreationDataCollection类的典型用法代码示例。如果您正苦于以下问题:C# CounterCreationDataCollection类的具体用法?C# CounterCreationDataCollection怎么用?C# CounterCreationDataCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CounterCreationDataCollection类属于System.Diagnostics命名空间,在下文中一共展示了CounterCreationDataCollection类的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: 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);
}
}
示例3: CreateOutboundCategory
private static void CreateOutboundCategory()
{
if (PerformanceCounterCategory.Exists(OutboundPerfomanceCounters.CATEGORY))
{
logger.DebugFormat("Deleting existing performance counter category '{0}'.", OutboundPerfomanceCounters.CATEGORY);
PerformanceCounterCategory.Delete(OutboundPerfomanceCounters.CATEGORY);
}
logger.DebugFormat("Creating performance counter category '{0}'.", OutboundPerfomanceCounters.CATEGORY);
try
{
var counters = new CounterCreationDataCollection(OutboundPerfomanceCounters.SupportedCounters().ToArray());
PerformanceCounterCategory.Create(
OutboundPerfomanceCounters.CATEGORY,
"Provides statistics for Rhino-Queues messages out-bound from the current machine.",
PerformanceCounterCategoryType.MultiInstance,
counters);
}
catch (Exception ex)
{
logger.Error("Creation of outbound counters failed.", ex);
throw;
}
}
示例4: Test
public void Test()
{
const string categoryName = "TestCategory";
const string categoryHelp = "Test category help";
const PerformanceCounterCategoryType categoryType = PerformanceCounterCategoryType.SingleInstance;
const string counterName = "TestElapsedTime";
const string counterHelp = "Test elapsed time";
if (!PerformanceCounterCategory.Exists(categoryName))
{
var counterCreationData = new CounterCreationDataCollection(ElapsedTime.CounterCreator.CreateCounterData(counterName, counterHelp));
var category = PerformanceCounterCategory.Create(categoryName, categoryHelp, categoryType, counterCreationData);
}
var elapsedTime = new ElapsedTime(PerformanceCounterFactory.Singleton, categoryName, "TestElapsedTime", false);
elapsedTime.Reset();
var count = 0;
while (++count < 10)
{
Thread.Sleep(1000);
var value = elapsedTime.NextValue();
Debug.Print("Value = {0}", value);
}
elapsedTime.Dispose();
PerformanceCounterCategory.Delete(categoryName);
}
示例5: 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);
}
}
示例6: 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;
}
示例7: Create
internal static void Create()
{
if (PerformanceCounterCategory.Exists(engineCategory))
{
PerformanceCounterCategory.Delete(engineCategory);
}
var counterList = new CounterCreationDataCollection();
counterList.Add(new CounterCreationData(
dirtyNodeEventCount,
"Describes the number of dirty node messages on the engine's event queue.",
PerformanceCounterType.NumberOfItems32));
counterList.Add(new CounterCreationData(
calculatedNodeCount,
"Describes the number of items scheduled for calculation by an engine task.",
PerformanceCounterType.NumberOfItems32));
counterList.Add(new CounterCreationData(
taskExecutionTime,
@"Describes the time in milliseconds to process an engine task.",
PerformanceCounterType.NumberOfItems32));
PerformanceCounterCategory.Create(
engineCategory,
"Engine counters",
PerformanceCounterCategoryType.SingleInstance,
counterList);
}
示例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: 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");
}
}
示例10: 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)
};
}
示例11: 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.");
}
示例12: PerformanceCounters
static PerformanceCounters()
{
try
{
if (PerformanceCounterCategory.Exists(category))
PerformanceCounterCategory.Delete(category);
// order to be sure that *Base follows counter
var props = typeof(PerformanceCounters).GetProperties().OrderBy(p => p.Name).ToList();
var counterCollection = new CounterCreationDataCollection();
foreach (var p in props)
{
var attr = (PerformanceCounterTypeAttribute)p.GetCustomAttributes(typeof(PerformanceCounterTypeAttribute), true).First();
counterCollection.Add(new CounterCreationData() { CounterName = p.Name, CounterHelp = string.Empty, CounterType = attr.Type });
}
PerformanceCounterCategory.Create(category, "Online Trainer Perf Counters", PerformanceCounterCategoryType.MultiInstance, counterCollection);
}
catch (Exception e)
{
new TelemetryClient().TrackException(e);
}
}
示例13: 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);
}
}
示例14: 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());
}
}
示例15: 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();
}