how to save number of function calls from profile

2 次查看(过去 30 天)
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?

回答(1 个)

Philip Borghesani
Philip Borghesani 2016-8-17
编辑:Philip Borghesani 2016-8-17
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 个评论
H D
H D 2016-8-18
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 2016-8-18
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]

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Performance and Memory 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by