Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,13 @@ public void initTrace(final IResource resource, final String path, final Class<?

try {
this.fTrace = new CTFTrace(path);
CtfTmfContext ctx;
/* Set the start and (current) end times for this trace */
ctx = (CtfTmfContext) seekEvent(0L);
CtfTmfEvent event = getNext(ctx);
if ((ctx.getLocation().equals(CtfIterator.NULL_LOCATION)) || (ctx.getCurrentEvent() == null)) {
/* Handle the case where the trace is empty */
this.setStartTime(TmfTimestamp.BIG_BANG);
} else {
final ITmfTimestamp curTime = event.getTimestamp();
this.setStartTime(curTime);
long endTime = Math.max(curTime.getValue(), fTrace.getCurrentEndTime());
this.setEndTime(TmfTimestamp.fromNanos(endTime));
CtfTmfContext ctx = setStartAndEndTime(false);

if (ctx == null) {
return;
}

/*
* Register every event type. When you call getType, it will register a trace to
* that type in the TmfEventTypeManager
Expand Down Expand Up @@ -913,4 +907,37 @@ public Path trim(@NonNull TmfTimeRange range, @NonNull Path destinationPath, @No
return null;
}

@Override
public synchronized void resetIndexer() {
super.resetIndexer();
setStartAndEndTime(true);
}

private @Nullable CtfTmfContext setStartAndEndTime(boolean reset) {
/* Set the start and (current) end times for this trace */
CtfTmfContext ctx = (CtfTmfContext) seekEvent(0L);

/* Verify context is valid. It's only invalid trace if trace.init() hasn't been called) */
if ((ctx != null) && (ctx.getLocation() != null)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is for the case that setTimestampTransform() is called before initTrace() and it avoids a NullPointerException. The test CtfTmfReadBoundsTest.testRapidBoundsWithTransform() for example call the transform method before init.

if (reset == true) {
/* Reset to uninitialized */
setStartTime(TmfTimestamp.BIG_BANG);
setEndTime(TmfTimestamp.BIG_BANG);
}

CtfTmfEvent event = getNext(ctx);
if ((ctx.getLocation().equals(CtfIterator.NULL_LOCATION)) || (ctx.getCurrentEvent() == null)) {
/* Handle the case where the trace is empty */
this.setStartTime(TmfTimestamp.BIG_BANG);
} else {
final ITmfTimestamp curTime = event.getTimestamp();
this.setStartTime(curTime);
long endTime = createTimestamp(fTrace.getCurrentEndTime()).getValue();
endTime = Math.max(curTime.getValue(), endTime);
this.setEndTime(TmfTimestamp.fromNanos(endTime));
}
return ctx;
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,24 @@ protected ITmfTraceIndexer createIndexer(int interval) {
return new TmfCheckpointIndexer(this, interval);
}

/**
* Reset indexer. It dispose the old indexer and creates a new one.
*
* Subclasses might want to reset the start and end time of the trace if
* needed.
*
* Note: Only call this when there is no trace reading is ongoing. Caller
* needs to ensure that trace indexing is restarted.
*
* @since 10.2
*/
public synchronized void resetIndexer() {
if (fIndexer != null) {
fIndexer.dispose();
}
fIndexer = createIndexer(fCacheSize);
}

// ------------------------------------------------------------------------
// ITmfTrace - Initializers
// ------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ public void initExperiment(final Class<? extends ITmfEvent> type,
if (!newTransform.equals(currentTransform)) {
TmfTraceManager.deleteSupplementaryFiles(trace);
trace.setTimestampTransform(newTransform);
if (trace instanceof TmfTrace tmfTrace) {
tmfTrace.resetIndexer();
}
}
});
}
Expand Down
Loading