profile application

Instruments a program to keep track of how much elapsed time is spent in methods of the program. You control which methods are instrumented by the arguments you specify. For example, java yourpkg.mainclass -sc pkg -op tempdir instruments each method of each used class in yourpkg, and outputs the instrumented classfiles to tempdir.

After the program has been instrumented, you can now do profiling runs:

  1. Whenever you run the instrumented program, specify a classpath that includes the directory used in the -op switch (if any) and the JTrek kit directory.
  2. After the program is run, the gathered profiling data will be in the current directory, in the text file profile.log.

The following data is output for each instrumented  method that consumes at least 1% of the application's run time, and either invokes another method or contains a loop:

  • The number of times the method was called
  • The average number of MS spent in the method, per call. Note that this includes the time spent in methods that this method calls. Thus the number shown for the program's main method approximates the entire run time of the program.
  • The classname.name of the method.

Restrictions

profile can be used on a GUI program only if the program terminates in either of the following ways:

  • The program's main thread is the last thread to end
  • The program ends by calling System.exit.

profile does not work on applets and servlets. (However it is possible to manually insert the desired start point and end point code in a program. See atEndOf() of profile.java in the JTrek kit's src directory).

profile will not instrument contructors in the java. and sun. classes.