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:
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:
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 you wrote the System.out.println call in the fragment.
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.
You have now created and used a simple probe that reports whenever a method in your program was entered. You are now ready to begin Exercise 1.4: Creating more advanced probes.