从命令行重置性能计数器

发布于 2025-01-04 05:12:25 字数 343 浏览 4 评论 0原文

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

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

语境: Windows 7 x64(具有管理员访问权限)

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

因此,场景是访问 Web 服务 10000 次并验证没有消息丢失(我测试了 MSMQ + 乱序处理 + 持久性 + Windows Workflow Service)

I want to execute a command from command line to reset given performance counter to 0.

I could write a simple "3" lines console app to do that, but wondering if VS or Windows or Windows SDK already comes with such utility. I did not find such option in either typeperf or logman.

Context:
Windows 7 x64 (with Admin access)

Background:
I use a performance counter to debug/develop/stress-test a web service. Web service increments a performance counter every time it is hit.

So the scenario is to hit web service 10000 times and verify no messages have been lost (I test MSMQ + out-of-order processing + persistence + Windows Workflow Service)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还如梦归 2025-01-11 05:12:25

当我等待更好的答案时,这里有一个完整的“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;
        }
    }
}

While I'm waiting for a better answer, here is a complete "rstpc.exe" utility to reset performance counter (of NumberOfItems32 type):

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;
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文