Skip to content

Commit 42c8c7a

Browse files
ctf: Make ctf2 trace have environment
Change-Id: If58b118283f9a5e3778e832edd94e358c23cded8 Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
1 parent c250987 commit 42c8c7a

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/metadata/IOStructGen.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020

2121
import java.util.ArrayList;
2222
import java.util.Collection;
23+
import java.util.LinkedHashMap;
2324
import java.util.List;
25+
import java.util.Map;
26+
import java.util.Map.Entry;
2427
import java.util.stream.Collectors;
2528

2629
import org.eclipse.jdt.annotation.NonNull;
@@ -46,6 +49,8 @@
4649
import org.eclipse.tracecompass.internal.ctf.core.utils.JsonMetadataStrings;
4750

4851
import com.google.common.collect.Iterables;
52+
import com.google.gson.JsonElement;
53+
import com.google.gson.JsonObject;
4954

5055
/**
5156
* IOStructGen
@@ -151,6 +156,23 @@ private void parseRoot(ICTFMetadataNode root) throws ParseException {
151156
throw new ParseException("Only one trace block is allowed"); //$NON-NLS-1$
152157
}
153158
traceNode = child;
159+
if (child instanceof JsonTraceMetadataNode node) {
160+
JsonObject environment = node.getEnvironment();
161+
if (environment != null) {
162+
Map<String, String> env = new LinkedHashMap<>();
163+
164+
for (Entry<String, JsonElement> entry : environment.entrySet()) {
165+
JsonElement value = entry.getValue();
166+
if (value.isJsonPrimitive()) {
167+
env.put(entry.getKey(), value.getAsString());
168+
} else {
169+
env.put(entry.getKey(), value.toString());
170+
}
171+
}
172+
fTrace.setEnvironment(env);
173+
}
174+
175+
}
154176
parseTrace(traceNode);
155177
} else if (CTFParser.tokenNames[CTFParser.STREAM].equals(type) || JsonMetadataStrings.FRAGMENT_DATA_STREAM.equals(type)) {
156178
StreamParser.INSTANCE.parse(child, new StreamParser.Param(fTrace, fRoot));

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/metadata/JsonTraceMetadataNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
import org.eclipse.tracecompass.ctf.core.CTFException;
1717
import org.eclipse.tracecompass.internal.ctf.core.event.types.ICTFMetadataNode;
18-
import org.json.JSONObject;
1918

19+
import com.google.gson.JsonObject;
2020
import com.google.gson.annotations.SerializedName;
2121

2222
/**
@@ -30,7 +30,7 @@ public class JsonTraceMetadataNode extends CTFJsonMetadataNode {
3030
@SerializedName("uid")
3131
private String fUid;
3232
@SerializedName("environment")
33-
private JSONObject fEnvironment;
33+
private JsonObject fEnvironment;
3434
@SerializedName("packet-header-field-class")
3535
private JsonStructureFieldMetadataNode fPacketHeader;
3636

@@ -62,7 +62,7 @@ public String getUid() {
6262
*
6363
* @return the environment
6464
*/
65-
public JSONObject getEnvironment() {
65+
public JsonObject getEnvironment() {
6666
return fEnvironment;
6767
}
6868

0 commit comments

Comments
 (0)