log used function names in a MATLAB program

1 Ansicht (letzte 30 Tage)
Behzad Abdollahi
Behzad Abdollahi am 22 Sep. 2016
Kommentiert: per isakson am 29 Sep. 2016
I want to log the name of all the functions that are called for each Object instance in MATLAB!
For example if we have this class:
classdef ClassName
methods
function obj = ClassName()
...
end
function ordinaryMethod()
...
end
end
end
And i run the following code:
testObj = ClassName();
testObj.ordinaryMethod();
I can somehow log that the ordinaryMethod was called for testObj which is a instance of ClassName. To make it clear, I dont want to just get a list of all the function names, I only need those that are used in my program.
Can anyone give me ideas, how i can achieve this? Ideal solution is that I don't have to change the function codes!

Akzeptierte Antwort

Guillaume
Guillaume am 22 Sep. 2016
Bearbeitet: Guillaume am 22 Sep. 2016
You could simply use the profiler which will return the list of all functions called by your code (when you run it), then filter that list by the class name:
profile('on'); %starts the profiler
%run your code
p = profile('info'); %stops the profiler
allfunctions = vertcat(p.FunctionName);
classfunctions = allfunctions(strncmp(allfunctions, 'ClassName>', numel(className))) %omly keep ClassName methods
  2 Kommentare
Behzad Abdollahi
Behzad Abdollahi am 29 Sep. 2016
this works just fine, but the problem is that using profiler slows down matlab significantly and therefore I can not use this solution. thanks anyway :)
per isakson
per isakson am 29 Sep. 2016
It might be worth trying &nbsp tracer4m by per isakson

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by