简体   繁体   English

有向代码的有向无环图生成

[英]Directed Acyclic Graph Generation for Code

Is a free application that automatically generates a directed acyclic graph (DAG) for all the functions in a code? 一个免费的应用程序是否会自动为代码中的所有功能生成有向无环图(DAG)? I am particularly interested in one that builds the DAG for the Python code edited in Pycharm. 我特别感兴趣的是为在Pycharm中编辑的Python代码构建DAG。

For static code inspection: in PyCharm, select the root folder of your project and press Ctrl + Alt + Shift + u for a class diagram . 进行静态代码检查:在PyCharm中,选择项目的根文件夹,然后按Ctrl + Alt + Shift + u查看

在此处输入图片说明

Edit : 编辑

Using Alt + F7 you can see the usages of a selected function in other functions and methods. 使用Alt + F7,您可以在其他功能和方法中查看所选功能的用法。 But this is also not a graph for all the functions in a project. 但这也不是项目中所有功能的图形。 What you are searching for is (in general) not feasible with static code analysis, since the overall call graph is highly dependent on the conditional jumps ( if clauses) during program execution. 通常来说,您要搜索的内容对于静态代码分析是不可行的,因为整个调用图高度依赖于程序执行过程中的条件跳转( if子句)。 There is no one true D(A)G. 没有一个真正的D(A)G。

Imagine variants of a DAG for this code snipped for example: 想象一下该代码的DAG变体,例如:

def baz():
    import datetime
    if datetime.datetime.now().second % 2:
        foo()
    else:
        bar()

Neither baz -> foo , nor baz -> bar would be the only possible solution. baz -> foobaz -> bar都不是唯一可能的解决方案。

However: 然而:

(1) your debugger might track every code that was executed in one specific run and present a graph of functions used after the actual run, including their relationship towards each other. (1)您的调试器可能会跟踪在一个特定运行中执行的每个代码,并提供实际运行使用的功能图,包括它们之间的关系。

(2) There is no static code analysis tool for the general case. (2)对于一般情况,没有静态代码分析工具。 For code written for ETL worflow frameworks like luigi , pinball , airflow , dagobah , dask , and theano (comparisons 1 , 2 ) it is possible to visualize the code execution before starting the application. 用于像ETL worflow框架编写的代码路易弹球气流达戈巴DASK ,和theano (比较12 ),可以启动应用程序之前以可视化的代码执行。 For more information, see the awesome-pipeline repository. 有关更多信息,请参见令人敬畏的管道存储库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM