File Exchange

image thumbnail

tracer4m

version 1.1 (214 KB) by

tracer4m traces calls to methods and functions.

4 Downloads

Updated

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

tracer4m traces calls to methods and functions.
Object-oriented design is about distributing responsibilities among interacting objects.
The objects should be small and focused. This results in a complex flow of calls.
Furthermore, in a GUI the user manipulates controls, which in turns trigger events and
chains of calls to methods and functions. There is a need to trace the calls.
The goal of tracer4m is to support unit testing, debugging, and analysis of existing code.
Example based on "Example - Using Events to Update Graphs" from the Matlab on-line help

feobject = fcneval( @(x,y) x.*exp(-x.^2-y.^2), [-2 2 ] );
fcnview.createViews( feobject );
log = TraceHistory.Instance;
log.setup( { 'fcneval', 'fcnview', 'createViews' } )
feobject.FofXY = @(x,y) x.*exp(-x.^.5-y.^.5);
disp( log )
%
log.clearHistory
feobject.Lm = [-8 3];
disp( log )

Part of the result is depicted in the image above.

Documentation: tracer4m_demo.html, which is generated by PUBLISH, discusses and demonstrate the use and behaviour of tracer4m.

I would appreciate comments especially regarding requirements on tracing tools for Matlab

Comments and Ratings (7)

Arabarra

Very useful. For workflows requiring complex interactions between objects, the native Matlab tools for debugging are not sufficient. Specially when communication through events is heavy, I always end up setting miriads of breakpoints.... this tool is just what I've been needing!

Zhao g-liang

a nice work

Thank you for this great tool, I can verify it worked on R2015a as well.

Therry

Therry (view profile)

Hello Per,
the new issue works well! Thank you for the good tool.
Best Regards
Therry

Therry

Therry (view profile)

Hello Per,
using tracer4m in Release R2016a with the tracer4m_demo runs in a problem in TraceHistory line 188ff {for ii = 1 : numel( sam )} for line 202 (s2 = regexp( sam(ii+1).message). In the last loop sam(ii+1) doesn't exist. Can you help?
Best Regards
Therry

per isakson

Jesse, thanks for the comment. The purpose of pause(0.001) *was* to ensure that each successive call should have a unique timestamp. That was useful during debugging.

Jesse Hopkins

Jesse Hopkins (view profile)

Wow thank you for this incredibly useful utility. I had one hickup which was user error. I used the output of "dir" to pass into the setup function, which broke the setup. Worked fine once I stripped off the ".m" extension from the filenames returned by dir.

Afterwords, everything "just worked", and I was able to get incredibly useful traces. I had attempted something simliar in the past, but never could get anything working without instrumenting the code. Well done using mlint & conditional breakpoint side effects to get function traces without needing to modify code.

Question: Why call pause(0.001) in TraceHistory.add?

Updates

1.1

Previous upload failed. Better luck this time :-)

1.1

Fixed the problem with R2016a reported by Therry. The revised code is tested only on R2016a, but "should" run on older versions.

Removed the limitation regarding function name reported by Jesse Hopkins. Now it also takes file names with wildcards.

MATLAB Release
MATLAB 9.0 (R2016a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today