measuring time of a profiled function

醉酒当歌 提交于 2019-12-12 01:34:47

问题



I'm trying to profile a function in another method, so in order to measure its time, I'm doing something like this:

double diffTime = GetCurrentTime() - m_lastTime;
SuspendOtherProcessThreads();
double runningTime += diffTime;

... Do profiling stuff ... 

ResumeOtherProcessThreads();
m_lastTime = GetCurrentTime();  

... Let profiled process run ....

This is what I do each sample and I consider the time in which I sampled to be "runningTime". But for some reason I get that "runningTime" is much smaller than the actual running time.
This code runs tens of thousands times a second.

does anybody know what's wrong with it?
does it have something to do with the Suspend/ Resume things?
thanks :)


回答1:


If your process is blocked by another process, your timing will be wrong.

Why are you not using a tool (like cachegrind to profile?



来源:https://stackoverflow.com/questions/4574727/measuring-time-of-a-profiled-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!