Performance

A number of links on this page are dead. Contents
  • Models
  • Eclipse
  • Profiling
  • Remote resources
  • Overview

    When a model is run, some run data is printed to stdout, such as:

          2212 ms. Memory: 31664K Free: 7107K (22%)
        

    This data is printed by ptolemy.actor.Manager, which has methods such as timeAndMemory().

    To measure the time of an execution within a model, you could use the WallClockTime actor.

    The Expression Language also has totalMemory and freeMemory variables that can be accessed, though the values tend to get cached, so they are not always updated during the execution of a system.

    To do performance measurements, run models without a GUI and then do several runs, tossing out the times for the first run. $PTII/ptolemy/actor/lib/test/performance, has some scripts that might be of use.

    Models

    Eclipse

    In Eclipse, use the Test & Performance Tools Platform (TPTP) Project

    See the TPTP Documentation

    1. Use the update manager to install EMF
      Help
    2. Use the update manager to install tptp
      1. From the Help menu in Eclipse, select Software Updates > Find and Install.
      2. Select the Search for new features to install radio button. Click Next.
      3. Add a new update site by clicking on New Remote Site.
      4. Enter the following name and URL and click OK:
        • Name: TPTP Update site
        • URL: http://eclipse.org/tptp/updates/site.xml
      5. Click Finish.
      6. In the "Search Results" dialog box, select the features to install.
        1. Select TPTP 4.2.0
        2. Unselect the BIRT and Web profiling packages
        Then click Next.
      7. In the "Feature License" dialog box, accept the license and click Next.
      8. In the "Installation" dialog box, verify the features to be installed and change install location if necessary. Then click Finish.
      9. After you click Finish, you will be presented a confirmation about a digital signature. Click Install All.
      10. When done, restart your workbench.

    Java 1.5 profiler and Eclipse

    Profiling J2SW 5.0 based applications using Eclipse
    1. Install the New Technology Agent Controller version 4.2+.
      1. See the Agent Controller 4.2 Windows IA32 Getting Started Guide
      2. Download the TPTP New Technology Agent Controller version 4.2+. (Agent Controller 4.2.0.2 Windows-IA32) and unzip in any directory.
      3. Go to the bin/ directory of the Agent Controller and run SetConfig.bat.
      4. While in the Agent Controller bin/ directory, start the Agent Controller with ./ACServer.exe.
    2. Download the JVMTI Client and unzip it in the Eclipse directory
    3. Download the New Java Profiler and unzip it in the same directory as the New Technology Agent Controller.
    4. Restart Eclipse
    5. See 2.4 Configuring The Eclipse Client:
      The New Java Profiler works with the New Technology Agent Controller. The client should be configured to connect to the New Technology Agent Controller port. This is configured in the file "serviceConfig.xml" in the /config directory. The default client connection port number of the New Technology Agent Controller is 10006.

      To configure the hostname, navigate to the Preferences menu ( Window > Preferences ) in the Eclipse Workbench and click on "Profiling and Logging". Change the "Agent Controller local port" to 10006. You will also need to select "Host" under "Profiling and Logging" to add a localhost entry with port 10006. (fig 2.1)

    6. Do Run -> Profiler -> Monitor and select Java Profiling with Instrumentation.
    7. Run the profiler
    8. In the Profile view, you should be able to start and stop the profiler

    Problems

    org.eclipse.core.runtime.CoreException
                  org.eclipse.core.runtime.CoreException
                  The process launcher seems to be inactive.  Restart the Agent Controller and try again.
    
                  org.eclipse.core.runtime.CoreException: The process launcher seems to be inactive.  Restart the Agent Controller and try again.
                  at org.eclipse.tptp.trace.ui.internal.launcher.core.LauncherUtility.createCoreException(LauncherUtility.java:115)
                  at org.eclipse.tptp.trace.ui.internal.launcher.core.LauncherUtility.createCoreException(LauncherUtility.java:123)
                  at org.eclipse.tptp.platform.jvmti.client.internal.launcher.TIDelegateHelper.handleError(TIDelegateHelper.java:278)
                  at org.eclipse.tptp.platform.jvmti.client.internal.launcher.TIDelegateHelper.launchProcess(TIDelegateHelper.java:264)
                  at org.eclipse.tptp.platform.jvmti.client.internal.launcher.TIDelegateHelper.launch(TIDelegateHelper.java:173)
                  at org.eclipse.tptp.platform.jvmti.client.internal.launcher.TIJavaLauncherDelegate.launch(TIJavaLauncherDelegate.java:37)
                  at org.eclipse.tptp.trace.ui.provisional.launcher.PrimaryLaunchDelegate.run(PrimaryLaunchDelegate.java:249)
                  at java.lang.Thread.run(Thread.java:595)
                
    1. In Window -> Preferences -> "Profiling and Logging", make sure that port 10006 is selected and click on the test button.
    2. In Run -> Profile -> Monitor, select "Java Profilin with Instrumentation" and click on the "Test availability" button.
       
                        The JVMTI agent org.eclipse.tptp.jvmti is not available.
                        Make sure that the agent's libraries are available and that
                        it is configured properly
                      

      See Re: jvmti agent

      It looks like the javaprofiler.all_platforms-TPTP-4.2.0.2.zip file should not be extracted in the Agent Controller home directory, it does not put the files in the plugin directory, instead it created a tptp directory that has platform specific files in it. In the Agent Controller directory, either

      • move the tptp/javaprofiler/win_ia32/plugins/org.eclipse.tptp.javaprofiler/ directory to plugins
      • or Download the JVMTI Agent controller extension for Windows-IA32 Runtime and unzip it in the Agent Controller directory.
      • In the Agent Controller bin directory, rerun SetConfig.bat and restart ACServer
      • In Eclipse: run -> Profile -> Monitor, select "Java Profilin with Instrumentation" and click on the "Test availability" button.

    Profiling

    In JDK1.3, try

            java -Xrunhprof:help
          

    Simple timing

    One simple way to time a run is to modify the run() method in ptolemy.actor.Manager so that System.out.println(new Date()).getTime()) is called at the start and the end of the run() method.

    You may also need to include the following at the top with the other import statements.

            import java.util.Date;
          

    Performance

    Memory Leaks

    Under C and C++, one must manage memory by hand.

    Java has a garbage collector, which helps, but memory leaks are still possible. Usually, an object is marked as being eligible for GC when it goes out of scope. Or, if the value of the object is null, then it may be GC'd. However, an object will not be garbage collected if the object has references to it. This is how we get memory leaks.

    We can ask that the garbage collector be run with

            System.gc();
          
    For example, we do this in the code generator after building the large AST that represents the java.lang and ptolemy.kernel classes.

    Finalization is what happens before an object is GC'd. We can force the system to run the finalize method on all objects that are waiting to be finalized with:

            System.runFinalization();
          
    For further information, see IBM page about memory leaks (archive.org).

    Increasing the size of the Heap

    Sometimes, as a workaround, all that is necessary is to increase the size of the Java heap. The java command takes non-standard commands like -Xmxsize to set the maximum stack size. For example, under Cygwin, to run with a 256 megabyte heap size:
            export JAVAFLAGS=-Xmx256m
            $PTII/bin/vergil
          
    To see what other -X commands are available, run
            java -X
          

    Heap Analysis Tool

    jhat - Java Heap Analysis Tool is a tool that can process -Xrunhprof data.

    See the JDC Book that discusses Heap Analysis Tool for downloads and further information.

    Generate a hprof file:

            java -Xrunhprof:file=vergil.hprof,format=b -classpath $PTII/lib/diva.jar\;$PTII/ptolemy/vergil/vergil.jar\;$PTII/ptolemy/ptolemy.jar\;$PTII ptolemy.vergil.VergilApplication
          
    Run HAT:
            java -classpath hat.zip\;$PTII/lib/diva.jar\;$PTII/ptolemy/vergil/vergil.jar\;$PTII/ptolemy/ptolemy.jar\;$PTII -mx100m hat.Main vergil.hprof
          

    Java 1.5 Console

    Java 1.5 includes the Java Console, which can be used to monitor memory usage. http://download.oracle.com/javase/6/docs/technotes/tools/index.html#jconsole
    1. In Cygwin bash, set the JAVAFLAGS property:
                  export JAVAFLAGS=-Dcom.sun.management.jmxremote
                
    2. Start up vergil
                  $PTII/bin/vergil &
                
    3. Start up jconsole
                  jconsole
                

    Remote resources

    Commercial Profilers

    Java and Optimization

    Benchmarks

    Scripting and Java