JDK-8269127 : JFR: Filename expansion
  • Type: CSR
  • Component: hotspot
  • Sub-Component: jfr
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 18
  • Submitted: 2021-06-22
  • Updated: 2021-07-25
  • Resolved: 2021-07-25
Related Reports
CSR :  
Description
Summary
-------

Extend the filename parameter of -XX:StartFlightRecording and the diagnostic commands JFR.start, JFR.stop and JFR.dump, so PID and timestamp can be included by specifying %p and %t.

Problem
-------

Today, users can create a JFR dump file like this:

    $ java -XX:StartFlightRecording:filename=test.jfr <Main Class>

But there is no way to add the PID to the filename because it is not known until the process is started.

Since the PID can be reused by the OS, It would also be useful to get the timestamp to avoid the same filename being used when starting multiple Java processes with the same command line arguments.


Solution
--------

Unified logging allows users to specify %p and %t when using -Xlog:filename option to get the timestamp and PID.

The same mechanism can be used with JFR, for example:

    $ java -XX:StartFlightRecording:filename=dump-%p.jfr <Main class>

'%p' will be replaced by the PID, i.e. 'dump-12342.jfr'

    $ jcmd <pid> JFR.start filename=dump-%t.jfr

'%t' will be repalced by the current timestamp, i.e. 'dump-2021_07_04_08_32_49.jfr'

'%p' and '%t' can be used together, and '%%' will be replaced by '%'


Specification
-------

### -XX:StartFlightRecording

    -XX:StartFlightRecording=parameter=value
    ...
       filename=path
              Specifies the path and name of the file to which the recording is written when
              the recordingis stopped, for example:
    
               �� recording.jfr
    
               �� /home/user/recordings/recording.jfr
   
               �� c:\recordings\recording.jfr
    
    +         If %p and/or %t is specified in the filename, it expands to the JVM's
    +         PID and the current timestamp, respectively.

### JFR.start

               Syntax : JFR.start [options]

               Options:

                 filename  (Optional) Name of the file to which the flight recording data is
                           written when the recording is stopped. If no filename is given, a
                           filename is generated from the PID and the current date and is
                           placed in the directory where the process was started. The
                           filename may also be a directory in which case, the filename is
                           generated from the PID and the current date in the specified
    -                      specified directory.  (STRING, no default value)
    +                      specified directory. If %p and/or %t is specified in the filename,
    +                      it expands to the JVM's PID and the current timestamp, respectively.
    +                      (STRING, no default value)

### JFR.stop

               Syntax : JFR.stop [options]

               Options:

                 filename  (Optional) Name of the file to which the recording is written when the
    -                      recording is stopped. If no path is provided, the data from the recording
    +                      recording is stopped. If %p and/or %t is specified in the filename, it 
    +                      expands to the JVM's PID and the current timestamp, respectively.
    +                      If no path is provided, the data from the recording is discarded.
    +                      (STRING, no default value)

### JFR.dump

               Syntax : JFR.dump [options]

               Options:

                 filename  (Optional) Name of the file to which the flight recording data is
                            dumped. If no filename is given, a filename is generated from the PID
                            and the current date. The filename may also be a directory in which
                            case, the filename is generated from the PID and the current date in
    -                       the specified directory. (STRING, no default value)
    +                       the specified directory. If %p and/or %t is specified in the filename, it 
    +                       expands to the JVM's PID and the current timestamp, respectively.
    +                       (STRING, no default value)




Comments
Moving to Approved.
25-07-2021

[~egahlin], please add yourself as a reviewer if you approve of the current from of the CSR or suggest additional changes; thanks.
24-07-2021

Re-finalize this CSR. I think Eric has reviewed it, please feel free to let me know if there is any other changes that I should make. Thanks
24-07-2021

As a reminder, for a CSR is pended status, it is the responsibility of the proponents of the CSR to make progress on it. If there is no longer interest in pursuing the CSR, it should be Withdrawn.
23-07-2021

Could you add a couple filename examples to the Solution section and then remove the jcmd examples in the Specification, You can look at the man pages for JFR.start and -XX:StartFlightRecording, located in jdk.jcmd and java.base module, and what text would be suitable to add there to describe the functionality of %t and %p. I think that would be suitable as a specification.
03-07-2021

[~egahlin] please help review this CSR.
02-07-2021

Pending the request. [~ddong], before re-Finalizing or Proposing the request, please set the fixVersion field to specific releases (e.g. 17, 18) or release families (e.g. 11-u) and have one or more other engineers review the request.
25-06-2021