How can I log commands being executed by matlab? Like diary() but for all function calls.
Show older comments
Hi there,
I have a GUI that wanted to log what the user interacts with. In my understading this would be which function calls are being executed in the background and their order, as the user goes about using the app.
Is there a way to tap into this "input stream" and log them into a file? Similar to diary() function but for all the function calls being executed.
My ultimate goal with this log of inputs is to be able to "replay" and rexecute the set of steps the user has made, programatically. Let me know if you suggest another aproach. I imagine this would be a large stack but I can probably come up with something to filter the relevant bits.
Thanks in advance!
2 Comments
Walter Roberson
on 29 Sep 2023
If it were possible at all, it would have to be very extensive since quite a bit of MATLAB is implemented in MATLAB. For example if fsurf() were called, then every line of argument processing of fsurf.m would have to be traced, every test to see what was being done, every calculation to do mesh refinement... until eventually built-in graphics commands were called.
Luciano Branco
on 29 Sep 2023
Edited: Luciano Branco
on 29 Sep 2023
Answers (1)
Bruno Luong
on 29 Sep 2023
1 vote
7 Comments
Luciano Branco
on 29 Sep 2023
Bruno Luong
on 29 Sep 2023
Edited: Bruno Luong
on 29 Sep 2023
What you ask (log with fuction call with full input arguments) is kind of practically impossible. The arguments of the functions when it was called can not be valid (such as object/graphic handle, a position of the mouse, of the slider...) when replay later. You also ask to save an arguments that could potentially be huge and can be stored separately in memory at a given instant (a huge matrix for example). MATLAB can shared data in the memory to save during the run. But when asking to save argument it will take the whole place by itseft, and that multiplied by the time history of the run, it would fillup your storage space very quickly. No one could dare to do that. And saving such stack will slow down significantly function calling and disrupt significantly the normal run.
Some heavily numerical library can have possibility of warm start; development such feature requires a great organization and it is not easy. What you ask is such a generic tool for any existing function out there.
I doubt such tool would exist for any language, any development tool.
Walter Roberson
on 29 Sep 2023
In part, it depends what they need for a replay.
Suppose for example during the original run that figure 3 existed and was a parameter to a function and had accumulated particular properties. Now, during the replay, is the required input a figure that exactly matched the original figure 3, right down to figure number and right down to the fact that at the time of the original run, axes7 existed with 'Tag', 'Walla Walla' (except possibly with the handles being at different locations in memory, as long as they were handles to the same contents) ? Is the purpose to be able to later step through and watch step-by-step how the results were formed based on identical objects?
Or is the purpose more like a "notebook" style of wanting the user to be able to play around and take a closer look at aspects if the user wants to? Because that is different -- the "notebook" style starts with fresh objects (or whatever objects are in memory) and evaluates the steps from the beginning, possibly a section at a time. Matrices do not need to have been saved at each step: the code works based on whatever it happens to find in memory at the time.
The "notebook" style is more or less what Livescript is for.
Luciano Branco
on 30 Sep 2023
Walter Roberson
on 30 Sep 2023
I dealt with something similar in the past. The way I handled it was to create a text-based command language. Each GUI operation was coded in terms of what it did in the internal command language.... which could be recorded and replayed or executed in batch.
Generally speaking, when you have a display component and you have an execution component, there are three major ways that the two can be combined:
- display and execution could be tightly coupled, knowing a lot about each other, in which case changing to a new display model or a new execution strategy might require a lot of co-dependent work; or
- display might be primarily coded as sort of a "front end" to the execution portion, in which case it might be fairly easy to create "macros" because the graphics is calling into a well-defined interface to do the real work anyhow; or
- display might be primary, and the way to create macros might end up being more or less recording mouse movements and key presses and then using java robot facility to replay them. Such macros are not typically human readable (or human comprehendible) and run the risk of failing if the font is changed or a spelling mistake is fixed (because that might make a button a different size and so alter where the robot needs to move to.)
Luciano Branco
on 2 Oct 2023
Strider
on 9 Jun 2024
@Luciano Branco My design space sounds similar to yours and I was approaching it with making a SQLite table(s) of known 'meta-deta' to get back to the state of a GUI. The trivial example would be recreating a tiled layout with several signals on it and having a class that can unpack that SQLite file.
I am interested to hear what solution you chose.
Categories
Find more on MATLAB 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!