Find the method that takes the most CPU time
Example 1:
Example 2:
Analyze heap dump
Compare two heap dump files
import java.util.ArrayList;
import java.util.Random;
/**
* -Xms30m -Xmx30m -XX:SurvivorRatio=8 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps
*/
public class OOMTest {
public static void main(String[] args) throws InterruptedException {
ArrayList<Box> list = new ArrayList<>();
while(true){
Thread.sleep(20);
list.add(new Box(new Random().nextInt(1024 * 56)));
}
}
}
class Box{
private byte[] data;
public Box(int length) {
this.data = new byte[length];
}
}