MATLAB: How to use a MATLAB script to create a profile with Dependency Walker

MATLAB

I want to create a Dependency Walker profile for MATLAB running some function on my Windows PC. However, it is difficult to properly configure Dependency Walker for profiling and so I wonder if there is a script available that helps me doing this?

Best Answer

You can execute the following MATLAB script which determines your computer architecture, then downloads the proper version of Dependency Walker into your TEMP directory. It then starts Dependency Walker in profiling mode. This launches another session of the MATLAB version that you are using to run this script. In this other session perform the operation that you want to profile. When done close that MATLAB session. Dependency Walker will save an image file (*.dwi) on your Desktop. The script will then also create a zipped version of the image file.
 
arch = computer('arch');
url = 'http://www.dependencywalker.com/depends22_x64.zip';
if strcmp(arch,'win32'), url=strrep(url,'x64','x86'); end
unzip(url,tempdir);
fn = fullfile(getenv('userprofile'),'Desktop',['Profile_of_MATLAB_' ...
version('-release') '_' arch]);
mr = fullfile(matlabroot,'bin',arch);
dos([fullfile(tempdir,'depends.exe') ' /c /f:1 /ps:1 /pp:1 /po:1 /ph:0 '...
'/pt:1 /pn:1 /pe:0 /pm:1 /pf:1 /pi:1 /pc:0 /pd:"' mr '" /pb /od:"' ...
[fn '.dwi'] '" "' fullfile(mr,'\matlab.exe"')]);
zip([fn '.zip'],[fn '.dwi']);
delete(fullfile(tempdir,'depends.*'));
This script is also attached below. You could even just execute the following line of code in MATLAB to run the script and create the profile without having to manually download anything:
 
eval(urlread('http://mathworks.com/matlabcentral/answers/uploaded_files/6858/create_DW_profile.m'))