src/jdk.jfr/share/classes/jdk/jfr/consumer/ChunkParser.java
branchJEP-349-branch
changeset 57380 6a7e7743b82f
parent 57377 528d85d2fce5
child 57385 7d9d4f629f6e
equal deleted inserted replaced
57378:2e35a025ebee 57380:6a7e7743b82f
    60     private LongMap<Type> typeMap;
    60     private LongMap<Type> typeMap;
    61     private LongMap<Parser> parsers;
    61     private LongMap<Parser> parsers;
    62     private boolean chunkFinished;
    62     private boolean chunkFinished;
    63     private InternalEventFilter eventFilter = InternalEventFilter.ACCEPT_ALL;
    63     private InternalEventFilter eventFilter = InternalEventFilter.ACCEPT_ALL;
    64     private boolean reuse;
    64     private boolean reuse;
       
    65     private boolean ordered;
       
    66     private boolean resetEventCache;
    65 
    67 
    66     public ChunkParser(RecordingInput input, boolean reuse) throws IOException {
    68     public ChunkParser(RecordingInput input, boolean reuse) throws IOException {
    67         this(new ChunkHeader(input), null, 500);
    69         this(new ChunkHeader(input), null, 500);
    68        this.reuse = reuse;
    70        this.reuse = reuse;
    69     }
    71     }
    70 
    72 
    71     public void setReuse(boolean resue) {
       
    72         this.reuse = resue;
       
    73         updateParsers();
       
    74     }
       
    75 
    73 
    76     private ChunkParser(ChunkHeader header, ChunkParser previous, long pollInterval) throws IOException {
    74     private ChunkParser(ChunkHeader header, ChunkParser previous, long pollInterval) throws IOException {
    77         this.input = header.getInput();
    75         this.input = header.getInput();
    78         this.chunkHeader = header;
    76         this.chunkHeader = header;
    79         if (previous == null) {
    77         if (previous == null) {
    93             typeMap = factory.getTypeMap();
    91             typeMap = factory.getTypeMap();
    94         } else {
    92         } else {
    95             parsers = previous.parsers;
    93             parsers = previous.parsers;
    96             typeMap = previous.typeMap;
    94             typeMap = previous.typeMap;
    97         }
    95         }
    98         updateParsers();
    96         updateEventParsers();
    99         constantLookups.forEach(c -> c.newPool());
    97         constantLookups.forEach(c -> c.newPool());
   100         fillConstantPools(0);
    98         fillConstantPools(0);
   101         constantLookups.forEach(c -> c.getLatestPool().setResolving());
    99         constantLookups.forEach(c -> c.getLatestPool().setResolving());
   102         constantLookups.forEach(c -> c.getLatestPool().resolve());
   100         constantLookups.forEach(c -> c.getLatestPool().resolve());
   103         constantLookups.forEach(c -> c.getLatestPool().setResolved());
   101         constantLookups.forEach(c -> c.getLatestPool().setResolved());
   114 
   112 
   115     public InternalEventFilter getEventFilter() {
   113     public InternalEventFilter getEventFilter() {
   116         return this.eventFilter;
   114         return this.eventFilter;
   117     }
   115     }
   118 
   116 
   119     private void updateParsers() {
   117 
   120         parsers.forEach(p -> {
       
   121             if (p instanceof EventParser) {
       
   122                 EventParser ep = (EventParser) p;
       
   123                 if (reuse) {
       
   124                     ep.setReuse(true);
       
   125                 }
       
   126                 long threshold = eventFilter.getThreshold(ep.getEventType().getName());
       
   127                 if (threshold >= 0) {
       
   128                     ep.setEnabled(true);
       
   129                     ep.setThreshold(timeConverter.convertDurationNanos(threshold));
       
   130                 } else {
       
   131                     ep.setThreshold(-1L);
       
   132                 }
       
   133             }
       
   134         });
       
   135     }
       
   136 
   118 
   137     /**
   119     /**
   138      * Reads an event and returns null when segment or chunk ends.
   120      * Reads an event and returns null when segment or chunk ends.
   139      */
   121      */
   140     public RecordedEvent readStreamingEvent(boolean awaitNewEvents) throws IOException {
   122     public RecordedEvent readStreamingEvent(boolean awaitNewEvents) throws IOException {
   161                 Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Found new metadata in chunk. Rebuilding types and parsers");
   143                 Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Found new metadata in chunk. Rebuilding types and parsers");
   162                 MetadataDescriptor metadata = chunkHeader.readMetadata(previousMetadata);
   144                 MetadataDescriptor metadata = chunkHeader.readMetadata(previousMetadata);
   163                 ParserFactory factory = new ParserFactory(metadata, constantLookups, timeConverter);
   145                 ParserFactory factory = new ParserFactory(metadata, constantLookups, timeConverter);
   164                 parsers = factory.getParsers();
   146                 parsers = factory.getParsers();
   165                 typeMap = factory.getTypeMap();
   147                 typeMap = factory.getTypeMap();
   166                 updateParsers();
   148                 updateEventParsers();
   167             }
   149             }
   168             if (contantPosition != chunkHeader.getConstantPoolPosition()) {
   150             if (contantPosition != chunkHeader.getConstantPoolPosition()) {
   169                 Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Found new constant pool data. Filling up pools with new values");
   151                 Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Found new constant pool data. Filling up pools with new values");
   170                 constantLookups.forEach(c -> c.getLatestPool().setAllResolved(false));
   152                 constantLookups.forEach(c -> c.getLatestPool().setAllResolved(false));
   171                 fillConstantPools(contantPosition + chunkHeader.getAbsoluteChunkStart());
   153                 fillConstantPools(contantPosition + chunkHeader.getAbsoluteChunkStart());
   354     }
   336     }
   355 
   337 
   356     public boolean isChunkFinished() {
   338     public boolean isChunkFinished() {
   357         return chunkFinished;
   339         return chunkFinished;
   358     }
   340     }
       
   341 
       
   342     // Need to call updateEventParsers() for
       
   343     // change to take effect
       
   344     public void setReuse(boolean resue) {
       
   345         this.reuse = resue;
       
   346     }
       
   347 
       
   348     // Need to call updateEventParsers() for
       
   349     // change to take effect
       
   350     public void setOrdered(boolean ordered) {
       
   351         this.ordered = ordered;
       
   352     }
       
   353 
       
   354     // Need to call updateEventParsers() for
       
   355     // change to take effect
       
   356     public void resetEventCache() {
       
   357         this.resetEventCache = true;
       
   358     }
       
   359 
       
   360     public void updateEventParsers() {
       
   361         parsers.forEach(p -> {
       
   362             if (p instanceof EventParser) {
       
   363                 EventParser ep = (EventParser) p;
       
   364                 ep.setOrdered(ordered);
       
   365                 ep.setReuse(reuse);
       
   366                 if (resetEventCache) {
       
   367                     ep.resetCache();
       
   368                 }
       
   369                 long threshold = eventFilter.getThreshold(ep.getEventType().getName());
       
   370                 if (threshold >= 0) {
       
   371                     ep.setEnabled(true);
       
   372                     ep.setThreshold(timeConverter.convertDurationNanos(threshold));
       
   373                 } else {
       
   374                     ep.setThreshold(-1L);
       
   375                 }
       
   376             }
       
   377         });
       
   378         resetEventCache = false;
       
   379     }
   359 }
   380 }