- “LibMdlStartCustomCode“and”LibMdlTerminateCustomCode” These target only the model’s top level initialization and termination functions, not every function generated by Embedded Coder.
- “LibSystemInitializeCustomCode”,”LibSystemOutputCustomCode”,”LibSystemUpdateCustomCode” These apply within each subsystem’s functions (initialize, output, update), but only where subsystems are defined. They do not cover other generated functions like utility or block-specific functions.
- “LibGetModelDotCFile”+LibSetSourceFileSection This lets you inject code into the “Functions” section of the model’s main.c file, but again, this is not true per-function instrumentation.
TLC function generation hook
8 views (last 30 days)
Show older comments
I'm trying to generate some code for a Simulink model using embedded coder and want to manually profile each of the generated functions by inserting a log statement at the start and end of the function body (before the return statemtent). Each function should have an ID that is passed to the logging statement inside the function and this function <-> ID mapping should be recorded in a separate header file.
Something along the lines of
int my_generated_func() {
LOG(300);
/* Function body */
LOG(300);
return 0;
}
I've seen examples of hooking in before and after code generation, but not during.
Can I get any suggestions on how to set this up:
- Is this possible, or do I need post processing methods? (I'd prefer avoiding post processing)
- Which TLC functions can I hook into to generate the log statements?
- Would this be more viable using a MATLAB script or native TLC code?
Thanks in advance
0 Comments
Answers (1)
Arushi
on 14 Aug 2025
Edited: Arushi
on 14 Aug 2025
Hi Eamon,
Yes, this is possible without post-processing but there’s no single TLC function that will automatically instrument every generated function. There are, however some TLC functions that can partially help:
You can refer to the documentation for more detail:
If still you want to modify all functions, you will need to edit the TLC templates that define how functions are emitted. This is not recommended on the original files , instead make a copy of the TLC files, modify those, and point your build to the custom ert.tlc so your changes are isolated.
Some TLC files you might look at include:
codetemplatelib.tlc
commonbodlib.tlc
hookslib.tlc
blocklib.tlc
In this case,native TLC modification is more viable than MATLAB Script. Changes are applied before the C code is written to disk, so you avoid extra parsing, patching, or string matching afterward.
0 Comments
See Also
Categories
Find more on Simulink Coder 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!