Rational® Rhapsody® includes
an option to optimize the code generated for port connections. In
many scenarios, this can result in improved performance of your application.
Note: This feature is only available for C++ code.
When ports are used in models, there are often situations where
a chain of non-behavioral ports are connected to each other, with
calls being delegated from one end to the other. This results in poorer
runtime performance and also makes debugging the application more
difficult.
To prevent this kind of problem, you can use the port connection
optimization feature. When you use this code generation option, the
generated code is designed to connect the ports at either end of this sort of
chain at run time.
When deciding whether to use the connection optimization feature
for ports, take into account that there is a trade-off. The optimized
code results in improved performance, but also uses more memory temporarily
when the application starts and the ports are initialized.
When using this optimization feature, code is not optimized for
connections involving the following types of ports:
- rapid ports
- multicasting ports
- ports with required interfaces that contain only event receptions
- ports with provided interfaces that contain at least one event
(or are derived from classes with at least one event)
Use of port connection optimization is controlled by the following
properties:
- CPP_CG::Configuration::OptimizePortConnectors - determines whether Rational Rhapsody should
generate the code required for optimization, in full or in part
- CPP_CG::Port::IncludeInConnectorOptimization - determines which
ports are included in the optimization when it is used
Controlling generation of port connection optimization
code
The port connection optimization code consists of:
- infrastructure code to make the feature possible
- a call to a macro called OM_OPTIMIZE_PORT_CONNECTORS to
actually enable the feature. This macro calls the optimization algorithm
that computes and sets the destination for each port
The OptimizePortConnectors property controls the generation
of this code, providing the following possible values:
- NoOptimization—no optimization is used - neither the infrastructure
code nor the call to the macro is generated
- ActivateInComponent—Rational Rhapsody generates
both the infrastructure code and the call to the macro. For executable
components, the macro call is generated in the main function. For
libraries, the call is generated in the constructor of the class representing
the component. The call to the macro is made after all the relations
have been initialized. When this value is used, optimization is enabled
for ports at the component level, meaning that only links within the
component are optimized.
- ActivateExternally—the required infrastructure code is generated
but Rational Rhapsody does
not generate the call to the OM_OPTIMIZE_PORT_CONNECTORS macro. It
is left to the user to include the call to this macro in the code
of a component that uses the optimized component or in other user-provided code.
Note: The
call to the macro frees up the extra memory that was used during port
initialization. So if you use the ActivateExternally property value,
but do not include a call to the macro, this memory will not be freed.
The ActivateInComponent value is appropriate for executables. For
libraries, it is appropriate in situations where the components that
use the library do not have to know whether port connector optimization
is used or not.
The ActivateExternally value should be used
in situations where cross-component connections must be optimized.
It is also appropriate in situations where port connections are also
initialized manually.
Note: If there are no links between ports
in a component, then even if you select the ActivateInComponent property
value, the code generated is the same as the code generated when the
ActivateExternally property value is used. This means that the required
infrastructure code is generated but the generated code does not include
a call to the OM_OPTIMIZE_PORT_CONNECTORS macro.
In such cases, the extra memory that was used during port initialization
is only freed if you include your own call to the macro.
Controlling which port connections are optimized
If
you have set the value of the OptimizePortConnectors property to use
optimization, you can control which port connections are optimized
by setting the value of the Boolean property CPP_CG::Port::IncludeInConnectorOptimization.
If
a chain of ports includes a port for which the value of the property
is set to False, that port will not be included in the optimization,
but optimization will still be used for the other port connections
in the chain.
Customizing the port connection optimization code
The following
properties can be used to customize the port connection optimization
code, for example the names of the macros used and the header files
included:
- CPP_CG::Framework::PortConnectorsOptimizationBaseClassPattern
- CPP_CG::Framework::PortConnectorsOptimizationImpIncludeFiles
- CPP_CG::Framework::PortConnectorsOptimizationOptimizationPattern
- CPP_CG::Framework::PortConnectorsOptimizationRegistrationPattern
- CPP_CG::Framework::PortConnectorsOptimizationSpecIncludeFiles