how to save number of function calls from profile

1 view (last 30 days)
I am using profile function in matlab. first I use profile on and then I run the function that I want statistics about it. I use profileview to see the profiled process. In the Profile Summary page, the column "calls" is what I am interested in. how can I record the number of calls which is in Profile Summary using matlab commands?

Answers (1)

Philip Borghesani
Philip Borghesani on 17 Aug 2016
Edited: Philip Borghesani on 17 Aug 2016
Use the results returned by profile('info').
profile on; magic(3) ; profile off;
ifo=profile('info');
ifo.FunctionTable(1)
struct with fields:
CompleteName: 'L:\work\Bscript2\matlab\toolbox\matlab\elmat\magic.m>magic'
FunctionName: 'magic'
FileName: 'L:\work\Bscript2\matlab\toolbox\matlab\elmat\magic.m'
Type: 'M-function'
Children: [1×1 struct]
Parents: [0×1 struct]
ExecutedLines: [3×3 double]
IsRecursive: 0
TotalRecursiveTime: 0
PartialData: 0
NumCalls: 1
TotalTime: 0.0120
The number of calls in in the field NumCalls
  2 Comments
H D
H D on 18 Aug 2016
Hi and thanks for your reply I have a second function inside the file whis is called by the main function based on a condition. lets name it f2. the f2 is called by main function when ever it is required. I need to grab this and to know how many times the f2 is called. i can see it in the Profile Summary file but I need it to be shown in the command window. Thanks once again
Philip Borghesani
Philip Borghesani on 18 Aug 2016
Data for other functions is at other indexes into the function table, you can examine the full output with struct2table(ifo.FunctionTable) or {ifo.FunctionTable.FunctionName;ifo.FunctionTable.NumCalls}'.
>> {ifo.FunctionTable.FunctionName;ifo.FunctionTable.NumCalls}'
ans =
2×2 cell array
'magic' [1]
'magic>oddOrderMagicSquare' [1]

Sign in to comment.

Categories

Find more on Performance and Memory in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!