Diagnostic Tools in the J2ME Wireless Toolkit
Starting with version 1.0.4, the J2ME Wireless Toolkit contains three tools you can use to understand your application's performance.
The first tool is a memory monitor. You can see a graph of memory usage in your application over time or a detailed breakdown of every object in your application. Turn on the memory monitor by choosing Edit Ø Preferences from the KToolbar menu. Click the Monitoring tab and check off Enable Memory Monitor. Next time you run the emulator, an additional window will pop up. You can examine the total memory used, which is useful when you're trying to make an application fit on a device with a limited heap size. (You can even set the heap size of the emulator in the Storage tab of the preferences window.) Figure 13-1 shows the memory monitor graph.
If you click the Objects tab in the memory monitor window, you'll see a detailed listing of the objects in your application. Figure 13-2 shows this view.
You can click on any column in the table to sort by that column. You can even search for specific items using View Ø Find. Examining the memory monitor window will help you identify the places where memory is consumed most in your application.
Aside from the memory monitor, the toolkit also includes a code profiler—a tool that shows how much time is spent in every method in your application. To turn on the profiler, choose Edit Ø Preferences from the KToolbar menu. Choose the Monitoring tab and check off Enable Profiling.
You won't see the profiler until you exit the emulator. When you do, the profiler window pops up, summarizing time spent in every method in your application during the last emulator run. Note that what you do in the emulator will affect the output in the profiler; if you want to test the performance of your application as a whole, you'll have to exercise all of its options. Figure 13-3 shows the emulator after running the QuatschMIDlet example from Chapter 11.
Finally, the J2ME Wireless Toolkit also includes a network monitor. Although it's probably more useful for debugging network protocols than for optimization, it deserves mention here. To turn on the network monitor, choose Edit Ø Preferences from the KToolbar menu. Choose the Monitoring tab and check off Enable Network Monitoring. Next time you run the emulator, a new window will pop up that tracks network usage. Figure 13-4 shows a few network interactions from the PeekAndPick application (http://wireless.java.sun.com/applications/peekandpick/2.0/).