The Cougaar memory profiler is a tool for debugging memory usage and leaks in any Java application. It features a scalable 100% Java design that is lighter weight than existing JVMPI-based profilers (hprof, OptimizeIt(tm), JProbe(tm), etc).

Memory leaks can arise in Java applications due to unintentional object references. For example, an application may fail to remove callback listeners or close streams, preventing these objects from being garbage collected. Even minor leaks can grow to major problems in deployed systems.

The profiler tracks memory usage within the application by using tables of WeakReferences. The developer selects which classes should be tracked and runs an automated classfile editor (using BCEL) to add profiling instructions to the constructors. The profiler maintains pointers to the live instances and can display useful debugging information:

  • Total number of allocations of a profiled class, including the number of live and GC'ed instances
  • Free/used/max VM heap size and force GC
  • Show instances in order of: allocation timestamp, compareTo, hashCode, toString, "size" (e.g. ArrayList.size() & String.length()), "capacity" (e.g. ArrayList.elementData.length). For example, find the largest HashMaps, ten newest "com.Foo", oldest "com.Foo", etc.
  • Count unique occurences of:allocation stacktrace, equals, toString, hashCode, allocation timestamp (& mod second/minute/hour), "size" (& mod 100/1000). For example, what's the most common allocation point for ArrayLists, which are the most common "equals" values (for potential caching), etc.
  • Sample instances for the above order/count views. For example, randomly select 100 of the 1000+ Strings and show the 10 most common "equals" values.
  • The profiler can be configured to randomly sample the allocations to further reduce runtime overhead on a per-class basis. For example, track 5% of allocated Strings. The UI will adjust the displayed data to match the sampling ratio(s).

An interactive servlet-based UI is included that displays all the above profiling data. A servlet-based UI was developed instead of a Swing UI since it matched the Cougaar Agent Architecture's embedded servlet server. It'd be straight-forward to port the servlet to Swing or create a JEditorPane/HTMLEditorKit adaptor. The servlet has minimal Cougaar dependencies and can be modified to run in any servlet server.

Licence: Proprietary