3

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.

Flight Recorder Screenshot

 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 ?

Samrat
  • 1,329
  • 12
  • 15

1 Answers1

2

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.

Kire Haglin
  • 6,569
  • 22
  • 27
  • Thanks for this information. I was searching for good documentation on what various events are meant to represent. I didn't find any. Is there documentation where it is mentioned that JFR doesn't currently instrument async I/O operations , that I can refer. – Samrat Aug 24 '21 at 05:29
  • "Events for async I/O is an outage in JFR, because we haven't figured out how to model and implement them. " https://bugs.openjdk.java.net/browse/JDK-8075813 – Kire Haglin Aug 24 '21 at 11:30
  • I changed my code to use BufferedInputStream and FileInputStream instead of commons-io and used that to copy a large file with readNBytes(b[],off,len) and writeNBytes . Yet no events were recorded. Can you point me to the api which I can use that will cause jdk.FileRead and Write events to fire ? Also the openjdk bugs link is behind a password wall. – Samrat Aug 25 '21 at 06:13
  • FileInputStream should work. You can see an example here: https://github.com/openjdk/jdk/blob/master/test/jdk/jdk/jfr/event/io/TestFileStreamEvents.java The threshold probably needs to be set to 0 ns. Sorry about the password, but I can't find anywhere it is public stated, so you have to take my word for it. I have worked on JFR for ten years in OpenJDK. – Kire Haglin Aug 25 '21 at 11:15