开发者

Using valgrind to find most intensive function?

开发者 https://www.devze.com 2023-03-02 11:20 出处:网络
I have a program running extrem开发者_JS百科ely slow. Is there a way to use valgrind to find out which function I need to optimize?

I have a program running extrem开发者_JS百科ely slow. Is there a way to use valgrind to find out which function I need to optimize? Thanks.


You can use the callgrind tool for valgrind, which should be part of each valgrind distribution. It runs the program in the valgrind "virtual machine" and counts the number of instructions spent in each function/line of code. The best UI for visualizing the results is kcachegrind (part of KDE).

Advantage: It works quite well if your bottleneck is CPU-bound, as it's completely simulates the application so one gets very accurate and detailed results if CPU instructions is what interests you. If not, the results might be distorted.

Disadvantage: It's slow (like valgrind). If your problem is I/O-bound, the slow execution speed will distort the results (making I/O faster in comparison) and also influence the behavior. In such cases, a profiler taking samples is the better approach.


No, Valgrind is a dynamic analysis tool used to flesh out memory allocation errors and thread race-conditions (among other things).

You're looking for a code profiler, such as Luke Stackwalker. I don't know of any for *NIX systems off the top of my head, sorry.


Not as far as I know. oprofile is the best tool for what you want.

0

精彩评论

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

关注公众号