How to find all nested functions in a program?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi all,
I have a complicated and nested functions rich program. After some time of development and evolution the directory which store all the functions (each in its own file) also stores 'dead' functions which the program no longer use. In order to clean the directory from unused functions I need a list of all the necessary ones. So, my question is:
Is there a simple way to extract all the nested functions that the main program and its nested functions call?
I know I can use the Profiler and see what functions were used. But this opens the way to troubles in cases when not all options were chosen while running the program.
Any help will be appreciated,
Alon
0 comentarios
Respuestas (3)
Guillaume
el 1 de Feb. de 2017
info = checkcode(somefile, '-id')
for inf = info(strcmp(info.id, 'DEFNU'))'
fprintf('%s\n', inf.message);
end
0 comentarios
Steven Lord
el 1 de Feb. de 2017
The checkcode-based approach Guillaume suggested is a good idea, but there may be some false positives that checkcode thinks are unused but are used inside eval or as callback functions or something similar. I would combine this with a Profiler based approach using the tests that you've written for your code.
Don't worry if you haven't written tests before. If you know how to write a script file and how to use the assert function you can write script-based tests. If you know how to use the runtests function (which at its most basic you call with no inputs to run all the tests in the directory) you can run script-based tests. Once you start thinking about how to test your code, you may spend more time brainstorming test cases than you will actually implementing the test!
0 comentarios
Jan
el 1 de Feb. de 2017
Editada: Jan
el 1 de Feb. de 2017
clear all
... run your code
... prefer exhaustive integration and unit testing
[M, Mex, C] = inmem('-completenames')
% Remove Matlab's own functions:
mroot = matlabroot;
M(strncmpi(M, mroot, length(mroot)) = [];
Mex(strncmpi(M, mroot, length(mroot)) = [];
C(strncmpi(M, mroot, length(mroot)) = [];
This fails, if the brute clear all appears anywhere in the code. This is another reasons, why I recommend to avoid it carefully.
Note that you can use this to identify the used toolboxes also - before the "mroot = ..." section.
0 comentarios
Ver también
Categorías
Más información sobre Dialog Boxes en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!