ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Profiling Your Applications with Eclipse Callisto
Pages: 1, 2, 3, 4

For the purposes of this article, we are going to test the following class, which represents a simple interface to a library catalog.



interface Catalog {
    List<Book> findBooksByAuthor(String name);
    List<Book> findAllBooks();
}

The basic unit tests are as follows:

public class CatalogTest extends TestCase {
    ...
    public Catalog getCatalog() {
        ...
    }

    public void testFindBooksByAuthor() {
        List<Book> books = getCatalog().findBooksByAuthor("Lewis");
    }

    public void testLoadFindBooksByAuthor() {
        for(int i = 0; i < 10; i++) {
            List<Book> books
                = getCatalog().findBooksByAuthor("Lewis");
        }
    }

    public void testFindAll() {
        List<Book> books = getCatalog().findAllBooks();
    }
}

The first thing you need to do is to set up a profile. Select "Run -> Profile" in the main Eclipse menu. This opens a Wizard in which you can configure different sorts of testing profiles, shown in Figure 2.

Creating a TPTP profile
Figure 2. Creating a TPTP profile

In this case, we are interested in the JUnit test profile. Double-click on this entry; the Wizard should create new entries for each of your unit test classes. TPTP is quite flexible, and this screen lets you configure a wide variety of options. For example, in the Test tab, you can either profile unit test classes individually or group them by project or package. The Arguments tab lets you specify runtime arguments, and the Environment tab lets you define environment variables. In the Destination tab, you can specify an external file where profiling data will be saved for future use. But the most useful is the Monitor tab (see Figure 3), where you specify which performance-related data you want to record and study:

  • Basic Memory Analysis: This option records memory usage statistics, including the number of object instances and the overall memory used.
  • Execution Time Analysis: This option records performance data--how long the application spends in each method.
  • Method Code Coverage: This option notes which classes and methods were executed during the tests.

The 'Monitor' tab lets you define the type of data you want to record.
Figure 3: The Monitor tab lets you define the type of data you want to record.

You can either run the profiling tool directly from this window, or using the contextual menu positioned on the test class you want to profile, via the Profile As menu entry (see Figure 4).

You can launch TPTP profiling using the contextual menu.
Figure 4: You can launch TPTP profiling using the contextual menu.

Pages: 1, 2, 3, 4

Next Pagearrow