开发者

C++ Asymptotic Profiling

开发者 https://www.devze.com 2022-12-31 17:20 出处:网络
I have a performance issue where I suspect one standard C library function is taking too long and causing my entire system (suite of pr开发者_如何学Cocesses) to basically \"hiccup\". Sure enough if I

I have a performance issue where I suspect one standard C library function is taking too long and causing my entire system (suite of pr开发者_如何学Cocesses) to basically "hiccup". Sure enough if I comment out the library function call, the hiccup goes away. This prompted me to investigate what standard methods there are to prove this type of thing? What would be the best practice for testing a function to see if it causes an entire system to hang for a sec (causing other processes to be momentarily starved)?

I would at least like to definitively correlate the function being called and the visible freeze.

Thanks


The best way to determine this stuff is to use a profiling tool to get the information on how long is spent in each function call.

Failing that set up a function that reserves a block of memory. Then in your code at various points, write a string to memory including the current time. (This avoids the delays associated with writing to the display). After you have run your code, pull out the memory and parse it to deterimine how long parts of your code are taking.


I'm trying to figure out what you mean by "hiccup". I'm imagining your program does something like this:

while (...){
  // 1. do some computing and/or file I/O
  // 2. print something to the console or move something on the screen
}

and normally the printed or graphical output hums along in a subjectively continuous way, but sometimes it appears to freeze, while the computing part takes longer.

Is that what you meant?

If so, I suspect in the running state it is most always in step 2, but in the hiccup state it spending time in step 1.

I would comment out step 2, so it would spend nearly all it's time in the hiccup state, and then just pause it under the debugger to see what it's doing. That technique tells you exactly what the problem is with very little effort.

0

精彩评论

暂无评论...
验证码 换一张
取 消