RFR: 8256156: JFR: Allow 'jfr' tool to show metadata without a recording

Yang Yi github.com+5010047+kelthuzadx at openjdk.java.net
Thu Feb 18 02:27:41 UTC 2021


On Tue, 16 Feb 2021 19:17:49 GMT, Erik Gahlin <egahlin at openjdk.org> wrote:

>> I've updated my patch. Only when meeting an event type, a filter applied, otherwise it operates on types
>
> It still doesn't work the same way as when you specify a file.
> 
> Here is a patch I think it will fix the functionality. Not tested or formatted.
> 
>     diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Metadata.java    
>     b/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Metadata.java
>     index 7a4b49703cf..1b6c50df441 100644
>     --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Metadata.java
>     +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Metadata.java
>     @@ -39,6 +39,7 @@ import java.util.List;
>     import java.util.function.Predicate;
>  
>     import jdk.jfr.EventType;
>     +import jdk.jfr.FlightRecorder;
>     import jdk.jfr.consumer.RecordingFile;
>     import jdk.jfr.internal.PlatformEventType;
>     import jdk.jfr.internal.PrivateAccess;
>     @@ -202,38 +203,40 @@ final class Metadata extends Command {
>              if (filter != null) {
>                  filter = addCache(filter, type -> type.getId());
>              }
>     -
>     -            List<Type> types = getAllTypes(file);
>     +           List<Type> types = findTypes(file);
>                  Collections.sort(types, new TypeComparator());
>                  for (Type type : types) {
>     -                // if it's an event type, apply filter on it
>     -                if (Type.SUPER_TYPE_EVENT.equals(type.getSuperType())) {
>     -                    EventType et = PrivateAccess.getInstance().newEventType((PlatformEventType) type);
>     -                    if (filter != null && !filter.test(et)) {
>     -                        continue;
>     +                if (filter != null) { 
>     +                    // If --events or --categories, only operate on events
>     +                    if (Type.SUPER_TYPE_EVENT.equals(type.getSuperType())) {
>     +                        EventType et = PrivateAccess.getInstance().newEventType((PlatformEventType) type);
>     +                        if (filter.test(et)) {
>     +                            prettyWriter.printType(type);
>     +                        }
>                      }
>     +                } else {
>     +                    prettyWriter.printType(type);
>                  }
>     -
>     -                prettyWriter.printType(type);
>              }
>              prettyWriter.flush(true);
>              pw.flush();
>          }
>      }
>  
>     -    private List<Type> getAllTypes(Path file) throws UserDataException {
>     +    private List<Type> findTypes(Path file) throws UserDataException {
>               // Determine whether reading from recording file or reading from the JDK where
>               // the jfr tool is located will be used
>               if (file == null) {
>     +            // Force initialization
>     +            FlightRecorder.getFlightRecorder().getEventTypes();
>                  return TypeLibrary.getInstance().getTypes();
>               }
>     -        List<Type> types = null;
>              try (RecordingFile rf = new RecordingFile(file)) {
>     -            types = PRIVATE_ACCESS.readTypes(rf);
>     +            return PRIVATE_ACCESS.readTypes(rf);
>              } catch (IOException ioe) {
>                  couldNotReadError(file, ioe);
>              }
>     -        return types;
>     +        return null; // Can't reach
>          }
>  
>      private Path getOptionalJFRInputFile(Deque<String> options) throws UserDataException {

Hi Erik, I have updated this patch according to your diff content.

I'm fine with changes about force initialization. But it looks like the changes in `execute()` method does the same thing? If no filter is given, they both print all types. If filter applied, they print only event type.

-------------

PR: https://git.openjdk.java.net/jdk/pull/1904


More information about the hotspot-jfr-dev mailing list