One of the advertised features of Java Flight Recorder is the ability to report the file created, read or force in the File I/O tab in JMC 8.1
To test this feature, I created a small application that uses Apache commons-io to copy a large file from source to destination.
public static void fileCopy(String srcPath ,String destPath) throws IOException {
File inpFile = new File(srcPath);
if(inpFile.exists() && inpFile.isFile()) {
File destFile = new File(destPath);
FileUtils.copyFile(inpFile, destFile);
}
}
On starting the FlightRecoder with the profile template, and observing the jfr file , I see no events in the File I/O template even though the copy operation took 11 seconds.
JVM used - OpenJDK 11 on Ubuntu.
java -XX:StartFlightRecording=name=benchmark,filename=benchmark.jfr,settings=profile -jar filecopyer-0.0.1-SNAPSHOT.jar
I also retried after changing the File IO threshold to 0 ns in the profile.jfc template, and still no events are recorded.
There are simply 0 events captured for jdk.FileWrite , jdk.FileRead and jdk.FileForce.
I however do see events under jdk.NativeMethodSample , which commons-io ends up calling.
Sample application on github : Profiled application
What am I doing wrong ?
Looks like the implementation of Files.copy, which Apache Commons seems to use, relies on async I/O to do the copying. See sun.nio.fs.UnixCopyFile::copy(...)
JFR doesn't currently instrument async I/O operations.