Can the Code Profiler be used programmatically to profile an app in App Designer?

3 views (last 30 days)
I am aware that I can open the Profiler, click 'start profiling' run my app, then stop profilling and view it.
Can I initiate the start and stop of the profiling programatically?
tic/toc is good, but that's better to test implementations. the Profiler is great to look at overall where my code is slow.

Accepted Answer

Voss
Voss on 28 May 2022
"Can I initiate the start and stop of the profiling programatically?"
Yes. See the "action" input argument part of the documentation for profile:
Using some of those actions, maybe you can do what you want:
% turn on and start the profiler:
profile('on');
profile('resume');
% run a function:
test_func();
% get the current profiler info:
s = profile('info')
s = struct with fields:
FunctionTable: [44×1 struct] FunctionHistory: [4×396 double] ClockPrecision: 1.0000e-06 ClockSpeed: 3.4554e+09 Name: 'MATLAB' Overhead: 0
s.FunctionTable
ans = 44×1 struct array with fields:
CompleteName FunctionName FileName Type Children Parents ExecutedLines IsRecursive TotalRecursiveTime PartialData NumCalls TotalTime
% get the info about the function test_func:
s.FunctionTable(strcmp({s.FunctionTable.FunctionName},'test_func'))
ans = struct with fields:
CompleteName: '/users/mss.system.IR6him/test_func.m>test_func' FunctionName: 'test_func' FileName: '/users/mss.system.IR6him/test_func.m' Type: 'M-function' Children: [0×1 struct] Parents: [1×1 struct] ExecutedLines: [5×3 double] IsRecursive: 0 TotalRecursiveTime: 0 PartialData: 0 NumCalls: 1 TotalTime: 6.6100e-04
% stop the profiler:
profile('off');

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!