Command line 从命令行重置性能计数器

Command line 从命令行重置性能计数器,command-line,performancecounter,Command Line,Performancecounter,我想从命令行执行一个命令,将给定的性能计数器重置为0 我可以编写一个简单的“3”行控制台应用程序来实现这一点,但不知道VS、Windows或Windows SDK是否已经附带了这样的实用程序。我在typeperf或logman中都没有找到这样的选项 背景: Windows 7 x64(具有管理员访问权限) 背景: 我使用性能计数器调试/开发/压力测试web服务。每次命中Web服务时,它都会增加一个性能计数器 因此,该场景是点击web服务10000次,并验证没有丢失任何消息(我测试MSMQ+无序处

我想从命令行执行一个命令,将给定的性能计数器重置为0

我可以编写一个简单的“3”行控制台应用程序来实现这一点,但不知道VS、Windows或Windows SDK是否已经附带了这样的实用程序。我在typeperf或logman中都没有找到这样的选项

背景: Windows 7 x64(具有管理员访问权限)

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


因此,该场景是点击web服务10000次,并验证没有丢失任何消息(我测试MSMQ+无序处理+持久性+Windows工作流服务)

在等待更好的答案时,下面是一个完整的“rstpc.exe”实用程序,用于重置性能计数器(NumberOfItems32类型):

使用系统;
使用System.Collections.Generic;
使用系统诊断;
使用System.IO;
使用System.Linq;
运用系统反思;
使用系统文本;
命名空间重置性能计数器
{
内部课程计划
{
私有静态int Main(字符串[]args)
{
如果(参数长度!=2)
{
字符串文件名=Path.GetFileName(Assembly.getExecutionGassembly().Location);
WriteLine(“用法:{0}”,文件名);
WriteLine(“Examlpe:{0}{1}{2}”,文件名,“GEF”,“CommandCount”);
返回-1;
}
字符串cat=args[0];
字符串名称=args[1];
如果(!PerformanceCounterCategory.Counter存在(名称,类别))
{
WriteLine(“找不到性能计数器{0}\\{1}。”,cat,name);
返回-2;
}
var pc=新系统.Diagnostics.PerformanceCounter(类别、名称、错误);
if(pc.CounterType!=PerformanceCounterType.NumberOfItems32)
{
WriteLine(“性能计数器的类型为{0}。只支持{1}个计数器。”,pc.CounterType.ToString(),PerformanceCounterType.NumberOfItems32);
返回-3;
}
WriteLine(“旧值:{0}”,pc.RawValue);
pc.RawValue=0;
WriteLine(“新值:{0}”,pc.RawValue);
控制台。WriteLine(“完成”);
返回0;
}
}
}

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

使用系统;
使用System.Collections.Generic;
使用系统诊断;
使用System.IO;
使用System.Linq;
运用系统反思;
使用系统文本;
命名空间重置性能计数器
{
内部课程计划
{
私有静态int Main(字符串[]args)
{
如果(参数长度!=2)
{
字符串文件名=Path.GetFileName(Assembly.getExecutionGassembly().Location);
WriteLine(“用法:{0}”,文件名);
WriteLine(“Examlpe:{0}{1}{2}”,文件名,“GEF”,“CommandCount”);
返回-1;
}
字符串cat=args[0];
字符串名称=args[1];
如果(!PerformanceCounterCategory.Counter存在(名称,类别))
{
WriteLine(“找不到性能计数器{0}\\{1}。”,cat,name);
返回-2;
}
var pc=新系统.Diagnostics.PerformanceCounter(类别、名称、错误);
if(pc.CounterType!=PerformanceCounterType.NumberOfItems32)
{
WriteLine(“性能计数器的类型为{0}。只支持{1}个计数器。”,pc.CounterType.ToString(),PerformanceCounterType.NumberOfItems32);
返回-3;
}
WriteLine(“旧值:{0}”,pc.RawValue);
pc.RawValue=0;
WriteLine(“新值:{0}”,pc.RawValue);
控制台。WriteLine(“完成”);
返回0;
}
}
}
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;
        }
    }
}