本文整理汇总了C#中System.Diagnostics.PerformanceCounter.Increment方法的典型用法代码示例。如果您正苦于以下问题:C# PerformanceCounter.Increment方法的具体用法?C# PerformanceCounter.Increment怎么用?C# PerformanceCounter.Increment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.PerformanceCounter
的用法示例。
在下文中一共展示了PerformanceCounter.Increment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
if (CreatePerformanecCounters())
{
Console.WriteLine("Created performance counters");
Console.WriteLine("Please restart the application");
Console.ReadKey();
return;
}
var totalOperationsCounter = new PerformanceCounter(
"MyCategory",
"# operations executed",
"",
false);
var operationsPerSecondCounter = new PerformanceCounter(
"MyCategory",
"# operations sec",
"",
false);
totalOperationsCounter.Increment();
operationsPerSecondCounter.Increment();
}
示例2: IncreaseCounter
protected void IncreaseCounter(object sender, EventArgs e)
{
using (var counter = new PerformanceCounter("Test Category", "Test Increment", readOnly: false))
{
counter.Increment();
}
}
示例3: UpdateCounterConditional
private void UpdateCounterConditional(PerformanceCounter c, CounterInvokeDirection expectedDirection)
{
if (c != null && (expectedDirection & _direction) == expectedDirection)
{
lock (c)
{
//reset name
string ins = c.InstanceName;
c.Increment();
//also update overall insance!
c.InstanceName = OverallInstance;
c.Increment();
c.InstanceName = ins;
}
}
}
示例4: btnCount_Click
private void btnCount_Click(object sender, RoutedEventArgs e)
{
if(!PerformanceCounterCategory.Exists("PerfApp"))
{
PerformanceCounterCategory.Create("PerfApp", "Conters for app", PerformanceCounterCategoryType.SingleInstance, "Clicks", "Times the user has clicked the button");
}
PerformanceCounter pc = new PerformanceCounter("PerfApp", "Clicks", false);
pc.Increment();
txbCounter.Content = pc.NextValue().ToString();
}
示例5: WriteCounters
public void WriteCounters ()
{
using (var hitCounter = new PerformanceCounter ("Category", "Hits")) {
using (var rateCounter = new PerformanceCounter ("Category", "Rate")) {
for (var x = 0; x < 5; x++) {
hitCounter.Increment ();
rateCounter.IncrementBy (x + 10);
}
}
}
}
示例6: Increment
public static void Increment()
{
if (_exists)
{
using (var counter = new PerformanceCounter(_category, _counter, false)
{
MachineName = "."
})
{
counter.Increment();
}
}
}
示例7: IncrementCounter
static void IncrementCounter()
{
// get an instance of our perf counter
PerformanceCounter counter = new PerformanceCounter();
counter.CategoryName = "MyCategory";
counter.CounterName = "AddCounter";
counter.ReadOnly = false;
// increment and close the perf counter
counter.Increment();
counter.Close();
}
示例8: Run
public override void Run()
{
while (true)
{
using (var counter = new PerformanceCounter("category", "counter1", false))
{
counter.Increment();
}
EventLog.WriteEntry("source", "running");
Thread.Sleep(1000);
}
}
示例9: SaveMetrics
public SaveMetrics()
{
if (!PerformanceCounterCategory.Exists(PerformanceCategoryName))
{
var counters = new CounterCreationDataCollection
{
new CounterCreationData(
//
"Save - Count", "Number of world saves.", PerformanceCounterType.NumberOfItems32),
new CounterCreationData(
//
"Save - Items/sec", "Number of items saved per second.", PerformanceCounterType.RateOfCountsPerSecond32),
new CounterCreationData(
//
"Save - Mobiles/sec", "Number of mobiles saved per second.", PerformanceCounterType.RateOfCountsPerSecond32),
new CounterCreationData(
//
"Save - Customs/sec", "Number of cores saved per second.", PerformanceCounterType.RateOfCountsPerSecond32),
new CounterCreationData(
//
"Save - Serialized bytes/sec",
"Amount of world-save bytes serialized per second.",
PerformanceCounterType.RateOfCountsPerSecond32),
new CounterCreationData(
//
"Save - Written bytes/sec",
"Amount of world-save bytes written to disk per second.",
PerformanceCounterType.RateOfCountsPerSecond32)
};
#if !MONO
PerformanceCounterCategory.Create(
PerformanceCategoryName, PerformanceCategoryDesc, PerformanceCounterCategoryType.SingleInstance, counters);
#endif
}
numberOfWorldSaves = new PerformanceCounter(PerformanceCategoryName, "Save - Count", false);
itemsPerSecond = new PerformanceCounter(PerformanceCategoryName, "Save - Items/sec", false);
mobilesPerSecond = new PerformanceCounter(PerformanceCategoryName, "Save - Mobiles/sec", false);
dataPerSecond = new PerformanceCounter(PerformanceCategoryName, "Save - Customs/sec", false);
serializedBytesPerSecond = new PerformanceCounter(PerformanceCategoryName, "Save - Serialized bytes/sec", false);
writtenBytesPerSecond = new PerformanceCounter(PerformanceCategoryName, "Save - Written bytes/sec", false);
// increment number of world saves
numberOfWorldSaves.Increment();
}
示例10: Main
static void Main(string[] args)
{
CounterCreationDataCollection counters = new CounterCreationDataCollection();
counters.Add(new CounterCreationData("Sales", "Number of total sales", PerformanceCounterType.NumberOfItems64));
counters.Add(new CounterCreationData("Active Users", "Number of active users", PerformanceCounterType.NumberOfItems64));
counters.Add(new CounterCreationData("Sales value", "Total value of all sales", PerformanceCounterType.NumberOfItems64));
PerformanceCounterCategory.Create("MyApp Counters", "Counters describing the performance of MyApp",
PerformanceCounterCategoryType.SingleInstance, counters);
PerformanceCounter pc = new PerformanceCounter("MyApp Counters", "Sales", false);
pc.RawValue = 7;
pc.Decrement();
pc.Increment();
pc.IncrementBy(3);
}
示例11: Sample_CreatingPerformanceCounter
//
// http://msdn.microsoft.com/en-us/library/5e3s61wf(v=vs.90).aspx
//
private static void Sample_CreatingPerformanceCounter()
{
var performanceMonitor = new PerformanceMonitor();
performanceMonitor.AddCounter("CustomInstance");
using (var counter = new PerformanceCounter(PerformanceMonitor.pcCategory, "CustomInstance", readOnly: false))
{
string command;
do
{
counter.Increment();
Console.Write("enter command: ");
command = Console.ReadLine();
} while (command != "");
}
Console.WriteLine("press any key...");
Console.ReadKey();
}
示例12: IncrementUnhandledExceptions
private static void IncrementUnhandledExceptions()
{
try
{
string performanceCounterCategory = Assembly.GetEntryAssembly().GetName().Name;
string performanceCounterName = "UnhandledExceptions";
PerformanceCounter counter = new PerformanceCounter();
counter.CategoryName = performanceCounterCategory;
counter.CounterName = performanceCounterName;
counter.ReadOnly = false;
counter.Increment();
counter.Close();
}
catch (Exception)
{
return;
}
}
示例13: Main
public static void Main(string[] args)
{
if (CreatePerformanceCounters())
{
Console.WriteLine("Created performance counters");
Console.WriteLine("Please restart application");
Console.ReadKey();
return;
}
var totalOperationsCounter = new PerformanceCounter("MyCategory", "# operations executed", "", false);
var operationsPerSecondCounter = new PerformanceCounter("MyCategory", "# operations / sec", "", false);
totalOperationsCounter.Increment();
operationsPerSecondCounter.Increment();
Console.WriteLine("Total number of operations: {0}", totalOperationsCounter.RawValue);
Console.WriteLine("Operations / sec: {0}", operationsPerSecondCounter.RawValue);
Console.ReadLine();
}
示例14: StopCounter
public void StopCounter()
{
this.stopWatch.Stop();
using (
var averageExecutionTimeCounter = new PerformanceCounter(Category,
AverageExecutionTimeCounterName,
this.instanceName,
false))
{
using (
var averageExecutionTimeBaseCounter = new PerformanceCounter(Category,
AverageExecutionTimeBaseCounterName,
this.instanceName,
false))
{
averageExecutionTimeCounter.IncrementBy(this.stopWatch.ElapsedTicks);
averageExecutionTimeBaseCounter.Increment();
}
}
}
示例15:
//public static void CountBeginAverageTimerCounter
// (
// this PerformanceCounter performanceCounter
// , PerformanceCounter basePerformanceCounter
// , Stopwatch stopwatch
// )
//{
// //stopwatch.Reset();
// //stopwatch.Start();
// stopwatch.Restart();
//}
public static void CountEndAverageTimerCounter
(
this PerformanceCounter performanceCounter
, PerformanceCounter basePerformanceCounter
, Stopwatch stopwatch
, Func<PerformanceCounterProcessingFlagsType, PerformanceCounter, long> onBasePerformanceCounterChangeValueProcessFunc = null
)
{
if
(
stopwatch != null
)
{
if (stopwatch.IsRunning)
{
stopwatch.Stop();
}
performanceCounter
.IncrementBy(stopwatch.ElapsedTicks);
//stopwatch = null;
var increment = 1L;
if (onBasePerformanceCounterChangeValueProcessFunc != null)
{
increment = onBasePerformanceCounterChangeValueProcessFunc
(
PerformanceCounterProcessingFlagsType.TimeBasedOnEnd
, basePerformanceCounter
);
}
if (increment == 1)
{
basePerformanceCounter.Increment();
}
else
{
basePerformanceCounter.IncrementBy(increment);
}
}
}
开发者ID:Microshaoft,项目名称:Microshaoft.Common.Utilities.Net.4x,代码行数:51,代码来源:PerformanceCounterExtensionMethodsManager.cs