Contents Previous Next Index

Chapter   4

Performance Tuning and Monitoring Applications


You can examine various aspects of the MIDlet applications you created with the J2ME Wireless Toolkit to identify where you can improve the efficiency and speed of your MIDlet. The Wireless Toolkit includes the following features that enable you to optimize the performance of your MIDlet:


Note – Turning on multiple performance features simultaneously can adversely affect the data collected by slowing down application execution. For more accurate results, try enabling one performance feature per data collection.

Profiling Your Application

You can examine the method execution time with the Profiler utility. The Profiler collects data from an emulator during runtime. By seeing how much time a method takes to execute, you can see where potential problems, such as bottlenecks, might exist in the application.

The Profiler window displays two types of method information:

Viewing Profiling Information

To obtain profiling information, follow these steps:

  1. Make sure that Enable Profiling is checked in the Monitor tab of the Preferences dialog box.
  2. (Optional) Check Show System Classes if you want to display the system classes. If unchecked, most system classes are hidden and ignored. Some system classes might be left visible to highlight lengthy execution time. Hiding the system class information helps you to see application class-specific information. You should hide the system classes information while you are developing your application.

  3. Run your application and then quit.
  4. When you quit the application, the Profiler window opens displaying information collected during execution.


Note – The profiling values obtained from an emulation do not reflect actual values on a real device, even though a real device skin might be used.

Profiling Data Display

In the Call Graph tree, you see folders for top-level methods. Opening a method’s folder displays the methods called by it. Selecting a method in the tree shows the profiling information for it and all the methods called by it. Selecting <root> displays profiling information for all methods in the program.

Profiler window.

FIGURE 10  –  Profiler Window

The table displays rows of methods. For each method, you can see its:

Click on the column titles in the table to sort the display. Clicking on Name sorts the methods in alphabetical order. Clicking Count, Cycles, %Cycles, Count with Children, or %Count with Children sorts the information in ascending order. Clicking on the column title again resorts the information in descending order.

Saving and Examining Profiling Information

You can save profiling information in two ways:

To save profiling information so you can it examine later using the Profiler:

To save the data and examine it with an external tool:


Note – You will not be able to load these (.txt) files back into the Profiler.

Examining Memory Usage

Another area to check for optimization is memory usage. The Memory Monitor Extension feature enables you to see how much memory is used by your application during runtime and to see a breakdown of the amount of memory usage per object.

Memory Monitor window, Objects view.

FIGURE 11  –  Memory Monitor Window

Viewing Memory Usage

To obtain memory usage information, follow these steps:

  1. Make sure that you have enabled the Memory Monitor in the Monitor tab of the Preferences dialog box.
  2. (Optional) If you want to set the heap size, click the Storage tab in the Preferences dialog box and enter a value. Setting the heap size is not required to use memory monitoring.

    (Optional) If you want to determine the required amount of memory during runtime, turn on Excessive GC mode. When turned on, garbage collection is run every time an object is about to be allocated.

  3. Run your application.
  4. (Optional) Click Run GC in the Memory Monitor Extension window to have garbage collection performed at anytime while the application is running.


Note – The memory usage values obtained from an emulation do not reflect actual memory usage on a real device, even though a real device skin might be used. The Memory Monitor merely provides you with possible indicators of excessive memory use for the emulation.

Memory Monitor Data Display

The Memory Monitor displays usage information in two tabbed panes:

Memory Monitor window, Graph view.

FIGURE 12  –  Memory Monitor Graph

Memory Monitor window, Objects view, close-up of Objects table.

FIGURE 13  –  Memory Monitor Objects Table

Click on the column titles in the table to sort the display. Clicking on Name sorts the classes in alphabetical order. Clicking Live, Total, Total Size, or Average Size sorts the information in that column from ascending to descending value.

Selecting a class in the Name column displays a hierarchical list of that class’ methods and the percentage of memory used by the objects allocated by that method and the methods called by it in the pane to the right of the table. Click Find to locate a specific method. The Objects table is dynamically updated during program execution; however, the method list is not. Click Refresh to update the display of percentage of usage information.

Saving and Examining Memory Usage Information

You can save memory usage information and examine it later by:

  1. Choosing File -> Save in the Memory Monitor and providing a filename.
  2. Click Open Session in the Memory Monitor’s toolbar and select the file you want.

To examine previously saved information from the KToolbar:

Monitoring Network Traffic

One of the many uses of a MIDP application is to get or send information. By monitoring the network traffic generated by your application, you can obtain information you might need to improve or fix communication with a server and optimize network usage. The Network Monitor enables you to monitor the following network protocols:

Demonstration applications for the following network protocols are available from the Open Project dialog box:

Viewing Network Traffic

To turn on network monitoring automatically when your application runs or to choose a specific proxy type, follow these steps:

  1. Make sure that you have enabled the Network Monitor in the Monitor tab of the Preferences dialog box.
  2. Run your application.
  3. The Network Monitor window opens when you start your application.

Network Monitor Data Displays

The Network Monitor displays a list of messages that were sent or received by the application. Messages are broken down into their header and body, if any.

To see information for a specific message:

Network Monitor window showing close up of key and value pairs.

FIGURE 14  –  Message Key and Value Pair

An asterisk (*) in the protocol tab indicates which network protocol has information to display if it is not the selected tab.

The field summary, shown in the right panel of the monitor. All protocols have a URL field. Depending on the protocol, the URL field can contain, for example, URL address, protocol, baud rate, hostname, phone number, and port number.

The properties of a message are displayed in key and value pairs in a table format. You can view the entire contents of a value by choosing that value and viewing it in the scrollable text field at the bottom of the pane.

To see the message body:

HTTP message body.

FIGURE 15  –  Message Body


Note – You can examine messages that are still in the process of being sent. Incomplete messages are indicated by bold highlighting in the message tree.

You can reorganize or narrow the messages displayed by setting filters or by sorting message by type. See the sections, "Filtering Messages" ” and "Sorting Messages" .

Filtering Messages

To examine a specific set of messages, you can set filters in the Network Monitor. Only those messages that fall within the filter settings are displayed in the message tree. Filter Settings are specific to the network protocol used.

  1. Choose Edit -> Filter Settings or click the Filter Settings button in the toolbar.
  2. Change one or all of the filter settings in the Message Filter dialog box:

TABLE 2  –  Filter Settings for Network Protocols
Network Protocol
Filter Settings
HTTP/HTTPS
  • URL--The URL for the messages you want to see in the URL text field.
  • Status Line--The status type of message you want to examine, in the Network Monitor Status Line text field.
  • Header Text--A specific header in the Header Text text field.
  • Body Text--A character string for the specific text in the body of the messages you want to examine in the Body Text text field.
SMS/CBS
  • Protocol--Either an SMS or CBS transmissions or both.
  • Type--Text or binary message.
  • Direction--Input and output indicators with chronological designations.
  • From--Phone and port number of origin.
  • To--Phone and port number of destination.
  • Content--A character string for the specific text in the body of the messages you want to examine in the Body Text text field.
Socket/SSL/Datagram/Comm
  • URL--The URL for the messages you want to see in the URL text field.
  • Content--A character string for the specific text in the body of the messages you want to examine in the Body Text text field.

Disabling Filtering

To disable message filtering so that all messages are displayed:

Sorting Messages

To arrange the messages in the message tree in a particular order:

Sorting parameters are dependent on the message protocol you choose. For instance, sorting by time is not relevant for message using the Socket protocol.

Saving and Examining a Networking Session

You can save information about a networking session and examine it later by:

  1. Choosing File -> Save in the Network Monitor and providing a filename. Examining Saved Messages
  2. Choose File -> Open in the Network Monitor and select the file you want from the file chooser.

To examine previously saved message information from the KToolbar:

Clearing the Message Tree

To remove the list of message in the message tree:

Managing Device Speed

If the application you develop has a graphical user interface (GUI), the time required to draw the GUI on the screen is critical to the overall usability of the application. Another critical time factor is knowing the speed at which your application runs on a device. The VM emulation speed approximates the slower running speed of an application on a device. How quickly an application is able to transmit information to the network is another performance factor The Wireless Toolkit lets you modify both graphic speed emulation, VM speed emulation, and the speed of the network throughput.

The intent of the speed emulation features is to enable you to scale down the performance of some of the emulator subsystems to better reflect performance on a real device. Developing the application in a slower performance environment enables you to monitor and optimize the code of low-end devices. It is not the purpose of the speed emulation features to accurately emulate a specific device.

Preferences dialog box for Default Emulator showing Performances tab.

FIGURE 16  –  Performance Settings

Setting Graphics Performance

To optimize GUI display capabilities, you should adjust both the Graphics primitive latency speed and the Refresh mode:

Vary the settings to find the ones that produce the fastest rendering with the least amount of flickering in your application.

Setting VM Speed Parameters

When running an emulation of a MIDlet, you cannot get an accurate demonstration of real time application execution speed. The emulation runs much faster than an application on an actual device. You can, however, adjust the VM speed emulation in the Wireless Toolkit to approximate the slower speed of a device on which the application might run.


Note – Setting the VM speed parameters does not emulate real device speed, even though a real device skin might be used.

To set the VM speed emulation, which is the amount of Java byte code that is executed per second:

Setting Network Speed Parameters

Sometimes an application’s performance is hindered by the speed of the network. To see how your application performs on a slow network, you can vary the network speed parameter. To set the rate at which the application transmits information to the network:


Note – Setting the network throughput speed does not emulate actual network transmission speed.

 


Contents Previous Next Index User's Guide
Java™ 2 Platform, Micro Edition, Wireless Toolkit, Version 2.1