首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我的性能计数器在哪里?它已创建,但在perfmon中看不到它

问我的性能计数器在哪里?它已创建,但在perfmon中看不到它
EN

Stack Overflow用户
提问于 2012-07-18 02:41:19
回答 2查看 2.9K关注 0票数 7

我有这段代码:我在哪里创建我的性能计数器。它执行正常,如果不存在,它也会创建性能计数器,但当我使用perfmon时,我找不到这个性能计数器。

这是怎么回事?

代码语言:javascript
复制
 const string _categoryName = "MyPerformanceCounter";
    if (!PerformanceCounterCategory.Exists(_categoryName))
    {
        CounterCreationDataCollection counters = new CounterCreationDataCollection();

        CounterCreationData ccdWorkingThreads = new CounterCreationData();
        ccdWorkingThreads.CounterName = "# working threads";
        ccdWorkingThreads.CounterHelp = "Total number of operations executed";
        ccdWorkingThreads.CounterType = PerformanceCounterType.NumberOfItems32;
        counters.Add(ccdWorkingThreads);

        // create new category with the counters above
        PerformanceCounterCategory.Create(_categoryName,
                "Performance counters of my app",
                PerformanceCounterCategoryType.SingleInstance,
                counters);
    }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-01 19:11:47

没有收到任何异常的原因是缺少try-catch块。如果将语句添加到try和catch块中,如下所示

代码语言:javascript
复制
        try
        {                
            const string _categoryName = "MyPerformanceCounter";
            if (!PerformanceCounterCategory.Exists(_categoryName))
            {
                CounterCreationDataCollection counters = 
                new CounterCreationDataCollection();

                CounterCreationData ccdWorkingThreads = new CounterCreationData();
                ccdWorkingThreads.CounterName = "# working threads";
                ccdWorkingThreads.CounterHelp = "Total number of operations executed";
                ccdWorkingThreads.CounterType = PerformanceCounterType.NumberOfItems32;
                counters.Add(ccdWorkingThreads);

                // create new category with the counters above
                PerformanceCounterCategory.Create(_categoryName,
                        "Performance counters of my app",
                        PerformanceCounterCategoryType.SingleInstance,
                        counters);
            }                
        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.ToString()); //Do necessary action
        }   

然后,它将捕获您看到的exceptions.If异常,如“请求的注册表访问不允许”。然后,您需要管理员权限才能执行此操作。要确认这一点,请使用管理权限运行Visual Studio并执行代码。

票数 2
EN

Stack Overflow用户

发布于 2014-10-09 22:26:53

除了以管理员身份运行Visual Studio以允许创建类别之外,我还遇到了同样的问题- .NET代码报告计数器在那里,但在perfmon中看不到这样的计数器类别。

显然,perfmon有时会disable performance counters by flagging it as disabled in the registry。

如果您在HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services下使用check in the registry,您应该能够找到您的性能计数器类别(只需在“文件夹”中查找您的类别名称)。在子项("folder") Performance下,找到注册表值Disable Performance Counters并将其设置为零。重新启动perfmon,您现在应该可以在perfmon中看到您的类别和计数器。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11528804

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档