File Exchange

image thumbnail

tracer4m

version 1.1.0.0 (214 KB) by per isakson
tracer4m traces calls to methods and functions.

3 Downloads

Updated 11 Sep 2016

View Version History

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

Cite As

per isakson (2020). tracer4m (https://www.mathworks.com/matlabcentral/fileexchange/28929-tracer4m), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (11)

Paul Dirac

Hi.
Does it also work on App Designer's .mlapp files?

per isakson

@Zoltán, I have reproduced the issue that you detected. Thanks for reporting.

A quick and dirty fix is to add the following if-statement after the line, obn = regexp( str, xpr, 'match', 'once' );

if isempty( obn ) || strcmp( obn, '~' )
obn = '117';
end

The reason I pass the name of the object to the function, tracer, is to allow this function to save the state of the object to a "log-file".

per isakson

@Zoltán, I have reproduced the issue, which you detected. Thanks for reporting.

A quick and dirty fix is to add the following if-statement after the line, obn = regexp( str, xpr, 'match', 'once' );

if isempty( obn ) || strcmp( obn, '~' )
obn = '117';
end

The reason I pass the name of the object to the function, tracer, is to allow this function to save the state of the object to a "log-file".

Zoltán Csáti

TraceHistory cannot handle the situation when a method has input argument ~. In that case, break_condition_for_class_ generates tracer( ~, 'begin' ), which is not allowed in dbstop.

Bug: suppose that TraceHistory.setup is currently processing method A in class C. If there is a method B in class C which calls method A and method B is earlier in class C than method A, then obn = regexp( str, xpr, 'match', 'once' ); returns the wrong position on line 442.

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

Vikaasa Kumar

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

Therry

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

Therry

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

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?

MATLAB Release Compatibility
Created with R2016a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!