Skip to content

Commit 3389fa5

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 3389fa5

File tree

3 files changed

+59
-11
lines changed

3 files changed

+59
-11
lines changed

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

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,19 +218,13 @@ 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 = setStartAndEndTime(false);
223+
224+
if (ctx == null) {
225+
return;
233226
}
227+
234228
/*
235229
* Register every event type. When you call getType, it will register a trace to
236230
* that type in the TmfEventTypeManager
@@ -913,4 +907,37 @@ public Path trim(@NonNull TmfTimeRange range, @NonNull Path destinationPath, @No
913907
return null;
914908
}
915909

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

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,24 @@ 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+
* Subclasses might want to reset the start and end time of the trace if
229+
* needed.
230+
*
231+
* Note: Only call this when there is no trace reading is ongoing. Caller
232+
* needs to ensure that trace indexing is restarted.
233+
*
234+
* @since 10.2
235+
*/
236+
public synchronized void resetIndexer() {
237+
if (fIndexer != null) {
238+
fIndexer.dispose();
239+
}
240+
fIndexer = createIndexer(fCacheSize);
241+
}
242+
225243
// ------------------------------------------------------------------------
226244
// ITmfTrace - Initializers
227245
// ------------------------------------------------------------------------

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ public void initExperiment(final Class<? extends ITmfEvent> type,
367367
if (!newTransform.equals(currentTransform)) {
368368
TmfTraceManager.deleteSupplementaryFiles(trace);
369369
trace.setTimestampTransform(newTransform);
370+
if (trace instanceof TmfTrace tmfTrace) {
371+
tmfTrace.resetIndexer();
372+
}
370373
}
371374
});
372375
}

0 commit comments

Comments
 (0)