Complexity Analysis


  The complexity analysis view allows you to investigate the algorithmic complexity of selected methods depending on its method parameters.

If you are unfamiliar with big O notation, see this introduction to algorithmic complexity and this list of complexities for common algorithms.

  Complexity recording is independent of CPU recording. First, you have to select one or more methods that should be monitored. If no methods have been configured, the  configure button is shown directly in the view, and it can always be found in the tool bar or in the View menu.

The following ways for selecting methods are available:

  • Search in configured classpath
    A class chooser will be shown that shows all classes in the classpath configured in the application settings. Finally you have to select a method from the selected class.
  • Search in other JAR or class files
    First, you can select a JAR or class file. If the selection is a JRE file, you then have to select a class in a class chooser. After the selection you will be asked whether to expand the classpath with the current selection. For remote sessions, the classpath is often not configured, so this is a shortcut to make your selection permanent. Finally, you can select a method from the selected class.
  • Search in profiled classes
    If the session is being profiled, a class chooser is displayed that shows all classes in the profiled JVM. There may be classes in the classpath that have not been loaded. Those classes will not be shown in the class chooser. Finally, you can to select a method from the selected class.
  • Enter manually (advanced)
    This option displays a dialog that allows you to enter class name, method name and method signature in JNI format. The JNI format of the method signature is explained in the javadoc of com.jprofiler.api.agent.probe.InterceptionMethod.

    The context menu for the list of methods offers the option to edit existing entries.

In the script editor, you can then enter a script whose return value of type long is used as the complexity for the current method call. For example, if one of the method parameters of type java.util.Collection is named inputs, the script could be inputs.size().

You can temporarily disable a method configuration by deselecting the check box in front of the script configuration. In that case, no complexity recording will be performed for the corresponding method.

  You can start and stop complexity recording directly in the complexity analysis view or by adjusting a recording profile. In addition, you can start or stop recording with the "Start recording" and "Stop recording" trigger actions, the command line controller as well as the profiling API.

After recording has been stopped, a graph with the results is displayed plotting the complexities on the x-axis against the execution times on the y-axis. To reduce memory requirements, JProfiler can combine different complexities and execution times into common buckets. The drop-down at the top allows you to switch between the different configured methods.

The graph is a bubble chart, where the size of each data point is proportional to the amount of measurements in it. If all measurements are distinct, you will see a regular scatter chart. In the other extreme, if all method invocations have the same complexity and execution time, you will see a single large circle.

  If there are at least 3 data points, a curve fit with common complexities is shown. JProfiler tries curve fits from several common complexities and initially shows you the best fit. The drop-down for the curve fits allows you to show other curve fit models as well. The R2 value embedded in the description of the curve fit shows you how good the fit is. The models in the drop-down are sorted in descending order with respect to R2, so the best model is always the first item.

Note that R2 can be negative, because it is just a notation and not really the square of anything. Negative values indicate a fit that is worse than a fit with a constant line. The constant line fit always has an R2 value of 0 and a perfect fit has a value of 1.

You can export the parameters of the currently displayed fit by choosing the "Properties" option in the export dialog. For automated analysis in a quality assurance environment, the command line export supports the properties format as well.