[英]unregistering a performance counters
I have added performance custom counters to my application to whether the no of times the operation takes place or not . 我已经在我的应用程序中添加了性能自定义计数器,以确定操作是否发生。
But now I want to unregister it . 但现在我想取消注册它。 Is it possible to unregister it remove it .
是否可以取消注册将其删除。
I have used this counters in C#. 我在C#中使用过这个计数器。
The class which creates a performance category and adds counters to it . 创建性能类别并向其添加计数器的类。
using System;
using System.Diagnostics;
namespace GroupChatLibrarySamples
{
///<summary>
///Helper class to demonstrate the setup of performance counters.
///</summary>
public class PerformanceCounterHelper
{
//Total number of tests executed
private PerformanceCounter _TotalFiles = null;
/// <summary>
/// Constructor
/// </summary>
public PerformanceCounterHelper()
{
// Set up the performance counter(s)
if (!PerformanceCounterCategory.Exists("Total_Files","."))
{
//Create the collection container
CounterCreationDataCollection counters = new CounterCreationDataCollection();
////Create counter #1 and add it to the collection
CounterCreationData tests = new CounterCreationData();
tests.CounterName = "Total_Files_Sent";
tests.CounterHelp = "Total number of Files Sent";
tests.CounterType = PerformanceCounterType.NumberOfItems32;
counters.Add(tests);
//Create the category and all of the counters.
PerformanceCounterCategory.Create("Total_Files", "Performance Counter for checking no of files sent", counters);
}
try
{
_TotalFiles = new PerformanceCounter();
_TotalFiles.CategoryName = "Total_Files";
_TotalFiles.CounterName = "Total_Files_Sent";
_TotalFiles.MachineName = ".";
_TotalFiles.ReadOnly = false;
}
catch (Exception e)
{
Console.WriteLine(" {0} \n", e.StackTrace);
}
}
public void IncrementCounters()
{
_TotalFiles.Increment();
}
}
}
The code where counter is incremented : 计数器递增的代码:
private void BeginSendFilesFinished(IAsyncResult ar)
{
currentOperation.End("BeginSendFilesFinished", () => session.EndUploadFile(ar));
Console.WriteLine(" File Count : {0} \n", listoffiles.Count);
if(sentFiles < (listoffiles.Count-1))
{
sentFiles++;
string SampleFile = listoffiles[sentFiles].ToString();
FileInfo filetoupload = new FileInfo(SampleFile);
ChatRoomFileUploadJob uploadfilejob = new ChatRoomFileUploadJob(filetoupload);
counterHelper.IncrementCounters();
currentOperation.Begin(string.Format("Send Files: # {0}", sentFiles), () => session.BeginUploadFile(uploadfilejob, BeginSendFilesFinished, null));
}
else
{
Log("Leave ChatRoom:");
// After sending 10 chat msgs, leave the chat room (and rejoin).
currentOperation.Begin("Leave ChatRoom:", () => session.BeginLeave(BeginLeaveChatRoomFinished, null));
}
}
Thanks & Regards, Tazim. 谢谢和问候,Tazim。
This might be too obvious, but given that you're trying to do the opposite of the PerformanceCounterCategory.Create action (I think), have you looked at using PerformanceCounterCategory.Delete ? 这可能太明显了,但考虑到你试图与PerformanceCounterCategory.Create动作相反(我认为),你有没有看过使用PerformanceCounterCategory.Delete ? According to the documentation it:
根据文件它:
Removes the category and its associated counters from the local computer
从本地计算机中删除类别及其关联的计数器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.