Version 2 (modified by manualwiki, 12 years ago) (diff) |
---|
Running dynamic call analysis
Dynamic function calls are either dynamic MFA calls (those MFA calls whose callee is given by means of non-literal expressions) or apply calls (calls to the erlang:apply/3 built-in function).
For instance, the following calls inside f are dynamic:
f(IOModule) -> Foo = ["foo"], IOModule:format("foo"), apply(IOModule, format, Foo).
These constructs are likely difficult to be statically analysed, since their callee is determined only at execution-time. Fortunately, in many cases static code analysis is able to find potential callees, but unlike other semantic analyses in RefactorErl, dynamic call analysis would be very inefficient to be performed incrementally. Therefore, static analysis of dynamic function calls has to be triggered by the user on demand.
In order to analyse dynamic call constructs, load all the libraries and files you would like to work with. Then type in the RefactorErl shell:
ri:anal_dyn().
Dynamic call analysis begins and informs you about the process and its progress. Firstly, all function calls are gathered from the database. Secondly, dynamic ones are filtered and passed to the next step, where a parallel algorithm tries to identify the callee of each call. Finally, the results are merged and stored into the database.
For instance, executed on Erlang stdlib 1.17.4:
24012 function calls found in the database. Looking for dynamic calls... 541 function calls seem to be dynamic. Looking up dynamic calls... (533/541) Identification of 8 dynamic calls timed out. 533 dynamic calls identified in the database. Analysing dynamic calls... (533/533) Analysis completed.
As you can see in this example, there may be function calls that are not identifiable in a reasonable time (currently the time limit is set to 5 seconds, and there were 8 calls whose analysis has been ignored). This is due to the complexity of some data-flow path analysis. Users may increase the time bound on their own risk in order to make the analysis process able to identify all the callees.
Please note that most database modifications (e.g. loading or refactoring a module) may invalidate the results of this dynamic call analysis. Currently this invalidation step is not automatically done, so the user has to invoke it. To clean the dynamic calls (and every corresponding entry) from the database, simply call:
ri:clean_dyn().