How to read and generate a call graph.
A call graph shows which functions call which. It answers the two questions you ask most in an unfamiliar codebase: what runs when this runs, and what breaks if I change it. This guide covers how to read one and the tools that generate it in each language.
What is a call graph?
Each node in a call graph is a function or method, and an arrow from A to B means A calls B. The functions that call a given function are its callers, and the functions it calls are its callees. Following callees tells you what a function does. Following callers tells you who depends on it.
POST /orders
└─ createOrder
├─ validateCart
├─ chargeCard ──► payments API
└─ saveOrder ──► orders tableA real graph is the same idea at a much larger scale. A route handler a few lines long can reach dozens of functions and several database tables.
Static and dynamic call graphs
| Static | Dynamic | |
|---|---|---|
| Built from | The source code, without running it | A recording of the program while it runs |
| Covers | Every path the code could take | Only the paths that ran, such as one request or one test suite |
| Weak spot | Callbacks, interfaces and dynamic dispatch, where the target has to be guessed | Anything the run did not exercise |
| Best for | Exploring code and finding every caller | Performance work and confirming what actually ran |
A static call graph is always an approximation. A call through an interface or a function passed as an argument cannot always be resolved without running the code. Good tools keep those edges but mark them as possible, so you know which arrows to check.
How to read a call graph
- Start from one function, not the whole program. A full graph of any real codebase is too dense to read.
- Follow callees forward to see what a function does, down to the database and the network.
- Follow callers backward before you change a function, to see everything the change reaches.
- Look for high fan-in. A function with many callers is risky to change and worth a good test.
- Look for long chains and cycles. A chain of ten hops is hard to debug; a cycle is recursion, intended or not.
- Look for functions with no callers. They are entry points, such as routes and jobs, or dead code.
Call graph vs dependency graph
A dependency graph shows files and modules and which ones import which. A call graph goes one level down, to functions. The dependency graph shows the shape of the system; the call graph follows one path through it. You usually want both.
How to generate a call graph
Python
pyan3 builds a static call graph from the source and writes it as a Graphviz file. For a dynamic graph, profile a run with the built-in cProfile and draw it with gprof2dot. PyCG, which you will see recommended, was archived by its authors in 2023.
pyan3 yourpackage/*.py --uses --no-defines --dot > calls.dot
python -m cProfile -o run.prof app.py
gprof2dot -f pstats run.prof | dot -T svg -o calls.svgGo
The Go team's callgraph command prints every call edge in a set of packages. Its -algo flag picks the analysis: static sees only direct calls, while cha, rta and vta resolve calls through interfaces with increasing precision. rta needs a main package.
go install golang.org/x/tools/cmd/callgraph@latest
callgraph -algo=vta ./...C and C++
Doxygen draws a call graph and a caller graph for every function when Graphviz is installed and the options are on. For a dynamic graph, run the program under Valgrind's callgrind tool and open the result in KCachegrind.
# Doxyfile
HAVE_DOT = YES
CALL_GRAPH = YES
CALLER_GRAPH = YES
valgrind --tool=callgrind ./appJavaScript, TypeScript, Java, Rust and others
Your editor's call hierarchy is the quickest static view. In VS Code, right-click a function and choose Show Call Hierarchy; it works wherever the language server supports it, including TypeScript and rust-analyzer. In IntelliJ IDEA, use Navigate, then Call Hierarchy. For a dynamic view of a Node.js program, node --cpu-prof app.js writes a profile you can open in Chrome DevTools.
Where these tools stop
- Each covers one language, so a TypeScript front end and a Python service end up in separate graphs.
- A whole-program graph drawn at once is unreadable past a few hundred functions.
- An image cannot be searched, and you cannot follow an edge from it to the code.
- Routes and database tables are not on the picture, so a call graph rarely shows where a request starts and ends.
A call graph you can explore
Nodeway is a desktop app, free to start, that builds the call graph of a whole repository on your own computer, in fourteen languages, alongside its files, routes and database tables. Nothing is uploaded. The Code map page shows it on a sample repository.
- Trace from any function. Follow callers or callees hop by hop, from a route down to the tables it reads and writes.
- Read the code beside it. Select a function and its source opens next to the graph.
- Sure and possible calls apart. A solid line is a call Nodeway is sure of. A call it cannot settle, such as a callback, stays on the map as a dashed line.
- Impact of a change. Show impact walks the callers of everything your branch changes, so you see what it reaches before you review the pull request. More on change impact analysis.

Questions
What is a call graph used for?
Following what runs when a function runs, finding every caller before you change a function, spotting code nothing calls, checking whether a vulnerable function is reachable, and seeing where a program spends its time.
What is the difference between a static and a dynamic call graph?
A static call graph is built from the source without running it, so it covers every path but has to guess at callbacks and dynamic dispatch. A dynamic call graph is recorded from a real run, so it is exact for that run and misses the paths it did not take.
How do I generate a call graph in Python?
For a static graph, pyan3 reads the source and writes a Graphviz file. For a dynamic one, run the program under cProfile and turn the profile into a graph with gprof2dot.
Is a call graph the same as a control flow graph?
No. A control flow graph shows the branches and loops inside one function. A call graph shows which functions call which across the whole program.