# Exercise 1.3: Applying your probe

Before you begin, you must complete Exercise 1.2: Creating your first probe.

Now that you have created your RandomNumbersProbe probe and fixed any errors in it, you can execute the RandomNumbers program and apply the probe to it. Note that you don't have to modify the project that contains RandomNumbers program.

First, let's run the RandomNumbers program without the probe.

The program selects a random number from one to ten. If the random number is 10, the simulation ends with a "hit." Otherwise the program selects random numbers until either (A) the new number matches the first number, or (B) the new number is 10. In case (A) the simulation reports a "hit." In case (B) the simulation reports a "miss."

To run the program:

1. From the Software Development Platform menu bar, select Window > Show View > Console. The Console view opens.
2. In the Package Explorer view, expand the RandomNumbers and default package entries.
3. Right-click the RandomNumbers.java file, and select Run > Java Application.

The output in the Console view will look something like this:

    Random number simulation now starting.
    Next selected random value: 7.
    The initial random value is not ten. Looking for a match.
    Target value is 7
    Next selected random value: 5.
    No match, not a ten. Continuing.
    Target value is 7
    Next selected random value: 8.
    No match, not a ten. Continuing.
    Target value is 7
    Next selected random value: 7.
    A match occurred before a ten: hit.

Now, run the program again, but this time apply your probe:

1. In the Package Explorer view, right-click the RandomNumbers.java file, and select Profile > Profile Java Application. The Properties dialog for RandomNumbers opens, allowing you to edit the launch configuration properties.
2. Select the Profiling tab.
3. From the profiling set list, select the Probe Example profiling set, and click Edit. The Edit Profiling Set dialog box opens.
4. Expand the Probes item in the tree, if it is not already expanded, and click Probe Insertion. (It's not enough that there is a check in the Probe Insertion check box; you have to click the Probe Insertion entry to edit the profiling set properties.) Your probe, `RandomNumbersProbe`, appears in the list of selectable probes.
5. Click the check box for `RandomNumbersProbe` to add a check, and make sure that any other probes that might be listed are not checked.
6. Click Next. The filter page of the Profiling set editor opens. We will use this page to make sure that the probe is applied only to the classes and methods that we are targeting.
7. Make sure that the Default filter set is selected.
8. Click Finish.
9. In the Properties dialog box, click OK. The Software Development Platform switches to the Profiling and Logging perspective, and the program runs. The probe you selected will be applied to its classes as they load, and the probe's "entry" fragment will be triggered as the methods execute.
   Note: If you get a Security Message that Agent Controller is not available, read If you were unable to collect data.
10. If the Console view is not already displayed, select Window > Show View > Console to open it.

The Console view displays the regular output for the RandomNumbers program, plus the output generated by the probe logic. It will look something like this:

    [Enter method RandomNumbers.main]
    [Enter method RandomNumbers.<init>]
    [Enter method RandomNumbers.runSimulation]
    Random number simulation now starting.
    [Enter method RandomNumbers.getRandomNumber]
    Next selected random value: 2.
    The initial random value is not ten. Looking for a match.
    Target value is 2
    [Enter method RandomNumbers.getRandomNumber]
    Next selected random value: 2.
    A match occurred before a ten: hit.

As you can see, the output from the probe's "entry" fragment appears along with the program's own output. Note that output from the probe is in brackets because that was how we wrote the `System.out.println` call in the fragment.

### If you were unable to collect data

Before you can collect any kind of profiling data, Agent Controller must be running. If you get a message that Agent Controller is not available, make sure that Agent Controller has been installed, start it manually, and try again. For instructions, refer to the installation guide. You can access the installation guide by using the launchpad, or you can find it on the product CD under `disk1/install.html`.

Now you are ready to begin Exercise 1.4: Creating more advanced probes.

Terms of use | Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.