How to: Create Custom Performance Counters

在性能测试的项目中,一些自己所刚需的系能指标需要纪录下来,而不仅仅是操作系统内置。 如何把自己想要记录下来的数据保存成raw data,便于对所测试的产品或者组件最更加详细的分析,这时候就需要我们创建自定义的performance counter。

来自的MSDN的一片文字说明的很清楚:

http://msdn.microsoft.com/en-us/library/5e3s61wf.aspx

 

用代码创建performance counter的过程:

 if (!PerformanceCounterCategory.Exists("ABSPerfCustomer"))
            {
                CounterCreationDataCollection CounterDatas =
                    new CounterCreationDataCollection();

                CounterCreationData counter1 = new CounterCreationData();
                CounterCreationData counter2 = new CounterCreationData();
                counter1.CounterName = "counter1";
                counter2.CounterName = "counter2";
                counter1.CounterHelp = "counter1_help";
                counter2.CounterHelp = "counter2_help";
                counter1.CounterType = PerformanceCounterType.CountPerTimeInterval64;
                counter2.CounterType = PerformanceCounterType.CountPerTimeInterval64;

                CounterDatas.Add(counter1);
                CounterDatas.Add(counter2);

                PerformanceCounterCategory.Create("ABSPerfCustomer", "ABSPerfCustomer_help", PerformanceCounterCategoryType.SingleInstance, CounterDatas);

            }

 用代码删除创建的自定义performance counter:

1 if (PerformanceCounterCategory.Exists("ABSPerfCustomer"))
2             {
3                 PerformanceCounterCategory.Delete("ABSPerfCustomer");
4             }
View Code

 

 

 

 

 

 

posted @ 2013-05-28 00:15  Longmarch2008  阅读(224)  评论(0编辑  收藏  举报