2012-02-08 81 views
2

我想从命令行执行的命令,以给定的性能计数器复位为0。复位性能计数器

我可以写一个简单的“3”行控制台应用程序要做到这一点,但想知道如果VS或Windows或Windows SDK已经有了这样的实用程序。我没有在typeperf或logman中找到这样的选项。

语境: 的Windows 7 64位(拥有管理员权限)

背景:
我使用性能计数器来调试/开发/压力测试的Web服务。每次访问时,Web服务都会增加一个性能计数器。

所以情况是打web服务10000次,并确认没有消息已经丢失(我测试MSMQ +乱序处理+执着+ Windows工作流服务)

回答

4

,而我等待更好的答案,这里是一个完整的“rstpc.exe”实用程序来重置性能计数器(NumberOfItems32类型):

using System; 
using System.Collections.Generic; 
using System.Diagnostics; 
using System.IO; 
using System.Linq; 
using System.Reflection; 
using System.Text; 

namespace ResetPerformanceCounter 
{ 
    internal class Program 
    { 
     private static int Main(string[] args) 
     { 
      if (args.Length != 2) 
      { 
       string fileName = Path.GetFileName(Assembly.GetExecutingAssembly().Location); 
       Console.WriteLine("Usage: {0} <PC Category> <PC Name>", fileName); 
       Console.WriteLine("Examlpe: {0} {1} {2}", fileName, "GEF", "CommandCount"); 
       return -1; 
      } 

      string cat = args[0]; 
      string name = args[1]; 

      if (!PerformanceCounterCategory.CounterExists(name, cat)) 
      { 
       Console.WriteLine("Performance Counter {0}\\{1} not found.", cat, name); 
       return - 2; 
      } 

      var pc = new System.Diagnostics.PerformanceCounter(cat, name, false); 

      if (pc.CounterType != PerformanceCounterType.NumberOfItems32) 
      { 
       Console.WriteLine("Performance counter is of type {0}. Only '{1}' countres are supported.", pc.CounterType.ToString(), PerformanceCounterType.NumberOfItems32); 
       return -3; 
      } 

      Console.WriteLine("Old value: {0}", pc.RawValue); 
      pc.RawValue = 0; 
      Console.WriteLine("New value: {0}", pc.RawValue); 
      Console.WriteLine("Done."); 
      return 0; 
     } 
    } 
}