I have a spring-boot web application which uses spring native /graalvm. Is it possible to get a heap dump of such kind of application? I tried to use: visual vm, jconsole, spring-actuator but did not succeed. These 3 options work fine for a non spring native applications. I just want to compare heap utilization of graalvm application and vanilla one.
Asked
Active
Viewed 398 times
1 Answers
1
You can not generate heap dump with jmap or visualVM but you can implement a code block to generate heap dump. here is example code
import java.text.DateFormat;
import java.util.Date;
public class SVMHeapDump extends Thread {
static int i = 0;
static int runs = 60;
static int sleepTime = 1000;
@Override
public void run() {
System.out.println(DateFormat.getDateTimeInstance().format(new Date()) + ": Thread started, it will run for " + runs + " seconds");
while (i < runs){
System.out.println("Sleeping for " + (runs-i) + " seconds." );
try {
Thread.sleep(sleepTime);
} catch (InterruptedException ie){
System.out.println("Sleep interrupted.");
}
i++;
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws InterruptedException {
StringBuffer sb1 = new StringBuffer(100);
sb1.append(DateFormat.getDateTimeInstance().format(new Date()));
sb1.append(": Hello GraalVM native image developer! \nGet PID of this process: ");
sb1.append("'ps -C svmheapdump -o pid= '\n");
sb1.append("then send it signal: ");
sb1.append("'kill -SIGUSR1 <pid_printed_above>' \n");
sb1.append("to get heap dump generated into working directory.\n");
sb1.append("Starting thread!");
System.out.println(sb1);
SVMHeapDump t = new SVMHeapDump();
t.start();
while (t.isAlive()) {
t.join(0);
}
sb1 = new StringBuffer(100);
sb1.append(DateFormat.getDateTimeInstance().format(new Date()));
sb1.append(": Thread finished after: ");
sb1.append(i);
sb1.append(" iterations.");
System.out.println(sb1);
}
}
after you build and run that code you can send the signal with kill -SIGUSR1 100
command.
for further details please check https://www.graalvm.org/reference-manual/native-image/NativeImageHeapdump/

ozkanpakdil
- 3,199
- 31
- 48