From 33532fdd72914e675b80c4c3fb91ff832e052e95 Mon Sep 17 00:00:00 2001 From: Siwei Zhang Date: Tue, 24 Sep 2024 10:27:09 +0200 Subject: [PATCH] Add clock scale to CTFTrace environment There is the need to get clock scale of the trace. This commit added the clock scale to the environment variables of the trace. [Added] clock scale in getEnvironment() in CTFTrace [Added] time offset for different clocks, and moved them into getEnvironment() in CTFTrace Signed-off-by: Siwei Zhang --- .../tracecompass/ctf/core/trace/CTFTrace.java | 18 ++++++++++++++++-- .../ctf/core/tests/trace/CtfTmfTraceTest.java | 2 +- .../tmf/ctf/core/trace/CtfTmfTrace.java | 8 -------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFTrace.java b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFTrace.java index a3282f1dde..ec13e2b492 100644 --- a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFTrace.java +++ b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFTrace.java @@ -29,10 +29,11 @@ import java.nio.file.StandardOpenOption; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.UUID; @@ -154,6 +155,12 @@ public String toString() { private static final FileFilter METADATA_FILE_FILTER = new MetadataFileFilter(); private static final Comparator METADATA_COMPARATOR = new MetadataComparator(); + /** + * Clock properties + */ + private static final String CLOCK_OFFSET_SUFFIX = "_offset"; //$NON-NLS-1$ + private static final String CLOCK_SCALE_SUFFIX = "_scale"; //$NON-NLS-1$ + private final DeclarationScope fScope = new DeclarationScope(null, MetadataStrings.TRACE); private boolean fUUIDMismatchWarning = false; @@ -777,7 +784,14 @@ public void addStream(ICTFStream stream) throws ParseException { * (key, value) */ public Map getEnvironment() { - return Collections.unmodifiableMap(fEnvironment); + Map env = new LinkedHashMap<>(); + env.putAll(fEnvironment); + for (Entry clock : fClocks.entrySet()) { + String clockname = clock.getKey(); + env.put(clockname + CLOCK_OFFSET_SUFFIX, String.valueOf( clock.getValue().getClockOffset())); + env.put(clockname + CLOCK_SCALE_SUFFIX, String.valueOf( clock.getValue().getClockScale())); + } + return env; } /** diff --git a/ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/src/org/eclipse/tracecompass/tmf/ctf/core/tests/trace/CtfTmfTraceTest.java b/ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/src/org/eclipse/tracecompass/tmf/ctf/core/tests/trace/CtfTmfTraceTest.java index 9044098568..3eeb4fa0d5 100644 --- a/ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/src/org/eclipse/tracecompass/tmf/ctf/core/tests/trace/CtfTmfTraceTest.java +++ b/ctf/org.eclipse.tracecompass.tmf.ctf.core.tests/src/org/eclipse/tracecompass/tmf/ctf/core/tests/trace/CtfTmfTraceTest.java @@ -245,7 +245,7 @@ public void testGetName() { @Test public void testGetTraceProperties() { int result = fixture.getProperties().size(); - assertEquals(10, result); + assertEquals(11, result); assertEquals(String.valueOf(1332166405241713987L), fixture.getProperties().get("clock_offset")); } diff --git a/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/trace/CtfTmfTrace.java b/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/trace/CtfTmfTrace.java index d34aebde0d..173bec9b35 100644 --- a/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/trace/CtfTmfTrace.java +++ b/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/trace/CtfTmfTrace.java @@ -109,13 +109,6 @@ public class CtfTmfTrace extends TmfTrace // Constants // ------------------------------------------- - /** - * Clock offset property - * - * @since 1.2 - */ - public static final String CLOCK_OFFSET = "clock_offset"; //$NON-NLS-1$ - /** * Default cache size for CTF traces */ @@ -584,7 +577,6 @@ public Map getProperties() { return properties; } properties.putAll(trace.getEnvironment()); - properties.put(CLOCK_OFFSET, Long.toUnsignedString(trace.getOffset())); properties.put(Messages.CtfTmfTrace_HostID, getHostId()); return properties; }