且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Xperf时间与KeQueryPerformanceCounter相比

更新时间:2023-02-27 13:16:07

您好Frank,

对于开/关性能分析,包括恢复方案,请参阅 http://www.microsoft.com/whdc/system/sysperf/On-Off_Transition.mspx

XPerf依靠ETW进行跟踪捕获,默认情况下使用QPC(与您自己的测量代码相同)。 QPC的精度约为1us。在某些地方,xperf将其舍入为ms,但基本精度仍为微秒。

10%与1500%的偏差毫无意义。 XPerf分析非常精确,并且已在多个平台上经过多年的验证。所以我要问你是如何用KeQueryPerformanceCounter测量函数A和B的?您如何记录您测量的数据?您是否确保不包括测量记录的成本?您需要手动测量这些数据点而不是在函数A和B的序言/结尾中记录ETW事件的任何原因吗?

感谢,
迈克尔

I'm attempting to profile a kernel mode driver during a resume cycle.  I run Xperf as : xperf -on ResumeTrace -stackwalk Profile.  I've also added code in my driver to measure the time a function takes, using KeQueryPerformanceCounter.  The issue I have is the times do not match:
- Xperf indicates fcn A has a larger "weight" than fcn B by ~10%;
- KeQueryPerformanceCounter indicates fcn B takes ~15 times more time to run than fcn A.

Also, it seems that the "weight" in Xperf is msec, which does not match that of KeQueryPerformanceCounter.

I've also used PwrTest to measure resume times, and these are closer to KeQueryPerformanceCounter.  So I am not sure if Xperf is giving me the correct data OR I don't understand exactly what/how Xperf is measuring.

Thanks for any advice.

Hi Frank,

For on/off performance analysis, including resume scenario please refer to http://www.microsoft.com/whdc/system/sysperf/On-Off_Transition.mspx.

XPerf relies on ETW for trace capture, and by default uses QPC (same as your own measuring code). Precision of QPC is about ~1us. In some places, xperf rounds it to ms, but underlying precision is still in microseconds.

The deviation of 10% vs 1500% makes no sense. XPerf profiling is very precise and has been verified over a course of numerous years across a wide range of platforms. So I have to ask how are you measuring functions A and B with KeQueryPerformanceCounter? How are you logging the data you measure? Do you make sure not to include the cost of logging in your measurement? Any reason you need to manually measure these data points rather than logging ETW events in prologue/epilogue of functions A and B?

Thanks,
Michael