You can use Java Flight Recorder (JFR) to profile your Java application on SapMachine, and Java Mission Control (JMC) to do remote profiling and analysis.
-
You have downloaded and installed a JDK Mission Control console. To do that, go to SapMachine → Download → JMC 9, select your operating system, and then choose Download.
-
You have installed the Cloud Foundry command line interface. See: Download and Install the cf CLI
-
You are logged on to a SAP BTP, Cloud Foundry space. See: Log On to the Cloud Foundry Environment Using cf CLI
-
You have a Java application that is up and running on SAP BTP, Cloud Foundry.
-
You have enabled SSH for your application. See: Configuring SSH access at the app level
To profile with JMC, you need to start the Management Agent on a RMI port and then open an SSH tunnel to connect to that port. To do that, follow the steps below.
In the steps below, we use myapp and 5555 as exemplary application name and port. Replace them with your actual app name and a free port number on your localhost.
-
Set the RMI server to
localhost
. To do that, set the following JBP_CONFIG_JAVA_OPTS option in themanifest.yml
file of your application:--- applications: - name: myapp buildpack: sap_java_buildpack ... env: TARGET_RUNTIME: tomcat JBP_CONFIG_COMPONENTS: "jres: ['com.sap.xs.java.buildpack.jre.SAPMachineJRE']" JBP_CONFIG_SAP_MACHINE_JRE: '{version: 11.+}' JBP_CONFIG_JAVA_OPTS: "[java_opts: '-Djava.rmi.server.hostname=127.0.0.1']"
-
Start the Management Agent by running
jcmd
in your Cloud Foundry container. Execute:cf ssh myapp -c "app/META-INF/.sap_java_buildpack/sap_machine_jre/bin/jcmd $(pgrep java) ManagementAgent.start jmxremote.authenticate=false jmxremote.ssl=false jmxremote.port=5555 jmxremote.rmi.port=5555"
Depending on what your SapMachine is using (JRE or JDK), specify the path accordingly (
sap_machine_jre
orsap_machine_jdk
). To learn more, see: SapMachineResult:
7: Command executed successfully
Management Agent is started and is listening to port 5555.
-
(Optional) You can check the status of the Management Agent. Execute:
cf ssh myapp -c "app/META-INF/.sap_java_buildpack/sap_machine_jre/bin/jcmd $(pgrep java) ManagementAgent.status"
-
Enable an SSH tunnel for this port. Execute:
cf ssh myapp -N -T -L 5555:127.0.0.1:5555
Your local port 5555 is connected to the remote port 5555 of the JVM, which is running in the Cloud Foundry container.
The connection is active until you close the SSH tunnel. When you finish profiling, close the SSH tunnel by pressing [Ctrl] + [C].
-
Connect with JMC to
localhost:5555
. To do that:-
Open your JDK Mission Control (JMC) console.
-
From, the JVM Browser tab, choose icon Create a new custom JVM connection.
-
For Port, enter
5555
(or your actual port number), and then choose Finish.
-
-
In the left-side menu, a new node localhost:5555 appears.
-
Double-click on MBean Server.
-
To start profiling, go to Flight Recorder and from its context menu, choose Start Flight Recording.
-
Set up the event settings. From the drop-down menu, choose one of the following options (templates):
-
Continuous – Low overhead configuration, safe for continuous use in production environments
-
Profiling – Low overhead configuration for profiling
-
gc – GC related events. Generates a small recording size.
-
gc_details – GC related events. Gets heap statistic and generates a large recording size.
-
Create your own configuration. To do that, choose Template Manager, then select a predefined template and choose Duplicate. Rename the new template and edit its configuration parameters according to your needs and preferences.
-
-
After profiling is done, go to localhost:5555 and from its context menu, choose Disconnect.
-
Then go back to your command line and close the SSH tunnel by pressing [Ctrl] + [C].
-
Stop the Management Agent. Execute:
cf ssh myapp -c "app/META-INF/.sap_java_buildpack/sap_machine_jre/bin/jcmd $(pgrep java) ManagementAgent.stop"
Related Information