An Introduction to Using BtM's features within TPTP
An Introduction to Using BtM's features within TPTP

Important: This user guide is assumed to be used with TPTP 4.4
The following document provides an overview of using the Build-to-Manage Toolkit (BtM) features currently available within TPTP. These plugins allow the user to instrument their java application using one of three technologies: Application Responses Measurement (ARM), Java Management Extensions (JMX), and Common Base Events (CBE).

Table of Contents:
1.0 Introduction - Description and Purpose
1.1 Requirements and Install
1.2 Known Limitations and Workarounds
1.3 Configuring Agent Controller
1.3.1 Configuring Remote Agent Controller (RAC)
2.0 Instrument Java Application
2.1 Instrumentation Preferences
2.2 Using filters and Byte code type
2.3 Instrument Java Application using ARM
2.3.1 Using ARM with Application Servers
2.3.1.1 IIOP Portable Request Interceptor
2.3.2 Viewing ARM data
2.4 Instrument Java Application using JMX
2.4.1 Using Managed Agent Explorer with JMX
2.5 Instrument Java Application using CBE
2.5.1 Viewing CBE logs
2.6 Source Editing
2.6.1 CBE Instrumentation using Source Editing
2.6.2 ARM Instrumentation using Source Editing
2.7 Exporting instrumented jars
2.8 Running instrumented application

1.0 Introduction - Description and Purpose

The Build-to-Manage Toolkit for Java Instrumentation promotes a set of management standards that have been available for Java programmers for some time. This document describes how to use these management standards to help instrument user code for response time measurement, management, and event creation.


1.1 Requirements and Install

BtM is developed based-on TPTP 4.4. BtM supports two byte code instrumentation mechanism: Probekit and AspectJ.

  1. Eclipse 3.3+
  2. TPTP 4.4+
  3. AspectJ requires AJDT 1.5

Follow the steps below to obtain a copy of BtM:

  1. Click on the 'TPTP all-in-on' link from TPTP's download page: http://www.eclipse.org/tptp/home/downloads
  2. Download the Agent Controller for your platform from the TPTP download page.
  3. Install AJDT 1.5 (optional. If you want to use AspectJ weaving technology, you must install AJDT).

Installing BtM

  1. Unzip 'TPTP all-in-on' package to the Eclipse installation directory, for example, D:\eclipse.
  2. Unzip the Agent Controller to the Agent Controller installation directory, for example, D:\agentcontroller. Read the getting_started.html file included with the Agent Controller download on installation and usage.


1.2 Known Limitations and Workarounds

The list below indicates some of the known limitations of the BtM.

1.3 Configuring Agent Controller

BtM supports Integrated Agent Controller (IAC) for JMX and CBE instrumentation and Remote Agent Controller (RAC) for ARM, JMX, and CBE's.

1.3.1 Configuring Remote Agent Controller (RAC)

  1. Click on the 'Latest Downloads' link from TPTP's home page: http://www.eclipse.org/tptp and select the version and the build that you wish to download.
  2. Select a convenient download mirror and save the zip file.
  3. To install the Agent Controller, unzip the zip file into a directory of your choice (e.g. c:\raserver). For information on setting up and running Agent Controller, see the Agent Controller Getting Started Guide include in the zip.
  4. Stop the Agent Controller
  5. Run SetConfig script
  6. Start the Agent Controller

2.0 Instrument Java Application

All java instrumentation takes placing using the Profile menu option and Profiling wizard available within TPTP. BtM Application Response Measurement (ARM) instrumentation places in the ARM start and stop calls for the specified methods selected in the Instrument filter.

BtM Java Management Extension (JMX) instrumentation automatically registers ModelMBeans (with required metadata) for the specified methods and member variables using an after advice (or exit fragment). BtM preferences determine which MBean server is to be used. The user can have JMX notifications sent for failures, successes, JMX attribute changes, and method execution time.

The BtM Common Base Events model formats log events to a specific XML schema. Events are derived from situations that the user selects in the event wizard. BtM�s CBEs indicate the exception thrown and the stack trace of the entry and exit method.

2.1 Instrumentation Preferences

To change the defaults, follow these steps:

  1. Select Window > Preferences. The Preferences window opens.
  2. From the tree on the left, select Profiling and Logging -> Instrumentation. The Instrumentation preferences pane opens.
  3. Use this pane to:
    • To select byte code type
    • Setup CBE logging information and properties
  4. Click Apply. Your choices take effect in all currently open profiling windows. Click OK to close the Preferences window.
2.2 Using filters and Byte code type

In the Instrument Collector filters can be added or removed to help the user determine what packages, classes, and/or methods to be include or exclude during instrumentation. Filters can be configured from the Instrument Collector -> Edit Options.

  1. Instrument Data Collector, the desired filters for instrument packages, classes or methods can be applied. For the purposes of this example, Select Default filter set.


    Figure 2.1 - Instrument Collector Filter

  2. Click Add to the right of the list of rules to add a new rule to the filter set. For example, add samle.bookstore in the Package field and * in the Class field and Method name field, select INCLUDE for the Rule, then click OK.


    Figure 2.2 - Add filter

  3. Click Next you must select the Byte Code Type you want to instrument your applications. Two instrumentation types are available: Probes and AspectJ. To select AspectJ type Byte Code, you must install AJDT 1.4.0; otherwise AspectJ will not be listed as an option.
  4. Click Finish

2.3 Instrument Java Application using ARM

  1. To monitor an application using ARM, select File Menu > Run > Profile.... The Profiling wizard opens.
  2. In the left pane (Configurations), select Java Application.
  3. Click New. A new configuration is created with the default name New_configuration.
  4. On the Main tab, browse to the Project and Main class that you want to profile.
  5. From the Profile Configuration screen select the Monitor tab -> Application Response Measurement Analysis under the Instrument Collector.


    Figure 2.3 - Select ARM Analysis Type

  6. Instrument type can be configured from the Application Response Measurement Analysis -> Edit Options. For most application Generic should work just fine, but for J2EE application and Tomcat you may want to use servlet, ejb and jdbc to get more detail information.


    Figure 2.4 - Select ARM Instrument Types

  7. Press the Profile button at the bottom to run your application with ARM Instrumentation.

2.3.1 Using ARM with Application Servers

The Profiling tool using the Application Response Measurement analysis type provides the ability to attach to a running application or to launch an application for profiling. Attaching to an application means that a monitor is created to contain the results observed by an associated agent. Launching a process means that the process is started with an agent is associated with to process, and a monitor is created to contain the results observed by the agent.

Attaching to a an application server requires either statically applied probes or placing arm calls directly in the application.

2.3.1.1 IIOP Portable Request Interceptor
For WebSphere Application Server to monitor IIOP calls with ARM you need to add the following items.
2.3.2 Viewing ARM data

The Application Response Measurement Analysis type provides a number of different views and tables to help visualize the profiling data.

  1. Select Application Response Measurement Analysis in the Profiling Monitor tab and right click to list the available views.


    Figure 2.5 - ARM views

  2. After select the desired view the ARM data will be displayed

2.4 Instrument Java Application using JMX

  1. To monitor an application using JMX, select File Menu > Run > Profile.... The Profiling wizard opens.
  2. In the left pane (Configurations), select Java Application.
  3. Click New. A new configuration is created with the default name New_configuration.
  4. On the Main tab, browse to the Project and Main class that you want to profile.
  5. From the Profile Configuration screen select the Monitor tab -> Java Management Extension Analysis under the Instrument Collector.
  6. Press the Profile button at the bottom to run your application with JMX Instrumentation.
  7. In the Profiling Console register mbeans names will be displayed.

2.4.1 Using Managed Agent Explorer with JMX

The Monitoring Instrumentation UI plug-in includes an implementation for JMX against org.eclipse.tptp.monitoring.managedagent.internal.ManagedResourceAgent. We can use the managed agent explorer to view those created and registered MBeans during the above instrumentation.

  1. To view the MBeans created, select File Menu > Run > Profile.... The Profiling wizard opens.
  2. In the left pane (Configurations), select Managed Resource.
  3. Click New. A new configuration is created with the default name New_configuration.
  4. Select JMX resource under Monitor tab, and press the Edit Options button to configure JMX Service URL address.
    • The Edit Options allows the user to specify the either to use the Embedded JMX MBean Server or specify a remote server.
    • If you want to retrieve the MBeans which are created and registered by Monitoring Instrumentation plug-in, you have to choose Embedded MBeanServer. If you want to view resources on any other MBeanServer, please choose Remote MBeanServer.

    Figure 2.6 - Create Resource Browser

  5. Press the Profile button.
  6. Right-click a MBean Server and select Launch agent to launch a new agent to view the details of this selected MBean.
    Figure 2.7 - Select Resource Browser

  7. The Managed Agent Explorer shows the registered mbeans for the selected MBean Server. To retrieve the attributes and operations right-click on an mbean and select Launch agent.
  8. The mbean info is broken into either properties (attributes in JMX) or operations.
    • To invoke attributes select the property in the Managed Agent Browser, change the value and push enter.
      Figure 2.8 - Change Property

    • To invoke operations select the operation in the Managed Agent Browser, fill in the required parameters and push the invoke button.
      Figure 2.9 - Change Property

2.5 Instrument Java Application using CBE

  1. To monitor an application using CBE, select File Menu > Run > Profile.... The Profiling wizard opens.
  2. In the left pane (Configurations), select Java Application.
  3. Click New. A new configuration is created with the default name New_configuration.
  4. On the Main tab, browse to the Project and Main class that you want to profile.
  5. From the Profile Configuration screen select the Monitor tab -> Common Base Event Analysis under the Instrument Collector.
  6. Click Edit Option to set CBE Configuration information.
    • CBE Scenario Selection: select Method CBE Instrument or Callsite CBE Instrument scenario.
    • Instrument Type Selection: for Method CBE Instrument, it provides three instrument types: Method Catch - log event while there is an exception, Method Entry - log event while entry a method and Method Exit - log event while exit a method; for Callsite CBE Instrument, it provides two instrument types: Before Call Method - log event before the method is called and After Call Method - log event after the method is called.
    • IV. CBE Output Selection: select output CBE messages to Logging Agent or Console.



    • Figure 2.10 - CBE Options

  7. Click Finish
  8. Press the Profile button at the bottom to run your application with CBE.

2.5.1 Viewing CBE logs

CBE have to output formats Logging Agent or Console. For the Console the CBE message are displayed in the Profiling perspective console. Follow the steps below to view the CBE messages in the Logging Agent.

  1. For Selecting output CBE to Logging Agent, A new item CBE Analysis Logging Agent appears in Profiling and Logging view.
  2. Right-Click CBE Analysis Logging Agent to Select Open With... >Log View from popup menu.
  3. CBE messages will be listed in Log view

2.6 Source Editing

The above sections have described how to use BtM toolkit to instrument Java application dynamically, that is, without source code changing. Source Editing is an alternative way provided by TPTP BtM to instrument Java application statically. Right-clicking in the source code region in Java editor, the related menus will be shown in the Source popup menu.


Figure 2.11 Source popup menu

Note: If placing the cursor within a method body, the instrumentation code will be only inserted into this method. If placing the cursor outside any method body, the instrumentation code will be inserted into all methods in the class.

2.6.1 CBE Instrumentation using Source Editing

There are two entries in the popup right-clicking menu for CBE, one is Add CBE Entry/Exit, the other is Add CBE Exception Catch. The first one can be used for any method, and the later one can only used for the method which includes a catch statement.


Figure 2.12 Original code


Figure 2.13 Instrumented code with CBE

In the above two figures, the CBE Entry/Exit code snippet is added into the method echo, and the CBE Exception Catch code snippet is added into the method sleep.

After adding the static instrumentation code into the source file, you can right-click those methods again, and will see the corresponding entries for deletion. One is Remove CBE Entry/Exit, and the other is Remove CBE Exception Catch.

Then you can open the launch configuration window of profiling mode, and select CBE Analysis. Do some configurations if necessary, and press the Profile button to begin profiling.

2.6.2 ARM Instrumentation using Source Editing

There is one entry in the popup right-clicking menu for ARM, it's Add ARM Instrumentation. Of course, there is a corresponding entry for deletion, it's Remove ARM Instrumentation.


Figure 2.14 Instrumented code with ARM

In the above figure, the ARM code snippet is added into the method echo.

Then you can open the launch configuration window of profiling mode, and select ARM Analysis. Do some configurations if necessary, and press the Profile button to begin profiling.

2.7 Exporting instrumented jars
  1. To export the instrumented jars, select File > Export.... The exporting wizard opens.
  2. Click the plus symbol before Java node, and select "JAR file with instrumentation support".


    Figure 2.15 Exporting wizard - guide

  3. Select the resources which you want to export, specify where the jar file will be exported, and select instrumentation type(s) you are using.


    Figure 2.16 Exporting wizard - selection

  4. Click Finish
2.8 Running instrumented application

In order to run an instrumented application outside Eclipse environment, we need to add some required jars into classpath. The jars are list in the table in section 2.3.1.

If using Probekit, the following arguments need to add to JVM (in one line):

-XrunpiAgent:server=standalone, extensionLibrary=<rac_install_dir>\plugins\org.eclipse.hyades.probekit\lib\ProbeAgentExtension.dll, ext-pk-BCILibraryName=<rac_install_dir>\plugins\org.eclipse.hyades.probekit\lib\BCIEngProbe.dll, ext-pk-probescript=<btm_probescript_file>, filters=<filters_file>

If using AspectJ, the following argument needs to add to JVM (in one line):

-javaagent:<path_to_aspectjweaver.jar>