Fix some null warnings
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.core / src / org / eclipse / tracecompass / tmf / ctf / core / trace / CtfTmfTrace.java
CommitLineData
b1baa808 1/*******************************************************************************
da707390 2 * Copyright (c) 2012, 2015 Ericsson, École Polytechnique de Montréal
b1baa808
MK
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
ea271da6
PT
9 * Contributors:
10 * Matthew Khouzam - Initial API and implementation
11 * Patrick Tasse - Updated for removal of context clone
e73a4ba5 12 * Geneviève Bastien - Added the createTimestamp function
b1baa808
MK
13 *******************************************************************************/
14
9722e5d7 15package org.eclipse.tracecompass.tmf.ctf.core.trace;
a3fc8213 16
5db5a3a4
AM
17import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
18
96c0f2af 19import java.nio.BufferOverflowException;
032ecd45 20import java.nio.ByteBuffer;
409bea20 21import java.util.ArrayList;
f9ff7d40 22import java.util.Collection;
e600c338 23import java.util.Collections;
2db2b43a 24import java.util.HashMap;
409bea20 25import java.util.List;
299e494e 26import java.util.Map;
409bea20 27import java.util.Set;
299e494e 28
a3fc8213
AM
29import org.eclipse.core.resources.IProject;
30import org.eclipse.core.resources.IResource;
6fd3c6e9 31import org.eclipse.core.runtime.CoreException;
a94410d9
MK
32import org.eclipse.core.runtime.IStatus;
33import org.eclipse.core.runtime.Status;
8192209b 34import org.eclipse.jdt.annotation.NonNull;
680f9173 35import org.eclipse.tracecompass.ctf.core.CTFException;
f357bcd4
AM
36import org.eclipse.tracecompass.ctf.core.event.CTFClock;
37import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
0c2409c1 38import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
f357bcd4
AM
39import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
40import org.eclipse.tracecompass.ctf.core.trace.CTFTraceReader;
d16bb0dd 41import org.eclipse.tracecompass.ctf.core.trace.Metadata;
2bdf0193 42import org.eclipse.tracecompass.internal.tmf.ctf.core.Activator;
fe71057b
AM
43import org.eclipse.tracecompass.internal.tmf.ctf.core.trace.iterator.CtfIterator;
44import org.eclipse.tracecompass.internal.tmf.ctf.core.trace.iterator.CtfIteratorManager;
2bdf0193
AM
45import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
46import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
2bdf0193 47import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
f9ff7d40 48import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
2bdf0193
AM
49import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
50import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
da707390 51import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
2bdf0193
AM
52import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
53import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
2bdf0193
AM
54import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceProperties;
55import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceWithPreDefinedEvents;
56import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
d16bb0dd 57import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
2bdf0193
AM
58import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfPersistentlyIndexable;
59import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
60import org.eclipse.tracecompass.tmf.core.trace.indexer.TmfBTreeTraceIndexer;
61import org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint;
62import org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint;
63import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
9722e5d7
AM
64import org.eclipse.tracecompass.tmf.ctf.core.CtfConstants;
65import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocation;
66import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocationInfo;
67import org.eclipse.tracecompass.tmf.ctf.core.context.CtfTmfContext;
68import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
8e376474 69import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventFactory;
9722e5d7 70import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventType;
f9ff7d40
AM
71import org.eclipse.tracecompass.tmf.ctf.core.event.aspect.CtfChannelAspect;
72import org.eclipse.tracecompass.tmf.ctf.core.event.aspect.CtfCpuAspect;
a3fc8213 73
f9ff7d40 74import com.google.common.collect.ImmutableList;
409bea20
GB
75import com.google.common.collect.ImmutableSet;
76
9ac2eb62 77/**
d09f973b
FC
78 * The CTf trace handler
79 *
80 * @version 1.0
81 * @author Matthew khouzam
9ac2eb62 82 */
22307af3 83public class CtfTmfTrace extends TmfTrace
5733be39 84 implements ITmfTraceProperties, ITmfPersistentlyIndexable,
0ff9e595 85 ITmfTraceWithPreDefinedEvents {
a3fc8213 86
a94410d9
MK
87 // -------------------------------------------
88 // Constants
89 // -------------------------------------------
f9ff7d40 90
324a6a4a
BH
91 /**
92 * Default cache size for CTF traces
93 */
94 protected static final int DEFAULT_CACHE_SIZE = 50000;
64c2cb4c 95
f9ff7d40
AM
96 /**
97 * Event aspects available for all CTF traces
dbc7991d 98 * @since 1.0
f9ff7d40 99 */
df2597e0 100 protected static final @NonNull Collection<@NonNull ITmfEventAspect> CTF_ASPECTS =
5db5a3a4 101 checkNotNull(ImmutableList.of(
f9ff7d40
AM
102 ITmfEventAspect.BaseAspects.TIMESTAMP,
103 new CtfChannelAspect(),
104 new CtfCpuAspect(),
105 ITmfEventAspect.BaseAspects.EVENT_TYPE,
106 ITmfEventAspect.BaseAspects.CONTENTS
5db5a3a4 107 ));
f9ff7d40
AM
108
109 /**
bb52f9bc
GB
110 * The Ctf clock unique identifier field
111 */
112 private static final String CLOCK_HOST_PROPERTY = "uuid"; //$NON-NLS-1$
cd43d683 113 private static final int CONFIDENCE = 10;
d16bb0dd 114 private static final int MIN_CONFIDENCE = 1;
bb52f9bc 115
a94410d9
MK
116 // -------------------------------------------
117 // Fields
118 // -------------------------------------------
a3fc8213 119
df2597e0
AM
120 private final Map<@NonNull String, @NonNull CtfTmfEventType> fContainedEventTypes =
121 Collections.synchronizedMap(new HashMap<>());
e600c338 122
df2597e0 123 private final CtfIteratorManager fIteratorManager = new CtfIteratorManager(this);
6a0ec7bc 124
8e376474
AM
125 private final @NonNull CtfTmfEventFactory fEventFactory;
126
127 /** Reference to the CTF Trace */
4b7c469f 128 private CTFTrace fTrace;
a3fc8213 129
8e376474
AM
130 // -------------------------------------------
131 // Constructor
132 // -------------------------------------------
133
134 /**
135 * Default constructor
136 */
137 public CtfTmfTrace() {
138 super();
139
140 /* Use default event factory */
141 fEventFactory = CtfTmfEventFactory.instance();
142 }
143
144 /**
145 * Constructor for sub-classes to specify their own event factory.
146 *
147 * @param eventFactory
148 * The event factory to use to generate trace events
149 * @since 2.0
150 */
151 protected CtfTmfTrace(@NonNull CtfTmfEventFactory eventFactory) {
152 super();
153 fEventFactory = eventFactory;
154 }
155
a94410d9
MK
156 // -------------------------------------------
157 // TmfTrace Overrides
158 // -------------------------------------------
b1baa808
MK
159 /**
160 * Method initTrace.
063f0d27
AM
161 *
162 * @param resource
163 * The resource associated with this trace
164 * @param path
165 * The path to the trace file
166 * @param eventType
167 * The type of events that will be read from this trace
b1baa808 168 * @throws TmfTraceException
07804639 169 * If something went wrong while reading the trace
b1baa808 170 */
a3fc8213 171 @Override
6256d8ad 172 public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> eventType)
b4f71e4a 173 throws TmfTraceException {
4a110860
AM
174 /*
175 * Set the cache size. This has to be done before the call to super()
176 * because the super needs to know the cache size.
177 */
178 setCacheSize();
324a6a4a 179
32c16b50
GB
180 super.initTrace(resource, path, eventType);
181
a3fc8213
AM
182 try {
183 this.fTrace = new CTFTrace(path);
81a2d02e 184 CtfTmfContext ctx;
99b483fe 185 /* Set the start and (current) end times for this trace */
81a2d02e 186 ctx = (CtfTmfContext) seekEvent(0L);
132a02b0 187 CtfTmfEvent event = getNext(ctx);
a94410d9 188 if ((ctx.getLocation().equals(CtfIterator.NULL_LOCATION)) || (ctx.getCurrentEvent() == null)) {
99b483fe
AM
189 /* Handle the case where the trace is empty */
190 this.setStartTime(TmfTimestamp.BIG_BANG);
191 } else {
132a02b0 192 final ITmfTimestamp curTime = event.getTimestamp();
21fb02fa
MK
193 this.setStartTime(curTime);
194 this.setEndTime(curTime);
99b483fe 195 }
409bea20
GB
196 /*
197 * Register every event type. When you call getType, it will
198 * register a trace to that type in the TmfEventTypeManager
199 */
6a0ec7bc 200 try (CtfIterator iter = fIteratorManager.getIterator(ctx)) {
409bea20 201 for (IEventDeclaration ied : iter.getEventDeclarations()) {
e600c338 202 CtfTmfEventType ctfTmfEventType = fContainedEventTypes.get(ied.getName());
409bea20
GB
203 if (ctfTmfEventType == null) {
204 List<ITmfEventField> content = new ArrayList<>();
205 /* Should only return null the first time */
0c2409c1
MK
206 final StructDeclaration fields = ied.getFields();
207 if (fields != null) {
208 for (String fieldName : fields.getFieldsList()) {
209 content.add(new TmfEventField(checkNotNull(fieldName), null, null));
210 }
211 ITmfEventField contentTree = new TmfEventField(
212 ITmfEventField.ROOT_FIELD_ID,
213 null,
214 content.toArray(new ITmfEventField[content.size()]));
215
aa353506 216 ctfTmfEventType = new CtfTmfEventType(checkNotNull(ied.getName()), contentTree);
0c2409c1 217 fContainedEventTypes.put(ctfTmfEventType.getName(), ctfTmfEventType);
409bea20 218 }
409bea20
GB
219 }
220 }
221 }
dd5615b7 222 ctx.dispose();
680f9173 223 } catch (final CTFException e) {
a3fc8213
AM
224 /*
225 * If it failed at the init(), we can assume it's because the file
226 * was not found or was not recognized as a CTF trace. Throw into
227 * the new type of exception expected by the rest of TMF.
228 */
9fa32496 229 throw new TmfTraceException(e.getMessage(), e);
a3fc8213 230 }
a3fc8213
AM
231 }
232
53b235e1
MK
233 @Override
234 public synchronized void dispose() {
6a0ec7bc 235 fIteratorManager.dispose();
5d1c6919 236 if (fTrace != null) {
5d1c6919
PT
237 fTrace = null;
238 }
53b235e1
MK
239 super.dispose();
240 }
241
b1baa808 242 /**
cd43d683
PT
243 * {@inheritDoc}
244 * <p>
d16bb0dd
BH
245 * The default implementation of a CTF trace.
246 *
247 * Firstly a weak validation of the metadata is done to determine if the
248 * path is actually for a CTF trace. After that a full validation is done.
249 *
250 * If the weak and full validation are successful the confidence is set
251 * to 10.
252 *
253 * If the weak validation was successful, but the full validation fails
254 * a TraceValidationStatus with severity warning and confidence of 1 is
255 * returned.
256 *
257 * If both weak and full validation fails an error status is returned.
b1baa808 258 */
a3fc8213 259 @Override
a94410d9 260 public IStatus validate(final IProject project, final String path) {
f841e903 261 boolean isMetadataFile = false;
b562a24f 262 try {
f841e903 263 isMetadataFile = Metadata.preValidate(path);
d16bb0dd
BH
264 } catch (final CTFException e) {
265 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + e.toString(), e); //$NON-NLS-1$
266 }
267
f841e903 268 if (isMetadataFile) {
d16bb0dd
BH
269 // Trace is pre-validated, continue will full validation
270 try {
271 final CTFTrace trace = new CTFTrace(path);
272 if (!trace.majorIsSet()) {
f841e903 273 if (isMetadataFile) {
d16bb0dd
BH
274 return new TraceValidationStatus(MIN_CONFIDENCE, IStatus.WARNING, Activator.PLUGIN_ID, Messages.CtfTmfTrace_MajorNotSet, null);
275 }
276 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_MajorNotSet);
b5354daa 277 }
d16bb0dd
BH
278
279 // Validate using reader initialization
280 try (CTFTraceReader ctfTraceReader = new CTFTraceReader(trace)) {}
281
282 // Trace is validated, return with confidence
283 return new CtfTraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID, trace.getEnvironment());
284
f841e903
BH
285 } catch (final CTFException | BufferOverflowException e ) {
286 // return warning since it's a CTF trace but with errors in it
287 return new TraceValidationStatus(MIN_CONFIDENCE, IStatus.WARNING, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + e.toString(), e); //$NON-NLS-1$
a94410d9 288 }
a3fc8213 289 }
d16bb0dd 290 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError);
a3fc8213
AM
291 }
292
f9ff7d40
AM
293 @Override
294 public Iterable<ITmfEventAspect> getEventAspects() {
295 return CTF_ASPECTS;
296 }
297
b1baa808 298 /**
f474d36b 299 * Method getCurrentLocation. This is not applicable in CTF
a94410d9 300 *
f474d36b 301 * @return null, since the trace has no knowledge of the current location
2bdf0193 302 * @see org.eclipse.tracecompass.tmf.core.trace.ITmfTrace#getCurrentLocation()
b1baa808 303 */
a3fc8213 304 @Override
1e1bef82 305 public ITmfLocation getCurrentLocation() {
f474d36b 306 return null;
a3fc8213
AM
307 }
308
a3fc8213 309 @Override
1e1bef82 310 public double getLocationRatio(ITmfLocation location) {
4b7c469f 311 final CtfLocation curLocation = (CtfLocation) location;
4a1f6c41
PT
312 final long startTime = getStartTime().getValue();
313 final double diff = curLocation.getLocationInfo().getTimestamp() - startTime;
314 final double total = getEndTime().getValue() - startTime;
315 return Math.max(0.0, Math.min(1.0, diff / total));
a3fc8213
AM
316 }
317
b1baa808
MK
318 /**
319 * Method seekEvent.
a94410d9
MK
320 *
321 * @param location
322 * ITmfLocation<?>
b1baa808 323 * @return ITmfContext
b1baa808 324 */
a3fc8213 325 @Override
76643eb7 326 public synchronized ITmfContext seekEvent(final ITmfLocation location) {
ce2388e0 327 CtfLocation currentLocation = (CtfLocation) location;
81a2d02e 328 CtfTmfContext context = new CtfTmfContext(this);
76643eb7
BH
329 if (fTrace == null) {
330 context.setLocation(null);
331 context.setRank(ITmfContext.UNKNOWN_RANK);
332 return context;
333 }
4a110860
AM
334 /*
335 * The rank is set to 0 if the iterator seeks the beginning. If not, it
336 * will be set to UNKNOWN_RANK, since CTF traces don't support seeking
337 * by rank for now.
338 */
11d6f468 339 if (currentLocation == null) {
f5df94f8 340 currentLocation = new CtfLocation(new CtfLocationInfo(0L, 0L));
4a110860 341 context.setRank(0);
544c79ad 342 } else {
3bd44ac8 343 context.setRank(ITmfContext.UNKNOWN_RANK);
64c2cb4c 344 }
544c79ad
PT
345 /* This will seek and update the location after the seek */
346 context.setLocation(currentLocation);
f474d36b 347 return context;
a3fc8213
AM
348 }
349
a3fc8213 350 @Override
76643eb7 351 public synchronized ITmfContext seekEvent(double ratio) {
81a2d02e 352 CtfTmfContext context = new CtfTmfContext(this);
76643eb7
BH
353 if (fTrace == null) {
354 context.setLocation(null);
355 context.setRank(ITmfContext.UNKNOWN_RANK);
356 return context;
357 }
4a1f6c41
PT
358 final long end = getEndTime().getValue();
359 final long start = getStartTime().getValue();
b2dc9e02 360 final long diff = end - start;
15e89960 361 final long ratioTs = Math.round(diff * ratio) + start;
b2dc9e02 362 context.seek(ratioTs);
f474d36b
PT
363 context.setRank(ITmfContext.UNKNOWN_RANK);
364 return context;
a3fc8213
AM
365 }
366
b1baa808
MK
367 /**
368 * Method readNextEvent.
a94410d9
MK
369 *
370 * @param context
371 * ITmfContext
b1baa808 372 * @return CtfTmfEvent
2bdf0193 373 * @see org.eclipse.tracecompass.tmf.core.trace.ITmfTrace#getNext(ITmfContext)
b1baa808 374 */
a3fc8213 375 @Override
4b7c469f 376 public synchronized CtfTmfEvent getNext(final ITmfContext context) {
faa38350
PT
377 if (fTrace == null) {
378 return null;
379 }
f474d36b 380 CtfTmfEvent event = null;
81a2d02e 381 if (context instanceof CtfTmfContext) {
575beffc 382 if (context.getLocation() == null || CtfLocation.INVALID_LOCATION.equals(context.getLocation().getLocationInfo())) {
ae09313d
PT
383 return null;
384 }
81a2d02e 385 CtfTmfContext ctfContext = (CtfTmfContext) context;
788ddcbc 386 event = ctfContext.getCurrentEvent();
4a110860 387
324a6a4a 388 if (event != null) {
5904c11e 389 updateAttributes(context, event);
788ddcbc
MK
390 ctfContext.advance();
391 ctfContext.increaseRank();
324a6a4a 392 }
f474d36b 393 }
4a110860 394
aa572e22 395 return event;
a3fc8213
AM
396 }
397
bb52f9bc
GB
398 /**
399 * Ctf traces have a clock with a unique uuid that will be used to identify
400 * the host. Traces with the same clock uuid will be known to have been made
401 * on the same machine.
402 *
403 * Note: uuid is an optional field, it may not be there for a clock.
404 */
405 @Override
406 public String getHostId() {
fe71057b 407 CTFClock clock = fTrace.getClock();
bb52f9bc
GB
408 if (clock != null) {
409 String clockHost = (String) clock.getProperty(CLOCK_HOST_PROPERTY);
410 if (clockHost != null) {
411 return clockHost;
412 }
413 }
414 return super.getHostId();
415 }
416
fe71057b
AM
417 /**
418 * Get the CTF environment variables defined in this CTF trace, in <name,
419 * value> form. This comes from the trace's CTF metadata.
420 *
421 * @return The CTF environment
422 */
423 public Map<String, String> getEnvironment() {
424 return fTrace.getEnvironment();
425 }
426
a94410d9 427 // -------------------------------------------
22307af3 428 // ITmfTraceProperties
a94410d9 429 // -------------------------------------------
4b7c469f 430
22307af3
AM
431 @Override
432 public Map<String, String> getTraceProperties() {
2db2b43a
GB
433 Map<String, String> properties = new HashMap<>();
434 properties.putAll(fTrace.getEnvironment());
435 properties.put(Messages.CtfTmfTrace_HostID, getHostId());
436 return properties;
4b7c469f
MK
437 }
438
a94410d9
MK
439 // -------------------------------------------
440 // Clocks
441 // -------------------------------------------
bfe038ff 442
9ac2eb62
MK
443 /**
444 * gets the clock offset
a94410d9 445 *
9ac2eb62
MK
446 * @return the clock offset in ns
447 */
a94410d9
MK
448 public long getOffset() {
449 if (fTrace != null) {
bfe038ff
MK
450 return fTrace.getOffset();
451 }
452 return 0;
453 }
454
fe71057b
AM
455 /**
456 * Convert a CTF timestamp in CPU cycles to its equivalent in nanoseconds
457 * for this trace.
458 *
459 * @param cycles
460 * The timestamp in cycles
461 * @return The timestamp in nanoseconds
462 */
463 public long timestampCyclesToNanos(long cycles) {
464 return fTrace.timestampCyclesToNanos(cycles);
465 }
466
467 /**
468 * Convert a CTF timestamp in nanoseconds to its equivalent in CPU cycles
469 * for this trace.
470 *
471 * @param nanos
472 * The timestamp in nanoseconds
473 * @return The timestamp in cycles
474 */
475 public long timestampNanoToCycles(long nanos) {
476 return fTrace.timestampNanoToCycles(nanos);
477 }
478
3480bf12 479 /**
409bea20 480 * Gets the list of declared events
3480bf12 481 */
409bea20 482 @Override
df2597e0 483 public Set<@NonNull CtfTmfEventType> getContainedEventTypes() {
e600c338
AM
484 return ImmutableSet.copyOf(fContainedEventTypes.values());
485 }
486
487 /**
488 * Register an event type to this trace.
489 *
9722e5d7 490 * Public visibility so that {@link CtfTmfEvent#getType} can call it.
e600c338
AM
491 *
492 * FIXME This could probably be made cleaner?
9722e5d7
AM
493 *
494 * @param eventType
495 * The event type to register
e600c338 496 */
9722e5d7 497 public void registerEventType(CtfTmfEventType eventType) {
e600c338 498 fContainedEventTypes.put(eventType.getName(), eventType);
3480bf12
GB
499 }
500
a94410d9
MK
501 // -------------------------------------------
502 // Parser
503 // -------------------------------------------
4b7c469f
MK
504
505 @Override
bfe038ff 506 public CtfTmfEvent parseEvent(ITmfContext context) {
4b7c469f 507 CtfTmfEvent event = null;
ea271da6
PT
508 if (context instanceof CtfTmfContext) {
509 final ITmfContext tmpContext = seekEvent(context.getLocation());
510 event = getNext(tmpContext);
4b7c469f
MK
511 }
512 return event;
11d6f468 513 }
64c2cb4c 514
324a6a4a 515 /**
64c2cb4c 516 * Sets the cache size for a CtfTmfTrace.
324a6a4a
BH
517 */
518 protected void setCacheSize() {
519 setCacheSize(DEFAULT_CACHE_SIZE);
520 }
ce2388e0 521
a94410d9 522 // -------------------------------------------
fe71057b 523 // CtfIterator factory methods
a94410d9 524 // -------------------------------------------
53b235e1 525
8e376474
AM
526 /**
527 * Get the event factory for this trace to generate new events for it.
528 *
529 * @return The event factory
530 * @since 2.0
531 */
532 public @NonNull CtfTmfEventFactory getEventFactory() {
533 return fEventFactory;
534 }
535
36dd544c
MK
536 /**
537 * Get an iterator to the trace
538 *
539 * @return an iterator to the trace
540 */
fe71057b
AM
541 public ITmfContext createIterator() {
542 try {
543 return new CtfIterator(fTrace, this);
680f9173 544 } catch (CTFException e) {
fe71057b
AM
545 Activator.getDefault().logError(e.getMessage(), e);
546 }
547 return null;
548 }
549
550 /**
551 * Get an iterator to the trace, , which will initially point to the given
552 * location/rank.
553 *
554 * @param ctfLocationData
555 * The initial timestamp the iterator will be pointing to
556 * @param rank
557 * The initial rank
558 * @return The new iterator
559 */
560 public ITmfContext createIterator(CtfLocationInfo ctfLocationData, long rank) {
db8e8f7d 561 try {
fe71057b 562 return new CtfIterator(fTrace, this, ctfLocationData, rank);
680f9173 563 } catch (CTFException e) {
91e7f946 564 Activator.getDefault().logError(e.getMessage(), e);
db8e8f7d
AM
565 }
566 return null;
36dd544c 567 }
e73a4ba5 568
0451d4d7
AM
569 /**
570 * Create the 'CtfIterator' object from a CtfTmfContext.
571 *
572 * @param context
573 * The iterator will initially be pointing to this context
574 * @return A new CtfIterator object
575 * @since 1.0
576 */
577 public ITmfContext createIteratorFromContext(CtfTmfContext context) {
578 return fIteratorManager.getIterator(context);
579 }
580
581 /**
582 * Dispose an iterator that was create with
583 * {@link #createIteratorFromContext}
584 *
585 * @param context
586 * The last context that was pointed to by the iterator (this is
587 * the 'key' to find the correct iterator to dispose).
588 * @since 1.0
589 */
590 public void disposeContext(CtfTmfContext context) {
591 fIteratorManager.removeIterator(context);
592 }
593
e73a4ba5
GB
594 // ------------------------------------------------------------------------
595 // Timestamp transformation functions
596 // ------------------------------------------------------------------------
597
da707390
MK
598 /**
599 * @since 1.0
600 */
e73a4ba5 601 @Override
da707390
MK
602 public @NonNull TmfNanoTimestamp createTimestamp(long ts) {
603 return new TmfNanoTimestamp(getTimestampTransform().transform(ts));
e73a4ba5 604 }
032ecd45
MAL
605
606 private static int fCheckpointSize = -1;
607
608 @Override
609 public synchronized int getCheckpointSize() {
610 if (fCheckpointSize == -1) {
da707390 611 TmfCheckpoint c = new TmfCheckpoint(new TmfNanoTimestamp(0), new CtfLocation(0, 0), 0);
032ecd45
MAL
612 ByteBuffer b = ByteBuffer.allocate(ITmfCheckpoint.MAX_SERIALIZE_SIZE);
613 b.clear();
614 c.serialize(b);
615 fCheckpointSize = b.position();
616 }
617
618 return fCheckpointSize;
619 }
620
621 @Override
622 protected ITmfTraceIndexer createIndexer(int interval) {
623 return new TmfBTreeTraceIndexer(this, interval);
624 }
625
626 @Override
627 public ITmfLocation restoreLocation(ByteBuffer bufferIn) {
628 return new CtfLocation(bufferIn);
629 }
6fd3c6e9
MAL
630
631 @Override
632 public boolean isComplete() {
633 if (getResource() == null) {
634 return true;
635 }
636
637 String host = null;
638 String port = null;
639 String sessionName = null;
640 try {
641 host = getResource().getPersistentProperty(CtfConstants.LIVE_HOST);
642 port = getResource().getPersistentProperty(CtfConstants.LIVE_PORT);
643 sessionName = getResource().getPersistentProperty(CtfConstants.LIVE_SESSION_NAME);
644 } catch (CoreException e) {
645 Activator.getDefault().logError(e.getMessage(), e);
b562a24f
MK
646 // Something happened to the resource, assume we won't get any more
647 // data from it
6fd3c6e9
MAL
648 return true;
649 }
650 return host == null || port == null || sessionName == null;
651 }
652
653 @Override
654 public void setComplete(final boolean isComplete) {
655 super.setComplete(isComplete);
656 try {
657 if (isComplete) {
658 getResource().setPersistentProperty(CtfConstants.LIVE_HOST, null);
659 getResource().setPersistentProperty(CtfConstants.LIVE_PORT, null);
660 getResource().setPersistentProperty(CtfConstants.LIVE_SESSION_NAME, null);
661 }
662 } catch (CoreException e) {
663 Activator.getDefault().logError(e.getMessage(), e);
664 }
665 }
a3fc8213 666}
This page took 0.147738 seconds and 5 git commands to generate.