Modelica Performance Analyzer

A common problem when simulating models in an equation-based language like Modelica is that the model may contain non-linear equation systems. These are solved in each time-step by extrapolating an initial guess and running a non-linear system solver. If the simulation takes too long to simulate, it is useful to run the performance analysis tool. The tool has around 5~25% overhead, which is very low compared to instruction-level profilers (30x-100x overhead). Due to being based on a single simulation run, the report may contain spikes in the charts.

When running a simulation for performance analysis, execution times of user-defined functions as well as linear, non-linear and mixed equation systems are recorded.

To start a simulation in this mode, turn on profiling with the following command line flag >>> setCommandLineOptions("--profiling=all")

The generated report is in HTML format (with images in the SVG format), stored in a file modelname_prof.html, but the XML database and measured times that generated the report and graphs are also available if you want to customize the report for comparison with other tools.

Below we use the performance profiler on the simple model A:

model ProfilingTest
  function f
    input Real r;
    output Real o = sin(r);
  end f;
  String s = "abc";
  Real x = f(x) "This is x";
  Real y(start=1);
  Real z1 = cos(z2);
  Real z2 = sin(z1);
equation
  der(y) = time;
end ProfilingTest;

We simulate as usual, after setting the profiling flag:

>>> setCommandLineOptions("--profiling=blocks+html")
true
>>> simulate(ProfilingTest)
record SimulationResult
    resultFile = "«DOCHOME»/ProfilingTest_res.mat",
    simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-6, method = 'auto', fileNamePrefix = 'ProfilingTest', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
    messages = "LOG_SUCCESS       | info    | The initialization finished successfully without homotopy method.
LOG_SUCCESS       | info    | The simulation finished successfully.
LOG_STDOUT        | info    | Time measurements are stored in ProfilingTest_prof.html (human-readable) and ProfilingTest_prof.xml (for XSL transforms or more details)
",
    timeFrontend = 0.002552532,
    timeBackend = 0.013967691,
    timeSimCode = 0.004499728,
    timeTemplates = 0.009943699,
    timeCompile = 0.536707576,
    timeSimulation = 0.060774849,
    timeTotal = 0.62880353
end SimulationResult;

Profiling information for ProfilingTest

Information

All times are measured using a real-time wall clock. This means context switching produces bad worst-case execution times (max times) for blocks. If you want better results, use a CPU-time clock or run the command using real-time priviliges (avoiding context switches).

Note that for blocks where the individual execution time is close to the accuracy of the real-time clock, the maximum measured time may deviate a lot from the average.

For more details, see ProfilingTest_prof.xml.

Settings

Name

Value

Integration method

auto

Output format

mat

Output name

ProfilingTest_res.mat

Output size

24.0 kB

Profiling data

ProfilingTest_prof.data

Profiling size

0 B

Summary

Task

Time

Fraction

Pre-Initialization

0.000197

9.71%

Initialization

0.000471

23.22%

Event-handling

0.000004

0.20%

Creating output file

0.000541

26.68%

Linearization

NaN%

Time steps

0.000621

30.62%

Overhead

0.000219

10.80%

Unknown

NaN

NaN%

Total simulation time

0.002028

100.00%

Global Steps

Steps

Total Time

F raction

Average Time

Max Time

De viation

|Graph th umbnail 999|

499

0 .000621

30.62%

1.2444 8897795 591e-06

0.00 0084115

66.59x

Measured Function Calls

Name

Calls

Time

F raction

Max Time

De viation

|Graph th umbnail f unction fun0|

|Graph

th umbnail count f unction fun0|

` Profili ngTest. f <#lin e=0>`__

6

0.00 0000280

0.01%

0.00 0000240

4.14x

Measured Blocks

Name

Calls

Time

F raction

Max Time

De viation

|Graph th umbnail eq0|

|Graph

th umbnail count eq0|

` <# eq0>`__

8

0.00 0090098

4.44%

0.00 0090266

7.01x

|Graph th umbnail eq11|

|Graph

th umbnail count eq11|

` <#e q11>`__

2

0.00 0001633

0.08%

0.00 0001657

1.03x

|Graph th umbnail eq19|

|Graph

th umbnail count eq19|

` <#e q19>`__

4

0.00 0006169

0.30%

0.00 0005086

2.30x

|Graph th umbnail eq21|

|Graph

th umbnail count eq21|

` <#e q21>`__

4

0.00 0002402

0.12%

0.00 0001348

1.24x

Equations

Name

Variables

eq0

eq1

y

eq2

s

eq3

z1

eq4

eq5

` <#var0>`__

eq6

` <#var0>`__

eq7

` <#var0>`__

eq8

` <#var0>`__

eq9

z2

eq10

eq11

x

eq12

eq13

z2

eq14

eq15

` <#var0>`__

eq16

` <#var0>`__

eq17

` <#var0>`__

eq18

` <#var0>`__

eq19

z1

eq20

eq21

x

eq22

der(y)

eq23

Variables

Name

Comment

y

der(y)

x

This is x

z1

z2

s


This report was generated by OpenModelica on 2026-12-03 03:35:45.

Genenerated JSON for the Example

Listing 10 ProfilingTest_prof.json
{
"name":"ProfilingTest",
"prefix":"ProfilingTest",
"date":"2026-12-03 03:35:45",
"method":"auto",
"outputFormat":"mat",
"outputFilename":"ProfilingTest_res.mat",
"outputFilesize":24581,
"overheadTime":0.000218796,
"preinitTime":0.00019669,
"initTime":0.000470789,
"eventTime":4.308e-06,
"outputTime":0.000541058,
"jacobianTime":2.561e-06,
"totalTime":0.00202769,
"totalStepsTime":1.041e-06,
"totalTimeProfileBlocks":0.000100302,
"numStep":499,
"maxTime":8.4115e-05,
"functions":[
{"name":"ProfilingTest.f","ncall":6,"time":0.000000280,"maxTime":0.000000240}
],
"profileBlocks":[
{"id":0,"ncall":8,"time":0.000090098,"maxTime":0.000090266},
{"id":11,"ncall":2,"time":0.000001633,"maxTime":0.000001657},
{"id":19,"ncall":4,"time":0.000006169,"maxTime":0.000005086},
{"id":21,"ncall":4,"time":0.000002402,"maxTime":0.000001348}
]
}

Using the Profiler from OMEdit

When running a simulation from OMEdit, it is possible to enable profiling information, which can be combined with the transformations browser.

Profiling setup

Figure 154 Setting up the profiler from OMEdit.

When profiling the DoublePendulum example from MSL, the following output in Figure 155 is a typical result. This information clearly shows which system takes longest to simulate (a linear system, where most of the time overhead probably comes from initializing LAPACK over and over).

Profiling results

Figure 155 Profiling results of the Modelica standard library DoublePendulum example, sorted by execution time.