Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profile mex function in visual studio

In here it is explained how to profile an .exe file in visual studio. Is there any way to profile a mex code using the same procedure?

Thanks.

like image 719
Thoth Avatar asked Feb 13 '23 03:02

Thoth


1 Answers

You sure can. Just enable generation of debug info (symbols) when building the MEX file, and attach to MATLAB.exe from the Analyze->Profile menu in Visual Studio.

It's nearly the same procedure as for debugging MEX files with Visual Studio. The process is trivial if you built the MEX file with a VS project (rather than the mex command), in which case you simply enable Profiling information in the project (Linker-Advanced-Profile property), build, and then attach to MATLAB.exe from the Analyze->Profiler->Attach/detach... menu item.

If you are building with mex from MATLAB, you need to enable building a MEX file with symbolic information, but also enable optimization:

mex -g -O -largeArrayDims myMEX.cpp

I generally build MEX files from VS projects rather than with mex, so I can't say how well this latter option works, but the documentation for the -O switch suggests that you can have optimization and symbolic information generation at the same time. EDIT: It may also require editing your mexopts.bat and adding /DEBUG /PROFILE (does not disable compiler optimizations!) to LINKFLAGS. This may also allow you to omit -g from mex, but I can't say.

EDIT 2: From R2014a, MEX options are no longer managed with .bat files. Instead, look for an XML file like C:\Users\Jon\AppData\Roaming\MathWorks\MATLAB\R2014a\mex_C_win64.xml.

like image 164
chappjc Avatar answered Feb 19 '23 18:02

chappjc