Skip to content

Commit 7f174a5

Browse files
committed
tmf.ctf: Re-initialize start and endtime after transform is applied
With this the start and endtime is correct when opening the experiment that has automatically applied timestamp transformation applied. fixes #323 [Fixed] Incorrect start/end time in ITmfTrace instances in experiment [Added] API in TmfTrace to reset indexer Signed-off-by: Bernd Hufmann <[email protected]>
1 parent 22545a7 commit 7f174a5

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/trace/CtfTmfTrace.java

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,11 @@ public void initTrace(final IResource resource, final String path, final Class<?
218218

219219
try {
220220
this.fTrace = new CTFTrace(path);
221-
CtfTmfContext ctx;
222221
/* Set the start and (current) end times for this trace */
223-
ctx = (CtfTmfContext) seekEvent(0L);
224-
CtfTmfEvent event = getNext(ctx);
225-
if ((ctx.getLocation().equals(CtfIterator.NULL_LOCATION)) || (ctx.getCurrentEvent() == null)) {
226-
/* Handle the case where the trace is empty */
227-
this.setStartTime(TmfTimestamp.BIG_BANG);
228-
} else {
229-
final ITmfTimestamp curTime = event.getTimestamp();
230-
this.setStartTime(curTime);
231-
long endTime = Math.max(curTime.getValue(), fTrace.getCurrentEndTime());
232-
this.setEndTime(TmfTimestamp.fromNanos(endTime));
222+
CtfTmfContext ctx = resetTimes();
223+
224+
if (ctx == null) {
225+
return;
233226
}
234227
/*
235228
* Register every event type. When you call getType, it will register a trace to
@@ -913,4 +906,30 @@ public Path trim(@NonNull TmfTimeRange range, @NonNull Path destinationPath, @No
913906
return null;
914907
}
915908

909+
@Override
910+
protected synchronized void resetIndexer() {
911+
super.resetIndexer();
912+
resetTimes();
913+
}
914+
915+
private @Nullable CtfTmfContext resetTimes() {
916+
/* Set the start and (current) end times for this trace */
917+
CtfTmfContext ctx = (CtfTmfContext) seekEvent(0L);
918+
CtfTmfEvent event = getNext(ctx);
919+
/* Verify context is valid. It's only invalid trace if trace.init() hasn't been called) */
920+
if ((ctx != null) && (ctx.getLocation() != null)) {
921+
if ((ctx.getLocation().equals(CtfIterator.NULL_LOCATION)) || (ctx.getCurrentEvent() == null)) {
922+
/* Handle the case where the trace is empty */
923+
this.setStartTime(TmfTimestamp.BIG_BANG);
924+
} else {
925+
final ITmfTimestamp curTime = event.getTimestamp();
926+
this.setStartTime(curTime);
927+
long endTime = createTimestamp(fTrace.getCurrentEndTime()).getValue();
928+
endTime = Math.max(curTime.getValue(), endTime);
929+
this.setEndTime(TmfTimestamp.fromNanos(endTime));
930+
}
931+
return ctx;
932+
}
933+
return null;
934+
}
916935
}

tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/TmfTrace.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,22 @@ protected ITmfTraceIndexer createIndexer(int interval) {
222222
return new TmfCheckpointIndexer(this, interval);
223223
}
224224

225+
/**
226+
* Reset indexer. It dispose the old indexer and creates a new one,
227+
*
228+
* Note:
229+
* Only call this when there is no trace reading is ongoing. Caller
230+
* needs to ensure that trace indexing is restarted.
231+
*
232+
* @since 10.2
233+
*/
234+
protected synchronized void resetIndexer() {
235+
if (fIndexer != null) {
236+
fIndexer.dispose();
237+
}
238+
fIndexer = createIndexer(fCacheSize);
239+
}
240+
225241
// ------------------------------------------------------------------------
226242
// ITmfTrace - Initializers
227243
// ------------------------------------------------------------------------
@@ -379,6 +395,7 @@ public synchronized void dispose() {
379395
ByteBufferTracker.setMarked();
380396
}
381397

398+
382399
// ------------------------------------------------------------------------
383400
// ITmfTrace - Basic getters
384401
// ------------------------------------------------------------------------

tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/experiment/TmfExperiment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ public void initExperiment(final Class<? extends ITmfEvent> type,
366366

367367
if (!newTransform.equals(currentTransform)) {
368368
TmfTraceManager.deleteSupplementaryFiles(trace);
369+
resetIndexer();
369370
trace.setTimestampTransform(newTransform);
370371
}
371372
});

0 commit comments

Comments
 (0)