简体   繁体   中英

measuring time of a profiled function


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 :)

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM