Post

Mastering Kernel Analysis - Visualizing Function Call Graphs with Doxygen.

Understanding the complex flow of function calls and their hierarchical relationships using Doxygen.

Mastering Kernel Analysis - Visualizing Function Call Graphs with Doxygen.

Introduction

Understanding the complex flow of function calls and their hierarchical relationships is crucial when working with large codebases like Linux Kernel. Doxygen, a powerful documentation generator, not only helps in creating structured documentation but also provides valuable insights into function call graphs and class hierarchies. In this post, we will explore how to leverage Doxygen to visualize kernel functions, uncover intricate call paths, and effectively navigate complex code structures. Whether you’re a systems programmer delving into kernel internals or a developer seeking to optimize code paths, this guide will walk you through the essential steps to harness Doxygen for insightful visual analysis.

This is not specific to Linux Kernel but rather can be applied to any C/C++ source.

What is Doxygen

Doxygen is an open-source documentation generator tool used for creating documentation from annotated source code. It can generate output in various formats including HTML. Doxygen can also be used to generate PDF using LaTeX as an intermediate step.

Installation of Doxygen and LaTeX

The steps mentioned are tested on Ubuntu 25.04.

1
sudo apt install doxygen doxygen-latex texlive-full graphviz

Doxygen configuration file

Doxygen takes a configuration file as input consisting of settings which needs to be enabled or disabled. The Doxygen itself can be used to dump the default configuration file which lists all the default settings with great deal of explanation for each setting.

1
2
3
4
5
6
7
8
9
$ doxygen -g

Configuration file 'Doxyfile' created.

Now edit the configuration file and enter

  doxygen

to generate the documentation for your project

The Doxyfile generated by Doxygen is large. For clarity, the custom Doxyfile that has been tested is provided below. The source file from the kernel taken for generating the call and caller graphs is clock subsystem core file drivers/clk/clk.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Input
INPUT                  = drivers/clk/clk.c
FILE_PATTERNS          = *.c *.h
RECURSIVE              = NO

# Graph settings
CALL_GRAPH             = YES
CALLER_GRAPH           = YES
HAVE_DOT               = YES
DOT_PATH               = /usr/bin/dot
DOT_CLEANUP            = YES

EXTRACT_ALL            = YES
EXTRACT_STATIC         = YES
EXTRACT_PRIVATE        = YES
EXTRACT_LOCAL_CLASSES  = YES
HIDE_UNDOC_MEMBERS     = NO
GENERATE_TREEVIEW      = YES
DISABLE_INDEX          = NO
FULL_SIDEBAR           = NO

# Output
GENERATE_HTML          = YES
GENERATE_LATEX         = YES
OUTPUT_DIRECTORY       = out

The INPUT settings must be configured to specify the file that Doxygen should process to generate call graphs for functions. GENERATE_LATEX is optional if a PDF is required.

Generate Graph

The following command will generate the HTML files in the out directory for the clock drivers/clk/clk.c file which is configured in the Doxyfile.

1
doxygen Doxyfile

Output

The index.html generated in the out/html directory can be opened in any of the browsers.

Lets select the function clk_core_round_rate_nolock and examine its generated graphs.

Call graph Call graph

Called graph Caller graph

The advantage of this mechanism is that it does not require any changes to or compilation of the Linux kernel. Just keep the Doxyfile in a separate directory, provide the necessary kernel source files, and generate the graphs.

This post is licensed under CC BY 4.0 by the author.

Trending Tags