如何可视化 Fortran(90 或更高版本)源代码,例如使用 Graphviz?

发布于 2024-09-08 02:10:15 字数 1539 浏览 11 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只是在用心讲痛 2024-09-15 02:10:15

我推荐 doxygen,它会自动从源代码生成文档(并且是免费的)。通常,您会在描述函数和变量的注释中添加一些标记。但是,您可以在未记录的源文件上运行 doxygen,前提是您在配置文件中将 EXTRACT_ALL 设置为 YES,并让它为您的所有函数创建关系图(即该函数调用这些函数并被这些其他函数调用)。

您需要安装 GraphViz 才能生成图表,并在配置文件中将 HAVE_DOT 选项设置为 YES

有关更多信息,请参阅 doxygen 文档中的图形和图表以及此示例类文档获取生成的输出示例。

编辑:当然,对于 Fortran,您应该在配置文件中将 OPTIMIZE_FOR_FORTRAN 选项设置为 YES

I would recommend doxygen, which automatically generates documentation from source code (and is free). Usually you add some markup to comments describing your functions and variables. However, you can just run doxygen on undocumented source files, provided you set EXTRACT_ALL to YES in the configuration file, and have it create create relationship diagrams for all your functions (i.e. this function call these functions and is called by these other functions).

You need GraphViz installed to get diagrams generated and have the HAVE_DOT option set to YES in the configuration file.

See the doxygen documentation for graphs and diagrams for more information and this example class documentation for a example of the output generated.

Edit: Of course for Fortran you should set the OPTIMIZE_FOR_FORTRAN option to YES in the configuration file.

守望孤独 2024-09-15 02:10:15

如果你有钱,那么了解 Fortran 值得一看。如果您没有钱但打算快速工作,那么您可以尝试下载该软件。

对于静态调用图,我从未找到过像 Understanding 这样有用的免费工具;很难找到任何免费工具,更不用说有用的工具了。我自己写一个,但市场很小:-(

对于动态调用图,请调查您的编译器选项。我使用英特尔 Fortran 编译器,它可以生成大量有关正在执行的程序的有用信息。TotalView 调试器还可以可视化您还应该查看 gprof2dot GPROF 调用“graph”中的 DOT 文件,这是免费的,而且

我还应该补充一点,尽管它不是我曾经使用过的东西,但 Callgrind 可能有用。

If you have money then Understand for Fortran is worth looking at. If you don't have money but intend to work quickly then you might get by with a trial download of the software.

For a static call graph, I've never found a free tool as useful as Understand; it's hard to find any free tools let alone a useful one. I'd write one myself but the market would be tiny :-(

For a dynamic call graph investigate your compiler options. I use the Intel Fortran Compiler which can generate a mound of useful information about an executing program. The TotalView debugger can also visualise the call graph of an executing program. You should also look at gprof2dot which makes a DOT file out of a GPROF call 'graph'. This is free and OK.

And I should also add, though it's not something I've ever used, that Callgrind may be of use.

青巷忧颜 2024-09-15 02:10:15

您可以在 Valgrind 中使用 callgrind

valgrind --tool=callgrind [your program]

这将生成 callgrind.out。 [pid] 文件。如果您在没有优化的情况下编译程序并使用调试标志,那么这种方法效果最好。

然后,您有几个查看数据的选项:

  1. 使用 grof2dot 将 callgrind 输出转换为 .dot 文件,然后使用 xdot 查看,或者使用 GraphViz 将其转换为静态图。
  2. 直接使用 Kcachegrind 查看它(包括源代码分析和调用图)。

You can use callgrind from within Valgrind:

valgrind --tool=callgrind [your program]

This will produce a callgrind.out.[pid] file. This works best if you compile your program without optimisations, and with debug flags.

You then have a couple of options for viewing the data:

  1. Convert the callgrind output to a .dot file with grof2dot, and then view it with xdot, or convert it to a static graph with GraphViz.
  2. View it directly with Kcachegrind (includes source analysis, and call graphs).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文