Skip to main content
Codegen provides powerful capabilities for analyzing and visualizing function call relationships in your codebase. This guide will show you how to traverse the call graph and create visual representations of function call paths.

Understanding Call Graph Traversal

At the heart of call graph traversal is the .function_calls property, which returns information about all function calls made within a function:

Building a Call Graph

Here’s how to build a directed graph of function calls using NetworkX:

Filtering and Visualization

You can filter the graph to show only relevant paths and visualize the results:

Advanced Usage

Example: Finding Dead Code

You can use call graph analysis to find unused functions:

Example: Analyzing Call Chains

Find the longest call chain in your codebase:
The .function_calls property is optimized for performance and uses Codegen’s internal graph structure to quickly traverse relationships. It’s much faster than parsing the code repeatedly.
When traversing call graphs, be mindful of:
  • Recursive calls that could create infinite loops
  • External module calls that might not be resolvable
  • Dynamic/runtime function calls that can’t be statically analyzed