Monday, December 10, 2007

Valgrind callgrind tools Part 2: accessing information inside a callgrind files

From Valgrind's callgrind manual:

Callgrind is a Valgrind tool for profiling programs. The collected data consists of the number of instructions executed on a run, their relationship to source lines, and call relationship among functions together with call counts. Optionally, a cache simulator (similar to cachegrind) can produce further information about the memory access behavior of the application.

The result is that the files that are produces contain a plethora of data just waiting to be mined. I have written a tool called callgrind_info to extract information out of a callgrind file.

When you want to watch a function for performance regressions callgrind excels at getting results that are similar one run to the next. Extracting the cost of a function in a nightly script would be a very useful thing to do to automatically determine if you are having performance regressions:
./callgrind_info callgrind.out.5511 -cost 'tst_QListView::cursorMove()'

The matching functionality for the "-cost" is the "-function" which will output every function that was used in some specific file:
./callgrind_info callgrind.out.5511 -functions tst_qlistview.cpp                              

callgrind_info also lets you extract a list of the different specification types.

If you want to know every object/library that was loaded during the run of the program:
./callgrind_info callgrind.out.5511 -spec ob

Every file:
./callgrind_info callgrind.out.5511 -spec fl | more

Every function:
./callgrind_info callgrind.out.5511 -spec fn | more
QBasicAtomicInt::operator int() const
QBasicAtomicInt::operator!=(int) const
QBasicAtomicInt::operator!() const
QBasicAtomicInt::operator==(int) const
QWidget::resize(int, int)
QWidget::height() const

The callgrind info tool just touches on some of the data that can be extracted, but already it has proved to be very useful.

The source for callgrind_info can be found in my callgrind tools git repository.

1 comment:

Ganesh said...

iam new to callgrind,
hence i would like to get details of basic information,
when we use callgrind, a valgrind tool
it results in file "./callgrind.PID" and when we have look at that resultant file it shows some graphical window abt diff functions involved in diff functions,
but we've headings saying-syscount,count,self cost, inclusive cost,
can anyone pls exp me what these signify?
and also it shows diff options in drop down box at the top,viz systime(when we enable systime),Inclusive cost and syscount,.
Please give me some details abt these terms, i couldn't get information abt these terms in any of the kcachegrind/valgrind handbooks


Popular Posts