KCachegrind - Profiling Visualization


Bugs & Wishes

Project Page


Example 1

Suppose you want to profile the startup of Konqueror, splitting the trace into execution parts of 10 000 000 basic blocks. Even if you don't have konqueror compiled with debug info, we get profile data with function symbols. These are always available (at least for every shared library, as runtime linking needs it). In an empty directory, run

   callgrind -v --dump-every-bb=10000000 konqueror

With "-v", you get some output when shared libraries are loaded and when a profile trace dump is made. After the konqueror window pops up, simple close it again.

Now the files callgrind.out.pid, callgrind.out.pid.2, callgrind.out.pid.2, ... are created. KCachegrind by default loads these files, when found in the current working directory. So it should be enough to run "kcachegrind". When you have profile data files from more runs in one directory, they can still distinguished by the pid. To load the files for the run with process ID pid, start "kcachegrind cachegrind.out.pid".

Example 2

This time, you want to only dump profile data when choosing View/Reload in the Konqueror Menu. Do

   callgrind -v --dumpat=KonqMainWindow::slotReload konqueror

Again, -v shows when dumps are made. Choose View/Reload two times to get profile data (1) before first reload, (2) before second reload, and (3) at program termination. By starting kcachegrind and selecting only the 2nd output file, you see exactly the cost of a reload action. You can already browse a profile data file while the Callgrind profiling is running in the background. When a new profile data file is dumped, choose "File/Reload" to load the new generated data.

Example 3

This time, we first start KCachegrind with 'kcachegrind &' in the directory where the profile data files will end in. Then, in the same directory (!), we start konqueror for interactive profiling without special options with

   callgrind konqueror

When the Konqueror window is shown, press the 'Force Dump' Toolbar button in KCachegrind. Now, when you move the mouse into the Konqueror window, you will see Konqueror freezing (no update) for a few seconds. And magically, KCachegrind will load the first profile data file of the current konqueror run! For this to work, a simple mechanism is used to control Callgrind: Callgrind looks regularly for a file named 'callgrind.cmd' to get commands from the outside. By pressing 'Force Dump', KCachegrind creates this file, and waits for its deletion by Callgrind. When Callgrind detects the file, it makes a dump and deletes 'callgrind.cmd'. KCachegrind now automatically does a reload. You can control a Callgrind profile run yourself by generating this command: Execute in the current working directory of the running callgrind profile:

   echo "Dump" > callgrind.cmd

Or better, use the supplied script callgrind_control:

   callgrind_control -d

When you list the contents of the directory, you can check that callgrind made a profile data dump. You have to press 'Reload' manually now in KCachegrind to get the new data. Note: When a dump finished, Callgrind removes the "callgrind.cmd" file and thus allows you to force another dump by creating it again. Callgrind tests for existance of "callgrind.cmd" only when actively running. A sleeping profile run unfortunately can't be forced to dump profile data. Thus, we needed to move the mouse into the Konqueror window above to trigger some execution.


Last site update: 27.9.2005