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 = 'dassl', 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.
Warning: empty y range [1:1], adjusting to [0.99:1.01]
Warning: empty y range [1:1], adjusting to [0.99:1.01]
Warning: empty y range [1:1], adjusting to [0.99:1.01]
Warning: empty y range [1:1], adjusting to [0.99:1.01]
Warning: empty y range [1:1], adjusting to [0.99:1.01]
Warning: empty y range [1:1], adjusting to [0.99:1.01]
LOG_STDOUT        | info    | Time measurements are stored in ProfilingTest_prof.html (human-readable) and ProfilingTest_prof.xml (for XSL transforms or more details)
",
    timeFrontend = 8.37046e-4,
    timeBackend = 0.006212132,
    timeSimCode = 5.71118e-4,
    timeTemplates = 0.0015534160000000002,
    timeCompile = 0.19928504299999994,
    timeSimulation = 0.019930738,
    timeTotal = 0.22844877499999994
end SimulationResult;
"[/var/lib/jenkins1/ws/OpenModelica_PR-10892/OMCompiler/Compiler/BackEnd/SymbolicJacobian.mo:1368:9-1368:86:writable] Error: Internal error function generateSparsePattern failed
Warning: The initial conditions are not fully specified. For more information set -d=initialization. In OMEdit Tools->Options->Simulation->Show additional information from the initialization process, in OMNotebook call setCommandLineOptions(\"-d=initialization\").
[/var/lib/jenkins1/ws/OpenModelica_PR-10892/OMCompiler/Compiler/BackEnd/SymbolicJacobian.mo:1368:9-1368:86:writable] Error: Internal error function generateSparsePattern failed
"

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

dassl

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.000078

9.15%

Initialization

0.000093

10.92%

Event-handling

0.000000

0.00%

Creating output file

0.000066

7.75%

Linearization

NaN%

Time steps

0.000475

55.75%

Overhead

0.000060

7.04%

Unknown

NaN

NaN%

Total simulation time

0.000852

100.00%

Global Steps

Steps

Total Time

F raction

Average Time

Max Time

De viation

|Graph th umbnail 999|

499

0 .000475

55.75%

9.5190 3807615 231e-07

0.00 0029896

30.41x

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>`__

506

0.00 0005513

0.65%

0.00 0000120

10.01x

Measured Blocks

Name

Calls

Time

F raction

Max Time

De viation

|Graph th umbnail eq0|

|Graph

th umbnail count eq0|

` <# eq0>`__

14

0.00 0060072

7.05%

0.00 0060202

13.03x

|Graph th umbnail eq7|

|Graph

th umbnail count eq7|

` <# eq7>`__

2

0.00 0000722

0.08%

0.00 0000732

1.03x

|Graph th umbnail eq11|

|Graph

th umbnail count eq11|

` <#e q11>`__

504

0.00 0138414

16.25%

0.00 0008727

30.78x

|Graph th umbnail eq13|

|Graph

th umbnail count eq13|

` <#e q13>`__

504

0.00 0126872

14.89%

0.00 0007804

30.00x

Equations

Name

Variables

eq0

eq1

y

eq2

s

eq3

z1

eq4

eq5

z2

eq6

eq7

x

eq8

eq9

z2

eq10

eq11

z1

eq12

eq13

x

eq14

der(y)

eq15

Variables

Name

Comment

y

der(y)

x

This is x

z1

z2

s


This report was generated by OpenModelica on 2025-10-11 03:12:49.

Genenerated JSON for the Example

Listing 9 ProfilingTest_prof.json
{
"name":"ProfilingTest",
"prefix":"ProfilingTest",
"date":"2025-10-11 03:12:49",
"method":"dassl",
"outputFormat":"mat",
"outputFilename":"ProfilingTest_res.mat",
"outputFilesize":24581,
"overheadTime":5.9637e-05,
"preinitTime":7.8367e-05,
"initTime":9.2643e-05,
"eventTime":1.42e-07,
"outputTime":6.6294e-05,
"jacobianTime":3.113e-06,
"totalTime":0.000851865,
"totalStepsTime":8.31e-07,
"totalTimeProfileBlocks":0.00032608,
"numStep":499,
"maxTime":2.9896e-05,
"functions":[
{"name":"ProfilingTest.f","ncall":506,"time":0.000005513,"maxTime":0.000000120}
],
"profileBlocks":[
{"id":0,"ncall":14,"time":0.000060072,"maxTime":0.000060202},
{"id":7,"ncall":2,"time":0.000000722,"maxTime":0.000000732},
{"id":11,"ncall":504,"time":0.000138414,"maxTime":0.000008727},
{"id":13,"ncall":504,"time":0.000126872,"maxTime":0.000007804}
]
}

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 121 Setting up the profiler from OMEdit.

When profiling the DoublePendulum example from MSL, the following output in Figure 122 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 122 Profiling results of the Modelica standard library DoublePendulum example, sorted by execution time.