使用性能计数器计算平均值 [英] Calculating Averages with Performance Counters

查看:55
本文介绍了使用性能计数器计算平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务流程,我想使用性能计数器来发布完成任务所需的平均时间.我正在使用AverageTimer32计数器执行此操作.

I have a service process, and I want to use performance counters to publish the average time that it takes to complete tasks. I am using the AverageTimer32 counter to do this.

它几乎可以按照我想要的方式工作,但不完全是:当我增加计数器时,它会短暂地上升到我期望的值(在Performance Monitor中监视),但是随后又下降到零.

It's almost working the way I want, but not quite: When I increment the counter, it will briefly bump up to the value that I expect (watching in Performance Monitor), but then it drops right back down to zero.

因此,计数器为零,我运行了一个任务,任务完成了,计数器短暂上升(达到正确的值),但随后几乎立即降为零.

So, the counter is zero, I run a task, the task completes, the counter briefly bumps up (to the correct value), but then it almost immediately falls back to zero.

我正在使用AverageTimer32计数器,并以AverageBase作为分母.每次启动任务时,我将AverageBase增加1,然后将完成任务时要完成的滴答数增加AverageTimer32.有人可以给我推吗?

I am using the AverageTimer32 counter with an AverageBase as the denominator. I increment the AverageBase by 1 every time I start a task, and then I increment the AverageTimer32 by the number of ticks to complete every time I finish the task. Can anyone give me a push?

推荐答案

事实证明,我无法做到自己想要的原因是,没有任何性能计数器类型提供自动计算均线的功能.(平均值"计数器根据该时刻计算平均值,例如每秒字节数".)

It turns out that the reason that I could not do what I wanted was that none of the performance counter types provide for automatically calculating a running average. (the "average" counters, calculate an average based upon that moment in time, like "bytes per second").

我想要一个运行平均值.因此,我使用了RawFraction性能计数器类型.

I wanted a running average. So, I used the RawFraction performance counter type.

该方法存在一个问题:该公式将结果除以100以产生一个百分比,而我想要一个原始数字(每秒完成的平均操作数).

There was one problem with that method: The formula divides the result by 100 to produce a percentage, and I wanted a raw number (average operations completed per second).

因此,我每执行1次操作就将分数的分母增加100(抵消百分比计算).

So, I incremented the denominator of the fraction by 100 for every 1 operation (offsetting the percentage calculation).

我的结果:现在,我可以显示我的服务平均完成一项任务所花费的时间.如果我的服务不忙,则平均值将保持不变,这样您就可以看到我的服务性能的长期趋势.

My result: I can now display how long it takes, on average, for my service to complete a task. If my service isn't busy, the average remains constant so that you can see the long-term trend of my service's performance.

这篇关于使用性能计数器计算平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆