Child pages
  • Tutorial

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

 

No Format
...
java.util.LinkedHashMap$Entry: 18,880 (0%) bytes in 590 (0%) objects (avg size 32 bytes)
    java.util.LinkedHashMap.createEntry: 18,560 (98%) bytes in 580 (98%) objects
        com.devexperts.aprof.AProfAgent.go: 18,432 (99%) bytes in 576 (99%) objects
        java.util.HashMap.put: 128 (0%) bytes in 4 (0%) objects
            java.io.ExpiringCache.put: 128 (100%) bytes in 4 (100%) objects
    java.util.LinkedHashMap.init: 320 (1%) bytes in 10 (1%) objects
        com.devexperts.aprof.AProfAgent.go: 128 (40%) bytes in 4 (40%) objects
        java.util.HashMap.<init>: 128 (40%) bytes in 4 (40%) objects
            java.util.LinkedHashMap.<init>: 128 (100%) bytes in 4 (100%) objects
        java.util.HashSet.<init>: 64 (20%) bytes in 2 (20%) objects
            java.util.LinkedHashSet.<init>: 64 (100%) bytes in 2 (100%) objects
java.lang.Long: 18,336 (0%) bytes in 1,146 (0%) objects (avg size 16 bytes)
    org.objectweb.asm.ClassReader.readConst: 18,304 (99%) bytes in 1,144 (99%) objects
        com.devexperts.aprof.AProfAgent.go: 16,992 (92%) bytes in 1,062 (92%) objects
        com.devexperts.aprof.transformer.AProfTransformer.transform: 1,312 (7%) bytes in 82 (7%) objects
    java.lang.Long.valueOf: 16 (0%) bytes in 1 (0%) objects
        java.lang.Long.valueOf: 16 (100%) bytes in 1 (100%) objects
            com.devexperts.sample.FibonacciNumbers.main: 16 (100%) bytes in 1 (100%) objects
    sun.reflect.UnsafeLongFieldAccessorImpl.get: 16 (0%) bytes in 1 (0%) objects
        com.devexperts.aprof.AProfAgent.go: 16 (100%) bytes in 1 (100%) objects
...

 

Examples

Aforementioned SwingSet2 demo is a complex application, hence its profiling results are not suitable for this tutorial. We will be using a series of specifically designed samples. Some of them make no sense, some are written in non-optimal way, some might even contain bugs. Most likely you will never see them in real applications. However, they help us demonstrate key features of Aprof.

...

Code Block
package com.devexperts.sample;
 
public class FibonacciNumbers {
	private static Integer fib(int n) {
		if (n < 2)
			return 1;
		return fib(n - 1) + fib(n - 2);
	}


	public static void main(String[] args) {
		int n = Integer.parseInt(args[0]);
		System.out.printf("fib(%d)=%d\n", n, fib(n));
	}
}

It calculates nth Fibonacci number and prints it to stdout. However, the method returns Integer instead of int which leads to a lot of garbage generated by the program. In large applications it is usually hard to find all such ineffective pieces of code.

...

There are no suspicious memory allocations here. Note, that for most many programs it is normal to have the most garbage generated for char[] objects.