Skip to content

Commit cc4ca63

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 Signed-off-by: Bernd Hufmann <[email protected]>
1 parent f71a42e commit cc4ca63

File tree

2 files changed

+50
-11
lines changed
  • ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/trace
  • tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace

2 files changed

+50
-11
lines changed

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

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects;
6666
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
6767
import org.eclipse.tracecompass.tmf.core.project.model.ITmfPropertiesProvider;
68+
import org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform;
6869
import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
6970
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
7071
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
@@ -218,18 +219,11 @@ public void initTrace(final IResource resource, final String path, final Class<?
218219

219220
try {
220221
this.fTrace = new CTFTrace(path);
221-
CtfTmfContext ctx;
222222
/* 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));
223+
CtfTmfContext ctx = resetTimes();
224+
225+
if (ctx == null) {
226+
return;
233227
}
234228
/*
235229
* Register every event type. When you call getType, it will register a trace to
@@ -913,4 +907,32 @@ public Path trim(@NonNull TmfTimeRange range, @NonNull Path destinationPath, @No
913907
return null;
914908
}
915909

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

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.1
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
// ------------------------------------------------------------------------

0 commit comments

Comments
 (0)