Is there a way to “map” the program execution order in Visual Studio or MATLAB?

有些话、适合烂在心里 提交于 2021-02-07 10:43:04

问题


What I mean by "map" is that I have a "main" function which calls many other programs inside, and I want to be able to see which file runs first, second, third, etc. Basically, I want to be able to see the list and order of dependencies in this large OOP design program (which the creator did not make a UML class diagram for) to help decipher the code. Surely such a functionality must exist in popular IDE's? I'm mostly dealing with C++ and MATLAB so I'm more concerned with these two specifically, but please list any IDE's you know of that have this functionality. I'd prefer something visual and not just running through a debugger and breakpoints a thousand times.


回答1:


In MATLAB, I don't believe there's a built-in way to do this visually, but you can get the information you need from the profiler using the FunctionTable returned by profile('info').

The parent/child relationships in the table essentially define a directed graph which you can interact with visually or otherwise in MATLAB if you convert it to a digraph object.

For example, to map the program execution of kmeans:

profile on
kmeans(rand(100,2),5);
p = profile('info');
t = struct2table(p.FunctionTable);
g = digraph(false(height(t)), t); % Create the graph with nodes and no edges

% Add the edges
for ii = 1:g.numnodes
    for jj = 1:numel(g.Nodes.Children{ii})
        g = g.addedge(ii, g.Nodes.Children{ii}(jj).Index);
    end
end

plot(g,'NodeLabel',g.Nodes.FunctionName,'Layout','layered');

Produces:

The file each function comes from is also accessible via the FileName field of the FunctionTable so if the distinction between functions and the files they came from is important you could use this information to color or simplify the graph accordingly.



来源:https://stackoverflow.com/questions/52193006/is-there-a-way-to-map-the-program-execution-order-in-visual-studio-or-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!