author | egahlin |
Mon, 26 Aug 2019 18:10:34 +0200 | |
branch | JEP-349-branch |
changeset 57883 | 90e867ac8c37 |
parent 57870 | 00860d9caf4d |
child 57985 | be121cbf3284 |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
57360 | 2 |
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
50113 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.jfr.consumer; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
import java.util.Collection; |
|
30 |
import java.util.List; |
|
57360 | 31 |
import java.util.StringJoiner; |
50113 | 32 |
|
33 |
import jdk.jfr.EventType; |
|
34 |
import jdk.jfr.internal.LogLevel; |
|
35 |
import jdk.jfr.internal.LogTag; |
|
36 |
import jdk.jfr.internal.Logger; |
|
57373 | 37 |
import jdk.jfr.internal.LongMap; |
50113 | 38 |
import jdk.jfr.internal.MetadataDescriptor; |
39 |
import jdk.jfr.internal.Type; |
|
57360 | 40 |
import jdk.jfr.internal.Utils; |
50113 | 41 |
import jdk.jfr.internal.consumer.ChunkHeader; |
57372
50ca040843ea
Prepare infrastructure for multiple implementations of EventStream
egahlin
parents:
57360
diff
changeset
|
42 |
import jdk.jfr.internal.consumer.InternalEventFilter; |
57360 | 43 |
import jdk.jfr.internal.consumer.Parser; |
50113 | 44 |
import jdk.jfr.internal.consumer.RecordingInput; |
45 |
||
46 |
/** |
|
47 |
* Parses a chunk. |
|
48 |
* |
|
49 |
*/ |
|
50 |
final class ChunkParser { |
|
57883
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
51 |
// Checkpoint that finishes a flush segment |
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
52 |
static final byte CHECKPOINT_FLUSH_MASK = 1; |
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
53 |
// Checkpoint contains chunk header information in the first pool |
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
54 |
static final byte CHECKPOINT_CHUNK_HEADER_MASK = 2; |
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
55 |
// Checkpoint contains only statics that will not change from chunk to chunk |
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
56 |
static final byte CHECKPOINT_STATICS_MASK = 4; |
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
57 |
// Checkpoint contains thread realted information |
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
58 |
static final byte CHECKPOINT_THREADS_MASK = 8; |
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
59 |
|
50113 | 60 |
private static final long CONSTANT_POOL_TYPE_ID = 1; |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57861
diff
changeset
|
61 |
private static final String CHUNKHEADER = "jdk.types.ChunkHeader"; |
50113 | 62 |
private final RecordingInput input; |
63 |
private final ChunkHeader chunkHeader; |
|
64 |
private final MetadataDescriptor metadata; |
|
65 |
private final TimeConverter timeConverter; |
|
57360 | 66 |
private final MetadataDescriptor previousMetadata; |
67 |
private final long pollInterval; |
|
68 |
private final LongMap<ConstantLookup> constantLookups; |
|
69 |
||
70 |
private LongMap<Type> typeMap; |
|
71 |
private LongMap<Parser> parsers; |
|
72 |
private boolean chunkFinished; |
|
73 |
private InternalEventFilter eventFilter = InternalEventFilter.ACCEPT_ALL; |
|
57376 | 74 |
private boolean reuse; |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
75 |
private boolean ordered; |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
76 |
private boolean resetEventCache; |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
77 |
private long firstNanos = 0; |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
78 |
private long lastNanos = Long.MAX_VALUE; |
57861 | 79 |
private Runnable flushOperation; |
50113 | 80 |
|
57376 | 81 |
public ChunkParser(RecordingInput input, boolean reuse) throws IOException { |
57459 | 82 |
this(new ChunkHeader(input), null, 1000); |
57376 | 83 |
this.reuse = reuse; |
84 |
} |
|
85 |
||
57427 | 86 |
public ChunkParser(ChunkParser previous) throws IOException { |
57459 | 87 |
this(new ChunkHeader(previous.input), previous, 1000); |
57427 | 88 |
} |
50113 | 89 |
|
57360 | 90 |
private ChunkParser(ChunkHeader header, ChunkParser previous, long pollInterval) throws IOException { |
50113 | 91 |
this.input = header.getInput(); |
92 |
this.chunkHeader = header; |
|
57360 | 93 |
if (previous == null) { |
57459 | 94 |
this.pollInterval = 1000; |
57360 | 95 |
this.constantLookups = new LongMap<>(); |
96 |
this.previousMetadata = null; |
|
97 |
} else { |
|
98 |
this.constantLookups = previous.constantLookups; |
|
99 |
this.previousMetadata = previous.metadata; |
|
100 |
this.pollInterval = previous.pollInterval; |
|
57385
7d9d4f629f6e
Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents:
57380
diff
changeset
|
101 |
this.ordered = previous.ordered; |
7d9d4f629f6e
Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents:
57380
diff
changeset
|
102 |
this.reuse = previous.reuse; |
7d9d4f629f6e
Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents:
57380
diff
changeset
|
103 |
this.eventFilter = previous.eventFilter; |
57360 | 104 |
} |
105 |
this.metadata = header.readMetadata(previousMetadata); |
|
52850 | 106 |
this.timeConverter = new TimeConverter(chunkHeader, metadata.getGMTOffset()); |
57360 | 107 |
if (metadata != previousMetadata) { |
108 |
ParserFactory factory = new ParserFactory(metadata, constantLookups, timeConverter); |
|
109 |
parsers = factory.getParsers(); |
|
110 |
typeMap = factory.getTypeMap(); |
|
57385
7d9d4f629f6e
Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents:
57380
diff
changeset
|
111 |
updateEventParsers(); |
57360 | 112 |
} else { |
113 |
parsers = previous.parsers; |
|
114 |
typeMap = previous.typeMap; |
|
115 |
} |
|
116 |
constantLookups.forEach(c -> c.newPool()); |
|
117 |
fillConstantPools(0); |
|
118 |
constantLookups.forEach(c -> c.getLatestPool().setResolving()); |
|
119 |
constantLookups.forEach(c -> c.getLatestPool().resolve()); |
|
120 |
constantLookups.forEach(c -> c.getLatestPool().setResolved()); |
|
50113 | 121 |
|
122 |
input.position(chunkHeader.getEventStart()); |
|
123 |
} |
|
124 |
||
57360 | 125 |
public void setParserFilter(InternalEventFilter filter) { |
57428 | 126 |
this.eventFilter = filter; |
57360 | 127 |
} |
128 |
||
129 |
public InternalEventFilter getEventFilter() { |
|
130 |
return this.eventFilter; |
|
131 |
} |
|
132 |
||
133 |
/** |
|
134 |
* Reads an event and returns null when segment or chunk ends. |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
135 |
* |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
136 |
* @param awaitNewEvents wait for new data. |
57360 | 137 |
*/ |
138 |
public RecordedEvent readStreamingEvent(boolean awaitNewEvents) throws IOException { |
|
139 |
long absoluteChunkEnd = chunkHeader.getEnd(); |
|
140 |
while (true) { |
|
141 |
RecordedEvent event = readEvent(); |
|
142 |
if (event != null) { |
|
143 |
return event; |
|
144 |
} |
|
145 |
if (!awaitNewEvents) { |
|
146 |
return null; |
|
147 |
} |
|
148 |
long lastValid = absoluteChunkEnd; |
|
149 |
long metadataPoistion = chunkHeader.getMetataPosition(); |
|
150 |
long contantPosition = chunkHeader.getConstantPoolPosition(); |
|
151 |
chunkFinished = awaitUpdatedHeader(absoluteChunkEnd); |
|
152 |
if (chunkFinished) { |
|
153 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "At chunk end"); |
|
154 |
return null; |
|
155 |
} |
|
156 |
absoluteChunkEnd = chunkHeader.getEnd(); |
|
157 |
// Read metadata and constant pools for the next segment |
|
158 |
if (chunkHeader.getMetataPosition() != metadataPoistion) { |
|
159 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Found new metadata in chunk. Rebuilding types and parsers"); |
|
160 |
MetadataDescriptor metadata = chunkHeader.readMetadata(previousMetadata); |
|
161 |
ParserFactory factory = new ParserFactory(metadata, constantLookups, timeConverter); |
|
162 |
parsers = factory.getParsers(); |
|
163 |
typeMap = factory.getTypeMap(); |
|
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
164 |
updateEventParsers(); |
57360 | 165 |
} |
166 |
if (contantPosition != chunkHeader.getConstantPoolPosition()) { |
|
167 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Found new constant pool data. Filling up pools with new values"); |
|
168 |
constantLookups.forEach(c -> c.getLatestPool().setAllResolved(false)); |
|
169 |
fillConstantPools(contantPosition + chunkHeader.getAbsoluteChunkStart()); |
|
170 |
constantLookups.forEach(c -> c.getLatestPool().setResolving()); |
|
171 |
constantLookups.forEach(c -> c.getLatestPool().resolve()); |
|
172 |
constantLookups.forEach(c -> c.getLatestPool().setResolved()); |
|
173 |
} |
|
174 |
input.position(lastValid); |
|
175 |
} |
|
176 |
} |
|
177 |
||
178 |
/** |
|
179 |
* Reads an event and returns null when the chunk ends |
|
180 |
*/ |
|
50113 | 181 |
public RecordedEvent readEvent() throws IOException { |
57360 | 182 |
long absoluteChunkEnd = chunkHeader.getEnd(); |
50113 | 183 |
while (input.position() < absoluteChunkEnd) { |
184 |
long pos = input.position(); |
|
185 |
int size = input.readInt(); |
|
186 |
if (size == 0) { |
|
187 |
throw new IOException("Event can't have zero size"); |
|
188 |
} |
|
189 |
long typeId = input.readLong(); |
|
57861 | 190 |
|
191 |
if (typeId != 0) { // Not metadata event |
|
57360 | 192 |
Parser p = parsers.get(typeId); |
193 |
if (p instanceof EventParser) { |
|
194 |
EventParser ep = (EventParser) p; |
|
195 |
RecordedEvent event = ep.parse(input); |
|
196 |
if (event != null) { |
|
197 |
input.position(pos + size); |
|
198 |
return event; |
|
199 |
} |
|
50113 | 200 |
} |
57861 | 201 |
if (typeId == 1 && flushOperation != null) { // checkpoint event |
202 |
parseCheckpoint(); |
|
203 |
} |
|
50113 | 204 |
} |
205 |
input.position(pos + size); |
|
206 |
} |
|
207 |
return null; |
|
208 |
} |
|
209 |
||
57861 | 210 |
private void parseCheckpoint() throws IOException { |
211 |
// Content has been parsed previously. This |
|
212 |
// is for triggering flsuh |
|
213 |
input.readLong(); // timestamp |
|
214 |
input.readLong(); // duration |
|
215 |
input.readLong(); // delta |
|
57883
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
216 |
byte c = input.readByte(); |
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
217 |
if ((c & CHECKPOINT_FLUSH_MASK)== 1) { |
57861 | 218 |
flushOperation.run(); |
219 |
} |
|
220 |
} |
|
221 |
||
57360 | 222 |
private boolean awaitUpdatedHeader(long absoluteChunkEnd) throws IOException { |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
223 |
if (Logger.shouldLog(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO)) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
224 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Waiting for more data (streaming). Read so far: " + chunkHeader.getChunkSize() + " bytes"); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
225 |
} |
57360 | 226 |
while (true) { |
227 |
chunkHeader.refresh(); |
|
228 |
if (absoluteChunkEnd != chunkHeader.getEnd()) { |
|
229 |
return false; |
|
230 |
} |
|
231 |
if (chunkHeader.isFinished()) { |
|
232 |
return true; |
|
233 |
} |
|
57459 | 234 |
Utils.waitFlush(pollInterval); |
57360 | 235 |
} |
236 |
} |
|
237 |
||
238 |
private void fillConstantPools(long abortCP) throws IOException { |
|
239 |
long thisCP = chunkHeader.getConstantPoolPosition() + chunkHeader.getAbsoluteChunkStart(); |
|
240 |
long lastCP = -1; |
|
241 |
long delta = -1; |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
242 |
boolean logTrace = Logger.shouldLog(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE); |
57360 | 243 |
while (thisCP != abortCP && delta != 0) { |
244 |
input.position(thisCP); |
|
245 |
lastCP = thisCP; |
|
50113 | 246 |
int size = input.readInt(); // size |
247 |
long typeId = input.readLong(); |
|
248 |
if (typeId != CONSTANT_POOL_TYPE_ID) { |
|
57360 | 249 |
throw new IOException("Expected check point event (id = 1) at position " + lastCP + ", but found type id = " + typeId); |
50113 | 250 |
} |
251 |
input.readLong(); // timestamp |
|
252 |
input.readLong(); // duration |
|
57360 | 253 |
delta = input.readLong(); |
254 |
thisCP += delta; |
|
50113 | 255 |
boolean flush = input.readBoolean(); |
256 |
int poolCount = input.readInt(); |
|
57360 | 257 |
final long logLastCP = lastCP; |
258 |
final long logDelta = delta; |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
259 |
if (logTrace) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
260 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE, () -> { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
261 |
return "New constant pool: startPosition=" + logLastCP + ", size=" + size + ", deltaToNext=" + logDelta + ", flush=" + flush + ", poolCount=" + poolCount; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
262 |
}); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
263 |
} |
50113 | 264 |
for (int i = 0; i < poolCount; i++) { |
265 |
long id = input.readLong(); // type id |
|
57360 | 266 |
ConstantLookup lookup = constantLookups.get(id); |
50113 | 267 |
Type type = typeMap.get(id); |
57360 | 268 |
if (lookup == null) { |
50113 | 269 |
if (type == null) { |
57360 | 270 |
throw new IOException( |
271 |
"Error parsing constant pool type " + getName(id) + " at position " + input.position() + " at check point between [" + lastCP + ", " + lastCP + size + "]"); |
|
50113 | 272 |
} |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57861
diff
changeset
|
273 |
if (type.getName() != CHUNKHEADER) { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57861
diff
changeset
|
274 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Found constant pool(" + id + ") that is never used"); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57861
diff
changeset
|
275 |
} |
57360 | 276 |
ConstantMap pool = new ConstantMap(ObjectFactory.create(type, timeConverter), type.getName()); |
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57861
diff
changeset
|
277 |
lookup = new ConstantLookup(pool, type); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57861
diff
changeset
|
278 |
constantLookups.put(type.getId(), lookup); |
50113 | 279 |
} |
57360 | 280 |
Parser parser = parsers.get(id); |
50113 | 281 |
if (parser == null) { |
282 |
throw new IOException("Could not find constant pool type with id = " + id); |
|
283 |
} |
|
284 |
try { |
|
285 |
int count = input.readInt(); |
|
57360 | 286 |
if (count == 0) { |
287 |
throw new InternalError("Pool " + type.getName() + " must contain at least one element "); |
|
288 |
} |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
289 |
if (logTrace) { |
57360 | 290 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE, "Constant Pool " + i + ": " + type.getName()); |
291 |
} |
|
50113 | 292 |
for (int j = 0; j < count; j++) { |
293 |
long key = input.readLong(); |
|
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57861
diff
changeset
|
294 |
Object resolved = lookup.getPreviousResolved(key); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57861
diff
changeset
|
295 |
if (resolved == null) { |
57360 | 296 |
Object v = parser.parse(input); |
297 |
logConstant(key, v, false); |
|
298 |
lookup.getLatestPool().put(key, v); |
|
57467 | 299 |
} else { |
300 |
parser.skip(input); |
|
301 |
logConstant(key, resolved, true); |
|
302 |
lookup.getLatestPool().putResolved(key, resolved); |
|
303 |
} |
|
50113 | 304 |
} |
305 |
} catch (Exception e) { |
|
57360 | 306 |
throw new IOException("Error parsing constant pool type " + getName(id) + " at position " + input.position() + " at check point between [" + lastCP + ", " + lastCP + size + "]", |
307 |
e); |
|
50113 | 308 |
} |
309 |
} |
|
57360 | 310 |
if (input.position() != lastCP + size) { |
50113 | 311 |
throw new IOException("Size of check point event doesn't match content"); |
312 |
} |
|
313 |
} |
|
314 |
} |
|
315 |
||
57360 | 316 |
private void logConstant(long key, Object v, boolean preresolved) { |
317 |
if (!Logger.shouldLog(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE)) { |
|
318 |
return; |
|
319 |
} |
|
320 |
String valueText; |
|
321 |
if (v.getClass().isArray()) { |
|
322 |
Object[] array = (Object[]) v; |
|
323 |
StringJoiner sj = new StringJoiner(", ", "{", "}"); |
|
324 |
for (int i = 0; i < array.length; i++) { |
|
325 |
sj.add(textify(array[i])); |
|
326 |
} |
|
327 |
valueText = sj.toString(); |
|
328 |
} else { |
|
329 |
valueText = textify(v); |
|
330 |
} |
|
331 |
String suffix = preresolved ? " (presolved)" :""; |
|
332 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE, "Constant: " + key + " = " + valueText + suffix); |
|
333 |
} |
|
334 |
||
335 |
private String textify(Object o) { |
|
336 |
if (o == null) { // should not happen |
|
337 |
return "null"; |
|
338 |
} |
|
339 |
if (o instanceof String) { |
|
340 |
return "\"" + String.valueOf(o) + "\""; |
|
341 |
} |
|
342 |
if (o instanceof RecordedObject) { |
|
343 |
return o.getClass().getName(); |
|
344 |
} |
|
345 |
if (o.getClass().isArray()) { |
|
346 |
Object[] array = (Object[]) o; |
|
347 |
if (array.length > 0) { |
|
348 |
return textify(array[0]) + "[]"; // can it be recursive? |
|
349 |
} |
|
350 |
} |
|
351 |
return String.valueOf(o); |
|
352 |
} |
|
353 |
||
50113 | 354 |
private String getName(long id) { |
355 |
Type type = typeMap.get(id); |
|
52850 | 356 |
return type == null ? ("unknown(" + id + ")") : type.getName(); |
50113 | 357 |
} |
358 |
||
359 |
public Collection<Type> getTypes() { |
|
360 |
return metadata.getTypes(); |
|
361 |
} |
|
362 |
||
363 |
public List<EventType> getEventTypes() { |
|
364 |
return metadata.getEventTypes(); |
|
365 |
} |
|
366 |
||
57360 | 367 |
public boolean isLastChunk() throws IOException { |
50113 | 368 |
return chunkHeader.isLastChunk(); |
369 |
} |
|
370 |
||
57427 | 371 |
public ChunkParser newChunkParser() throws IOException { |
372 |
return new ChunkParser(this); |
|
373 |
} |
|
374 |
||
50113 | 375 |
public ChunkParser nextChunkParser() throws IOException { |
57360 | 376 |
return new ChunkParser(chunkHeader.nextHeader(), this, pollInterval); |
377 |
} |
|
378 |
||
379 |
public boolean isChunkFinished() { |
|
380 |
return chunkFinished; |
|
50113 | 381 |
} |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
382 |
|
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
383 |
// Need to call updateEventParsers() for |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
384 |
// change to take effect |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
385 |
public void setReuse(boolean resue) { |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
386 |
this.reuse = resue; |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
387 |
} |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
388 |
|
57861 | 389 |
public void setFlushOperation(Runnable flushOperation) { |
390 |
this.flushOperation = flushOperation; |
|
391 |
} |
|
392 |
||
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
393 |
// Need to call updateEventParsers() for |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
394 |
// change to take effect |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
395 |
public void setOrdered(boolean ordered) { |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
396 |
this.ordered = ordered; |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
397 |
} |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
398 |
|
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
399 |
// Need to call updateEventParsers() for |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
400 |
// change to take effect |
57452
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
401 |
public void setFirstNanos(long firstNanos) { |
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
402 |
long chunkStart = chunkHeader.getStartNanos(); |
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
403 |
// Optimization. |
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
404 |
if (firstNanos < chunkStart - 1_000_000_000L) { |
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
405 |
firstNanos = 0; |
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
406 |
} |
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
407 |
this.firstNanos = firstNanos; |
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
408 |
} |
57861 | 409 |
|
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
410 |
public void setLastNanos(long lastNanos) { |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
411 |
this.lastNanos = lastNanos; |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
412 |
} |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
413 |
|
57452
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
414 |
// Need to call updateEventParsers() for |
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
415 |
// change to take effect |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
416 |
public void resetEventCache() { |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
417 |
this.resetEventCache = true; |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
418 |
} |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
419 |
|
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
420 |
public void updateEventParsers() { |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
421 |
parsers.forEach(p -> { |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
422 |
if (p instanceof EventParser) { |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
423 |
EventParser ep = (EventParser) p; |
57433 | 424 |
String name = ep.getEventType().getName(); |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
425 |
ep.setOrdered(ordered); |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
426 |
ep.setReuse(reuse); |
57452
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
427 |
ep.setFirstNanos(firstNanos); |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
428 |
ep.setLastNanos(lastNanos); |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
429 |
if (resetEventCache) { |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
430 |
ep.resetCache(); |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
431 |
} |
57433 | 432 |
long threshold = eventFilter.getThreshold(name); |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
433 |
if (threshold >= 0) { |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
434 |
ep.setEnabled(true); |
57452
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
435 |
ep.setThresholdNanos(threshold); |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
436 |
} else { |
57433 | 437 |
ep.setEnabled(false); |
57452
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
438 |
ep.setThresholdNanos(Long.MAX_VALUE); |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
439 |
} |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
440 |
} |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
441 |
}); |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
442 |
resetEventCache = false; |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
443 |
} |
57640
46a77fccd251
Fix first(...), next(...) and last() path from RepositoryFiles
egahlin
parents:
57604
diff
changeset
|
444 |
|
46a77fccd251
Fix first(...), next(...) and last() path from RepositoryFiles
egahlin
parents:
57604
diff
changeset
|
445 |
public long getChunkDuration() { |
46a77fccd251
Fix first(...), next(...) and last() path from RepositoryFiles
egahlin
parents:
57604
diff
changeset
|
446 |
return chunkHeader.getDurationNanos(); |
46a77fccd251
Fix first(...), next(...) and last() path from RepositoryFiles
egahlin
parents:
57604
diff
changeset
|
447 |
} |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
448 |
|
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
449 |
public long getStartNanos() { |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
450 |
return chunkHeader.getStartNanos(); |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
451 |
} |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
452 |
|
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
453 |
|
50113 | 454 |
} |