Static analysis tools for Fortran source code and call graph visualization

Hello everyone,

Is there a free and reliable tool similar to GNU cflow for Fortran that can generate call graphs? I am aware of Doxygen and profiling based workarounds using Valgrind Callgrind and KCachegrind (dynamic tools), but I would prefer static analysis tool, something like cflow that reads the source code directly and can generate Graphviz DOT output.

Best,

Simo

1 Like

You might want to read that thread

Thanks for sharing that. I have already read it, but my understanding is that it deals with dependencies. Whereas I am asking about generating call graphs: i.e., the function/subroutine call relationship extracted from the source code.

The NAG Fortran Compiler can do this: NAG Fortran Compiler, Release 7.2: Producing a Call Graph

So can FPT: https://www.simconglobal.com/fpt_ref_show_call_structure.html

Edit: I’ve tested the NAG one before on the entire LAPACK and BLAS. I used some custom Python script for post-processing and plotting. Here showing the procedures as randomly positioned nodes with calls represented as edges between them (the arrows can’t be seen because of the poor image resolution; in case someone wants to create a string and nail art I can forward the SVG image :wink:, it would make a nice present for Jack Dongarra ).

The top 10 most called procedures are

XERBLA 1381
LSAME 1174
SLAMCH 344
DLAMCH 342
ILAENV 298
SROUNDUP_LWORK 211
CABS1 162
SSCAL 121
DSCAL 120
SCOPY 107

2 Likes

Searching my list of Fortran tools, which has a Static Analysis category, for call.*graph gives the projects below. I don’t know how closely they meet your preferences.

fortrancallgraph: static source code analysis for Fortran, tracking variables in a routine’s callgraph, from fortesg
fortran-callgraph: Tool to create call graphs from JULES source code
FORTRAN_callgraph_browser: browsing tool that reads in a directory of Fortran code and displays it as an interactive graph, by Dan Ellis and Richard Rigby
FortranTree: parses Fortran source code and creates a call tree graph with Python, by imaliyov. The code relies on pygraphviz and fparser.

1 Like

You can also have a look at Doxygen. Here is a minimal doxyfile to get you started:
```txt

INPUT                  = ./src
HAVE_DOT               = YES
EXTRACT_ALL            = YES
EXTRACT_PRIVATE        = YES
EXTRACT_STATIC         = YES
CALL_GRAPH             = YES
CALLER_GRAPH           = YES
DISABLE_INDEX          = YES 
GENERATE_TREEVIEW      = YES
RECURSIVE              = YES
COLLABORATION_GRAPH    = YES
GRAPHICAL_HIERARCHY    = YES
DOT_CLEANUP            = NO
GENERATE_HTML          = YES
GENERATE_LATEX         = NO

```

And this is what you can expect (the sample corresponds to the callgraph of daskr)

It works nicely on functional codes (i.e. f77 style).

1 Like

Thank you for the suggestion. Actually, your repository was the first thing I looked at, but unfortunately I was disappointed because those tools seem unmaintained (last updated 5 years ago, and I doubt they are still reliable or even working).

@davidpfister

Thanks for the suggestion and your Doxygen example.As I mentioned in my first post, I am already familiar with Doxygen and dynamic tools.

What comes closest to cflow is what @ivanpribec already suggested: the NAG Fortran compiler and fpt.

creates a graph for RTL input, and “gfortran -fdump-rtl-expand” should generate RTL from Fortran. You would need Graphviz, gfortran, egypt, perl at least.

1 Like

If you installed Intel OneAPI, you can run Intel Fortran under Visual Studio. In its debug mode, show ‘call stack‘, when you pause the code, it will generate the plot which is similar (or perhaps even better in my opinion) with what @davidpfister showed above.

Indeed and if you are to use the intel suite you can also go for vTune. It generates a flame chart that is a graphical representation of the call stack + elapsed time per function. But the method is dynamic and depends on the runtime option. The OP asked for something static though.

1 Like

There is also cally, which is essentially the same as egypt but in Python.

1 Like

That’s perfectly what I was looking for! It works like a charm.

There is also marauder’s map, for Fortran, Python and C.

Far from perfect, with docs a bit outdated, and approximate static callgraph…

but you can read a full example here.
It uses tucan underneath, which computes several interesting metrics

Will update the mmap pypi version soon
If you are interested or need assistance contact me.

1 Like