1

I need to measure the execution time of a subsystem (group of Simulink blocks) which runs as an atomic unit with a specific sampleTime. The measurement will be done on a Real-time embedded target hardware by flashing code generated by Simulink coder.

I am planning to use the custom code block in Simulink coder to add counters to the generated code. By using specific code at entry and exit of the generated code for subsystem, I plan to count number of clock cycles taken to execute the subsystem.

dSpace RTI library has clock counters like

/* Start time measurement.*/
RTLIB_TIC_START();          

/*code*/

/* Read the elapsed time period. */      
subsystem_exec_time_1 = RTLIB_TIC_READ();

However, I am not sure if I have dSpace libraries at my disposal. My question is how do I write a counter or a function to log elapsed real-time or count number of clock cycles taken for execution? Is there a way that simulink enables such measurements?

Daniel
  • 36,610
  • 3
  • 36
  • 69
  • 1
    Measuring execution time is a very hardware specific operation so there's no way that (plain vanilla) Simulink is going to be able to do it. You'll need to use appropriate libraries/functionality/monitoring tools available with your RTOS. – Phil Goddard May 06 '19 at 15:28
  • 1
    Agree with Phil. Just like to add that you cancall C-code in simulink. E.g. true RTOS timing lib calls, or own hacks (expect it to be inaccurate): Methods; Matlab Functions with "ceval" or TLC S-function wrapper. The trick is to force Simulink to insert those calls in the right places, but a block that does a NOP on an input signal will be called before your atomic subsystem, and one on an output signal will be inserted afterwards. Ceval call will be made in both Simulink and target execution (both a pro/con) TLC code only acts on target. Search "ceval" or "TLC S-function wrapper" in docs. /BR – ErikP May 06 '19 at 20:32
  • 1
    Which processor are you using? Simulink now has ability to profile execution times on some architectures. – R S May 07 '19 at 06:09
  • @ErikP , Exactly what I want to do, Call a custom C code in right places. Simulink coder has custom code blocks like (System output, System update etc). And it already inserts the code where I want it to. I was looking for a Simulink (Plain vanilla as Phil says) function that counts clock cycles rather than an RTOS functions. I have to develop this with a limited access to RTOS details. Thanks guys this helps :) – Bhargav Kinnal May 07 '19 at 07:52
  • @RS I have surveyed this option and it does not work for me. Or atleast I will use this as a final option when nothing works for me. Thanks – Bhargav Kinnal May 07 '19 at 07:53

0 Answers0