本文整理汇总了C#中System.Diagnostics.PerformanceCounter.IncrementBy方法的典型用法代码示例。如果您正苦于以下问题:C# PerformanceCounter.IncrementBy方法的具体用法?C# PerformanceCounter.IncrementBy怎么用?C# PerformanceCounter.IncrementBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.PerformanceCounter
的用法示例。
在下文中一共展示了PerformanceCounter.IncrementBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeforeCallInvoke
/// <summary>
/// Invoked before passing to the method
/// </summary>
/// <param name="c"></param>
protected virtual void BeforeCallInvoke(PerformanceCounter c)
{
if (c != null)
{
lock (c)
{
string name = c.InstanceName;
c.IncrementBy(_increaseDecrease);
//also update overall insance!
c.InstanceName = OverallInstance;
c.IncrementBy(_increaseDecrease);
c.InstanceName = name;
}
}
}
示例2: IncreaseCounter
public static void IncreaseCounter(int numberOfExecutedRequests, string instanceName)
{
using (
var processedRequestsPerSecondCounter = new PerformanceCounter(Category,
ProcessedRequestsPerSecondCounterName,
instanceName,
false))
{
processedRequestsPerSecondCounter.IncrementBy(numberOfExecutedRequests);
}
}
示例3: 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);
}
}
}
}
示例4: 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);
}
示例5: 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();
}
}
}
示例6:
//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
示例7: GetCounter
PerformanceCounter GetCounter(string category, string counter,
PerformanceCounterType type = PerformanceCounterType.AverageCount64,
string machine = ".", string instance = "_Total")
{
if (!PerformanceCounterCategory.Exists(category))
{
// create category
var counterInfos = new CounterCreationDataCollection();
var counterInfo = new CounterCreationData()
{
CounterType = type,
CounterName = counter,
};
counterInfos.Add(counterInfo);
PerformanceCounterCategory
.Create(category, category, counterInfos);
// check creation
var counters
= new PerformanceCounterCategory(category, machine);
if (!counters.CounterExists(counter))
Debug.Fail("Counter was not created");
if (!counters.InstanceExists(instance))
Debug.Fail("Instance not found");
}
// get counter
var perfCounter = new PerformanceCounter
{
CategoryName = category,
CounterName = counter,
MachineName = machine,
ReadOnly = false,
};
perfCounter.IncrementBy(10);
return perfCounter;
}
示例8: IncrementCounter
public static void IncrementCounter(string counterName, int incrementBy)
{
try
{
if (m_sipsorceryCategoryReady)
{
if (m_counters.ContainsKey(counterName))
{
m_counters[counterName].IncrementBy(incrementBy);
}
else
{
PerformanceCounter counter = new PerformanceCounter(PERFORMANCE_COUNTER_CATEGORY_NAME, counterName, false);
m_counters.Add(counterName, counter);
counter.IncrementBy(incrementBy);
}
}
}
catch (Exception excp)
{
logger.Error("Exception SIPSorceryPerformanceMonitor IncrementCounter (" + counterName + "). " + excp.Message);
}
}
示例9: ClearCounter
private static void ClearCounter(PerformanceCounter counter)
{
counter.IncrementBy(-1 * counter.RawValue);
}
示例10: PerformanceCountersEndRequest
void PerformanceCountersEndRequest()
{
try
{
if (HttpContext.Current.Items["DsiPage"] != null)
{
if (PerformanceCounterCategory.Exists("DontStayIn"))
{
PerformanceCounter DsiPages = new PerformanceCounter();
DsiPages.CategoryName = "DontStayIn";
DsiPages.CounterName = "DsiPages per sec";
DsiPages.MachineName = ".";
DsiPages.ReadOnly = false;
PerformanceCounter GenTime = new PerformanceCounter();
GenTime.CategoryName = "DontStayIn";
GenTime.CounterName = "DsiPage generation time";
GenTime.MachineName = ".";
GenTime.ReadOnly = false;
PerformanceCounter GenTimeBase = new PerformanceCounter();
GenTimeBase.CategoryName = "DontStayIn";
GenTimeBase.CounterName = "DsiPage generation time base";
GenTimeBase.MachineName = ".";
GenTimeBase.ReadOnly = false;
DsiPages.Increment();
long ticksStart = (long)HttpContext.Current.Items["ApplicationStartTicks"];
long ticksEnd = 0;
QueryPerformanceCounter(ref ticksEnd);
GenTime.IncrementBy(ticksEnd - ticksStart);
GenTimeBase.Increment();
}
}
}
catch { }
}
示例11: setupAndIncrement
private static void setupAndIncrement(PerformanceCounter counter, string counterName, long? value = null)
{
if (Diagnostics.CassandraPerformanceCountersEnabled)
{
if (counter == null)
counter = SetupCounter(CassandraCountersCategory, counterName);
if (counter != null && CategoryReady)
if (value != null)
counter.IncrementBy((long)value);
else
counter.Increment();
}
}
示例12: DecrementBy
private void DecrementBy(PerformanceCounter counter, long value)
{
if (counter != null)
counter.IncrementBy(value < 0 ? value : value * -1);
}
示例13: IncrementBy
private void IncrementBy(PerformanceCounter counter, long value)
{
if (counter != null)
counter.IncrementBy(value);
}
示例14: Initialise
/// <summary>
/// Initialises the extension.
/// </summary>
/// <param name="extensionConfig"></param>
/// <param name="server">The server that this extension is for.</param>
public void Initialise(ICruiseServer server, ExtensionConfiguration extensionConfig)
{
if (!PerformanceCounterCategory.Exists("CruiseControl.NET"))
{
Log.Info("Initialising new performance counters for integration requests");
var collection = new CounterCreationDataCollection();
// Number of integrations completed counter
var numberOfCompletedIntegrations = new CounterCreationData();
numberOfCompletedIntegrations.CounterType = PerformanceCounterType.NumberOfItems32;
numberOfCompletedIntegrations.CounterName = "Number of Completed Integrations";
collection.Add(numberOfCompletedIntegrations);
// Number of integrations failed counter
var numberOfFailedIntegrations = new CounterCreationData();
numberOfFailedIntegrations.CounterType = PerformanceCounterType.NumberOfItems32;
numberOfFailedIntegrations.CounterName = "Number of Failed Integrations";
collection.Add(numberOfFailedIntegrations);
// Integration time counter
var integrationElapsedTime = new CounterCreationData();
integrationElapsedTime.CounterType = PerformanceCounterType.AverageTimer32;
integrationElapsedTime.CounterName = "Integration Time";
collection.Add(integrationElapsedTime);
// Integration count counter
var averageIntegrations = new CounterCreationData();
averageIntegrations.CounterType = PerformanceCounterType.AverageBase;
averageIntegrations.CounterName = "Average number of integrations";
collection.Add(averageIntegrations);
// Create the category
PerformanceCounterCategory.Create("CruiseControl.NET",
"Performance counters for CruiseControl.NET",
collection);
}
// Retrieve the counters
Log.Debug("Initialising performance monitoring - integration requests");
var numberOfCompletedIntegrationsCounter = new PerformanceCounter("CruiseControl.NET", "Number of Completed Integrations", false);
var numberOfFailedIntegrationsCounter = new PerformanceCounter("CruiseControl.NET", "Number of Failed Integrations", false);
var integrationElapsedTimeCounter = new PerformanceCounter("CruiseControl.NET", "Integration Time", false);
var averageIntegrationsCounter = new PerformanceCounter("CruiseControl.NET", "Average number of integrations", false);
var stopwatches = new Dictionary<string, Stopwatch>();
server.IntegrationStarted += (o, e) =>
{
Log.Debug(string.Format("Starting stopwatch for '{0}'", e.ProjectName));
// Start a stopwatch for the project
if (stopwatches.ContainsKey(e.ProjectName))
{
stopwatches[e.ProjectName].Reset();
}
else
{
var stopwatch = new Stopwatch();
stopwatches.Add(e.ProjectName, stopwatch);
stopwatch.Start();
}
};
server.IntegrationCompleted += (o, e) =>
{
Log.Debug(string.Format("Performance logging for '{0}'", e.ProjectName));
// Stop the stopwatch and record the elapsed time
if (stopwatches.ContainsKey(e.ProjectName))
{
var stopwatch = stopwatches[e.ProjectName];
stopwatch.Stop();
stopwatches.Remove(e.ProjectName);
averageIntegrationsCounter.Increment();
integrationElapsedTimeCounter.IncrementBy(stopwatch.ElapsedTicks);
}
// Record the result
if (e.Status == IntegrationStatus.Success)
{
numberOfCompletedIntegrationsCounter.Increment();
}
else
{
numberOfFailedIntegrationsCounter.Increment();
}
};
}
示例15: Increment
static void Increment(long amount, PerformanceCounter total, PerformanceCounter remote, PerformanceCounter local)
{
total.IncrementBy(amount);
if (ServiceHandler.IsExecuting)
remote.IncrementBy(amount);
else
local.IncrementBy(amount);
}