author | egahlin |
Fri, 09 Aug 2019 01:18:18 +0200 | |
branch | JEP-349-branch |
changeset 57690 | 9316d02dd4a5 |
parent 57640 | 46a77fccd251 |
child 57861 | 86022e34ba63 |
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 { |
|
51 |
private static final long CONSTANT_POOL_TYPE_ID = 1; |
|
52 |
private final RecordingInput input; |
|
53 |
private final ChunkHeader chunkHeader; |
|
54 |
private final MetadataDescriptor metadata; |
|
55 |
private final TimeConverter timeConverter; |
|
57360 | 56 |
private final MetadataDescriptor previousMetadata; |
57 |
private final long pollInterval; |
|
58 |
private final LongMap<ConstantLookup> constantLookups; |
|
59 |
||
60 |
private LongMap<Type> typeMap; |
|
61 |
private LongMap<Parser> parsers; |
|
62 |
private boolean chunkFinished; |
|
63 |
private InternalEventFilter eventFilter = InternalEventFilter.ACCEPT_ALL; |
|
57376 | 64 |
private boolean reuse; |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
65 |
private boolean ordered; |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
66 |
private boolean resetEventCache; |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
67 |
private long firstNanos = 0; |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
68 |
private long lastNanos = Long.MAX_VALUE; |
50113 | 69 |
|
57376 | 70 |
public ChunkParser(RecordingInput input, boolean reuse) throws IOException { |
57459 | 71 |
this(new ChunkHeader(input), null, 1000); |
57376 | 72 |
this.reuse = reuse; |
73 |
} |
|
74 |
||
57427 | 75 |
public ChunkParser(ChunkParser previous) throws IOException { |
57459 | 76 |
this(new ChunkHeader(previous.input), previous, 1000); |
57427 | 77 |
} |
50113 | 78 |
|
57360 | 79 |
private ChunkParser(ChunkHeader header, ChunkParser previous, long pollInterval) throws IOException { |
50113 | 80 |
this.input = header.getInput(); |
81 |
this.chunkHeader = header; |
|
57360 | 82 |
if (previous == null) { |
57459 | 83 |
this.pollInterval = 1000; |
57360 | 84 |
this.constantLookups = new LongMap<>(); |
85 |
this.previousMetadata = null; |
|
86 |
} else { |
|
87 |
this.constantLookups = previous.constantLookups; |
|
88 |
this.previousMetadata = previous.metadata; |
|
89 |
this.pollInterval = previous.pollInterval; |
|
57385
7d9d4f629f6e
Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents:
57380
diff
changeset
|
90 |
this.ordered = previous.ordered; |
7d9d4f629f6e
Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents:
57380
diff
changeset
|
91 |
this.reuse = previous.reuse; |
7d9d4f629f6e
Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents:
57380
diff
changeset
|
92 |
this.eventFilter = previous.eventFilter; |
57360 | 93 |
} |
94 |
this.metadata = header.readMetadata(previousMetadata); |
|
52850 | 95 |
this.timeConverter = new TimeConverter(chunkHeader, metadata.getGMTOffset()); |
57360 | 96 |
if (metadata != previousMetadata) { |
97 |
ParserFactory factory = new ParserFactory(metadata, constantLookups, timeConverter); |
|
98 |
parsers = factory.getParsers(); |
|
99 |
typeMap = factory.getTypeMap(); |
|
57385
7d9d4f629f6e
Make setReuse and setOrdered work across chunk boundaries. Improved unit tests
egahlin
parents:
57380
diff
changeset
|
100 |
updateEventParsers(); |
57360 | 101 |
} else { |
102 |
parsers = previous.parsers; |
|
103 |
typeMap = previous.typeMap; |
|
104 |
} |
|
105 |
constantLookups.forEach(c -> c.newPool()); |
|
106 |
fillConstantPools(0); |
|
107 |
constantLookups.forEach(c -> c.getLatestPool().setResolving()); |
|
108 |
constantLookups.forEach(c -> c.getLatestPool().resolve()); |
|
109 |
constantLookups.forEach(c -> c.getLatestPool().setResolved()); |
|
50113 | 110 |
|
111 |
input.position(chunkHeader.getEventStart()); |
|
112 |
} |
|
113 |
||
57360 | 114 |
public void setParserFilter(InternalEventFilter filter) { |
57428 | 115 |
this.eventFilter = filter; |
57360 | 116 |
} |
117 |
||
118 |
public InternalEventFilter getEventFilter() { |
|
119 |
return this.eventFilter; |
|
120 |
} |
|
121 |
||
122 |
/** |
|
123 |
* 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
|
124 |
* |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
125 |
* @param awaitNewEvents wait for new data. |
57360 | 126 |
*/ |
127 |
public RecordedEvent readStreamingEvent(boolean awaitNewEvents) throws IOException { |
|
128 |
long absoluteChunkEnd = chunkHeader.getEnd(); |
|
129 |
while (true) { |
|
130 |
RecordedEvent event = readEvent(); |
|
131 |
if (event != null) { |
|
132 |
return event; |
|
133 |
} |
|
134 |
if (!awaitNewEvents) { |
|
135 |
return null; |
|
136 |
} |
|
137 |
long lastValid = absoluteChunkEnd; |
|
138 |
long metadataPoistion = chunkHeader.getMetataPosition(); |
|
139 |
long contantPosition = chunkHeader.getConstantPoolPosition(); |
|
140 |
chunkFinished = awaitUpdatedHeader(absoluteChunkEnd); |
|
141 |
if (chunkFinished) { |
|
142 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "At chunk end"); |
|
143 |
return null; |
|
144 |
} |
|
145 |
absoluteChunkEnd = chunkHeader.getEnd(); |
|
146 |
// Read metadata and constant pools for the next segment |
|
147 |
if (chunkHeader.getMetataPosition() != metadataPoistion) { |
|
148 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Found new metadata in chunk. Rebuilding types and parsers"); |
|
149 |
MetadataDescriptor metadata = chunkHeader.readMetadata(previousMetadata); |
|
150 |
ParserFactory factory = new ParserFactory(metadata, constantLookups, timeConverter); |
|
151 |
parsers = factory.getParsers(); |
|
152 |
typeMap = factory.getTypeMap(); |
|
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
153 |
updateEventParsers(); |
57360 | 154 |
} |
155 |
if (contantPosition != chunkHeader.getConstantPoolPosition()) { |
|
156 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Found new constant pool data. Filling up pools with new values"); |
|
157 |
constantLookups.forEach(c -> c.getLatestPool().setAllResolved(false)); |
|
158 |
fillConstantPools(contantPosition + chunkHeader.getAbsoluteChunkStart()); |
|
159 |
constantLookups.forEach(c -> c.getLatestPool().setResolving()); |
|
160 |
constantLookups.forEach(c -> c.getLatestPool().resolve()); |
|
161 |
constantLookups.forEach(c -> c.getLatestPool().setResolved()); |
|
162 |
} |
|
163 |
input.position(lastValid); |
|
164 |
} |
|
165 |
} |
|
166 |
||
167 |
/** |
|
168 |
* Reads an event and returns null when the chunk ends |
|
169 |
*/ |
|
50113 | 170 |
public RecordedEvent readEvent() throws IOException { |
57360 | 171 |
long absoluteChunkEnd = chunkHeader.getEnd(); |
50113 | 172 |
while (input.position() < absoluteChunkEnd) { |
173 |
long pos = input.position(); |
|
174 |
int size = input.readInt(); |
|
175 |
if (size == 0) { |
|
176 |
throw new IOException("Event can't have zero size"); |
|
177 |
} |
|
178 |
long typeId = input.readLong(); |
|
57360 | 179 |
// Skip metadata and constant pool events (id = 0, id = 1) |
180 |
if (typeId > CONSTANT_POOL_TYPE_ID) { |
|
181 |
Parser p = parsers.get(typeId); |
|
182 |
if (p instanceof EventParser) { |
|
183 |
EventParser ep = (EventParser) p; |
|
184 |
RecordedEvent event = ep.parse(input); |
|
185 |
if (event != null) { |
|
186 |
input.position(pos + size); |
|
187 |
return event; |
|
188 |
} |
|
50113 | 189 |
} |
190 |
} |
|
191 |
input.position(pos + size); |
|
192 |
} |
|
193 |
return null; |
|
194 |
} |
|
195 |
||
57360 | 196 |
private boolean awaitUpdatedHeader(long absoluteChunkEnd) throws IOException { |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
197 |
if (Logger.shouldLog(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO)) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
198 |
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
|
199 |
} |
57360 | 200 |
while (true) { |
201 |
chunkHeader.refresh(); |
|
202 |
if (absoluteChunkEnd != chunkHeader.getEnd()) { |
|
203 |
return false; |
|
204 |
} |
|
205 |
if (chunkHeader.isFinished()) { |
|
206 |
return true; |
|
207 |
} |
|
57459 | 208 |
Utils.waitFlush(pollInterval); |
57360 | 209 |
} |
210 |
} |
|
211 |
||
212 |
private void fillConstantPools(long abortCP) throws IOException { |
|
213 |
long thisCP = chunkHeader.getConstantPoolPosition() + chunkHeader.getAbsoluteChunkStart(); |
|
214 |
long lastCP = -1; |
|
215 |
long delta = -1; |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
216 |
boolean logTrace = Logger.shouldLog(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE); |
57360 | 217 |
while (thisCP != abortCP && delta != 0) { |
218 |
input.position(thisCP); |
|
219 |
lastCP = thisCP; |
|
50113 | 220 |
int size = input.readInt(); // size |
221 |
long typeId = input.readLong(); |
|
222 |
if (typeId != CONSTANT_POOL_TYPE_ID) { |
|
57360 | 223 |
throw new IOException("Expected check point event (id = 1) at position " + lastCP + ", but found type id = " + typeId); |
50113 | 224 |
} |
225 |
input.readLong(); // timestamp |
|
226 |
input.readLong(); // duration |
|
57360 | 227 |
delta = input.readLong(); |
228 |
thisCP += delta; |
|
50113 | 229 |
boolean flush = input.readBoolean(); |
230 |
int poolCount = input.readInt(); |
|
57360 | 231 |
final long logLastCP = lastCP; |
232 |
final long logDelta = delta; |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
233 |
if (logTrace) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
234 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE, () -> { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
235 |
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
|
236 |
}); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
237 |
} |
50113 | 238 |
for (int i = 0; i < poolCount; i++) { |
239 |
long id = input.readLong(); // type id |
|
57360 | 240 |
ConstantLookup lookup = constantLookups.get(id); |
50113 | 241 |
Type type = typeMap.get(id); |
57360 | 242 |
if (lookup == null) { |
50113 | 243 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Found constant pool(" + id + ") that is never used"); |
244 |
if (type == null) { |
|
57360 | 245 |
throw new IOException( |
246 |
"Error parsing constant pool type " + getName(id) + " at position " + input.position() + " at check point between [" + lastCP + ", " + lastCP + size + "]"); |
|
50113 | 247 |
} |
57360 | 248 |
ConstantMap pool = new ConstantMap(ObjectFactory.create(type, timeConverter), type.getName()); |
249 |
constantLookups.put(type.getId(), new ConstantLookup(pool, type)); |
|
50113 | 250 |
} |
57360 | 251 |
Parser parser = parsers.get(id); |
50113 | 252 |
if (parser == null) { |
253 |
throw new IOException("Could not find constant pool type with id = " + id); |
|
254 |
} |
|
255 |
try { |
|
256 |
int count = input.readInt(); |
|
57360 | 257 |
if (count == 0) { |
258 |
throw new InternalError("Pool " + type.getName() + " must contain at least one element "); |
|
259 |
} |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
260 |
if (logTrace) { |
57360 | 261 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE, "Constant Pool " + i + ": " + type.getName()); |
262 |
} |
|
50113 | 263 |
for (int j = 0; j < count; j++) { |
264 |
long key = input.readLong(); |
|
57467 | 265 |
Object resolved = lookup.getPreviousResolved(key); |
266 |
if (resolved == null) { |
|
57360 | 267 |
Object v = parser.parse(input); |
268 |
logConstant(key, v, false); |
|
269 |
lookup.getLatestPool().put(key, v); |
|
57467 | 270 |
} else { |
271 |
parser.skip(input); |
|
272 |
logConstant(key, resolved, true); |
|
273 |
lookup.getLatestPool().putResolved(key, resolved); |
|
274 |
} |
|
50113 | 275 |
} |
276 |
} catch (Exception e) { |
|
57360 | 277 |
throw new IOException("Error parsing constant pool type " + getName(id) + " at position " + input.position() + " at check point between [" + lastCP + ", " + lastCP + size + "]", |
278 |
e); |
|
50113 | 279 |
} |
280 |
} |
|
57360 | 281 |
if (input.position() != lastCP + size) { |
50113 | 282 |
throw new IOException("Size of check point event doesn't match content"); |
283 |
} |
|
284 |
} |
|
285 |
} |
|
286 |
||
57360 | 287 |
private void logConstant(long key, Object v, boolean preresolved) { |
288 |
if (!Logger.shouldLog(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE)) { |
|
289 |
return; |
|
290 |
} |
|
291 |
String valueText; |
|
292 |
if (v.getClass().isArray()) { |
|
293 |
Object[] array = (Object[]) v; |
|
294 |
StringJoiner sj = new StringJoiner(", ", "{", "}"); |
|
295 |
for (int i = 0; i < array.length; i++) { |
|
296 |
sj.add(textify(array[i])); |
|
297 |
} |
|
298 |
valueText = sj.toString(); |
|
299 |
} else { |
|
300 |
valueText = textify(v); |
|
301 |
} |
|
302 |
String suffix = preresolved ? " (presolved)" :""; |
|
303 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE, "Constant: " + key + " = " + valueText + suffix); |
|
304 |
} |
|
305 |
||
306 |
private String textify(Object o) { |
|
307 |
if (o == null) { // should not happen |
|
308 |
return "null"; |
|
309 |
} |
|
310 |
if (o instanceof String) { |
|
311 |
return "\"" + String.valueOf(o) + "\""; |
|
312 |
} |
|
313 |
if (o instanceof RecordedObject) { |
|
314 |
return o.getClass().getName(); |
|
315 |
} |
|
316 |
if (o.getClass().isArray()) { |
|
317 |
Object[] array = (Object[]) o; |
|
318 |
if (array.length > 0) { |
|
319 |
return textify(array[0]) + "[]"; // can it be recursive? |
|
320 |
} |
|
321 |
} |
|
322 |
return String.valueOf(o); |
|
323 |
} |
|
324 |
||
50113 | 325 |
private String getName(long id) { |
326 |
Type type = typeMap.get(id); |
|
52850 | 327 |
return type == null ? ("unknown(" + id + ")") : type.getName(); |
50113 | 328 |
} |
329 |
||
330 |
public Collection<Type> getTypes() { |
|
331 |
return metadata.getTypes(); |
|
332 |
} |
|
333 |
||
334 |
public List<EventType> getEventTypes() { |
|
335 |
return metadata.getEventTypes(); |
|
336 |
} |
|
337 |
||
57360 | 338 |
public boolean isLastChunk() throws IOException { |
50113 | 339 |
return chunkHeader.isLastChunk(); |
340 |
} |
|
341 |
||
57427 | 342 |
public ChunkParser newChunkParser() throws IOException { |
343 |
return new ChunkParser(this); |
|
344 |
} |
|
345 |
||
50113 | 346 |
public ChunkParser nextChunkParser() throws IOException { |
57360 | 347 |
return new ChunkParser(chunkHeader.nextHeader(), this, pollInterval); |
348 |
} |
|
349 |
||
350 |
public boolean isChunkFinished() { |
|
351 |
return chunkFinished; |
|
50113 | 352 |
} |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
353 |
|
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
354 |
// Need to call updateEventParsers() for |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
355 |
// change to take effect |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
356 |
public void setReuse(boolean resue) { |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
357 |
this.reuse = resue; |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
358 |
} |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
359 |
|
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
360 |
// Need to call updateEventParsers() for |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
361 |
// change to take effect |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
362 |
public void setOrdered(boolean ordered) { |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
363 |
this.ordered = ordered; |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
364 |
} |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
365 |
|
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
366 |
// Need to call updateEventParsers() for |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
367 |
// change to take effect |
57452
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
368 |
public void setFirstNanos(long firstNanos) { |
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
369 |
long chunkStart = chunkHeader.getStartNanos(); |
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
370 |
// Optimization. |
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
371 |
if (firstNanos < chunkStart - 1_000_000_000L) { |
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
372 |
firstNanos = 0; |
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
373 |
} |
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
374 |
this.firstNanos = firstNanos; |
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
375 |
} |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
376 |
public void setLastNanos(long lastNanos) { |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
377 |
this.lastNanos = lastNanos; |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
378 |
} |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
379 |
|
57452
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
380 |
|
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
381 |
// Need to call updateEventParsers() for |
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
382 |
// change to take effect |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
383 |
public void resetEventCache() { |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
384 |
this.resetEventCache = true; |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
385 |
} |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
386 |
|
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
387 |
public void updateEventParsers() { |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
388 |
parsers.forEach(p -> { |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
389 |
if (p instanceof EventParser) { |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
390 |
EventParser ep = (EventParser) p; |
57433 | 391 |
String name = ep.getEventType().getName(); |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
392 |
ep.setOrdered(ordered); |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
393 |
ep.setReuse(reuse); |
57452
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
394 |
ep.setFirstNanos(firstNanos); |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
395 |
ep.setLastNanos(lastNanos); |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
396 |
if (resetEventCache) { |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
397 |
ep.resetCache(); |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
398 |
} |
57433 | 399 |
long threshold = eventFilter.getThreshold(name); |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
400 |
if (threshold >= 0) { |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
401 |
ep.setEnabled(true); |
57452
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
402 |
ep.setThresholdNanos(threshold); |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
403 |
} else { |
57433 | 404 |
ep.setEnabled(false); |
57452
6fabe73e5d9a
Reduced allocation pressure. Fix getValue for startTime and duration
egahlin
parents:
57433
diff
changeset
|
405 |
ep.setThresholdNanos(Long.MAX_VALUE); |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
406 |
} |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
407 |
} |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
408 |
}); |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
409 |
resetEventCache = false; |
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
410 |
} |
57640
46a77fccd251
Fix first(...), next(...) and last() path from RepositoryFiles
egahlin
parents:
57604
diff
changeset
|
411 |
|
46a77fccd251
Fix first(...), next(...) and last() path from RepositoryFiles
egahlin
parents:
57604
diff
changeset
|
412 |
public long getChunkDuration() { |
46a77fccd251
Fix first(...), next(...) and last() path from RepositoryFiles
egahlin
parents:
57604
diff
changeset
|
413 |
return chunkHeader.getDurationNanos(); |
46a77fccd251
Fix first(...), next(...) and last() path from RepositoryFiles
egahlin
parents:
57604
diff
changeset
|
414 |
} |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
415 |
|
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
416 |
public long getStartNanos() { |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
417 |
return chunkHeader.getStartNanos(); |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
418 |
} |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
419 |
|
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
420 |
|
50113 | 421 |
} |