Skip to content

Commit

Permalink
Add clock scale to CTFTrace environment
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Siwei Zhang committed Sep 27, 2024
1 parent 945b92e commit 33532fd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -154,6 +155,12 @@ public String toString() {
private static final FileFilter METADATA_FILE_FILTER = new MetadataFileFilter();
private static final Comparator<File> 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;
Expand Down Expand Up @@ -777,7 +784,14 @@ public void addStream(ICTFStream stream) throws ParseException {
* (key, value)
*/
public Map<String, String> getEnvironment() {
return Collections.unmodifiableMap(fEnvironment);
Map<String, String> env = new LinkedHashMap<>();
env.putAll(fEnvironment);
for (Entry<String, CTFClock> 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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -584,7 +577,6 @@ public Map<String, String> getProperties() {
return properties;
}
properties.putAll(trace.getEnvironment());
properties.put(CLOCK_OFFSET, Long.toUnsignedString(trace.getOffset()));
properties.put(Messages.CtfTmfTrace_HostID, getHostId());
return properties;
}
Expand Down

0 comments on commit 33532fd

Please sign in to comment.