Skip to content

Commit 23f35c9

Browse files
committed
lttng: Make text metadata detection more lenient
Text CTF metadata files are supposed to start with "/* CTF " followed by the CTF version. https://diamon.org/ctf/v1.8.3/#spec7.1 However, to workaround traces that doen't comply with specification is complied with then check for some common metadata keywords at the beginning of the metadata file. This will allow to open such traces with Trace Compass. fixes #298 Signed-off-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
1 parent a55a408 commit 23f35c9

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/Metadata.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonFieldClassAliasMetadataNode;
6464
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonPreambleMetadataNode;
6565
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonTraceMetadataNode;
66+
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.MetadataStrings;
6667
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.ParseException;
6768
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.trace.TraceDeclarationParser;
6869
import org.eclipse.tracecompass.internal.ctf.core.event.types.ICTFMetadataNode;
@@ -90,6 +91,9 @@ public class Metadata {
9091

9192
private static final String TEXT_ONLY_METADATA_HEADER_PREFIX = "/* CTF"; //$NON-NLS-1$
9293

94+
private static final List<String> TEXT_ONLY_METADATA_HEADER_PREFIXES = List.of(TEXT_ONLY_METADATA_HEADER_PREFIX,
95+
MetadataStrings.TYPE_ALIAS, MetadataStrings.TRACE, MetadataStrings.ENV);
96+
9397
private static final int PREVALIDATION_SIZE = 8;
9498

9599
private static final int BITS_PER_BYTE = Byte.SIZE;
@@ -349,7 +353,7 @@ public static boolean preValidate(String path) throws CTFException {
349353
}
350354
try (BufferedReader br = new BufferedReader(new FileReader(metadataFile))) {
351355
String text = br.readLine();
352-
return text.startsWith(TEXT_ONLY_METADATA_HEADER_PREFIX);
356+
return TEXT_ONLY_METADATA_HEADER_PREFIXES.stream().anyMatch(text::startsWith);
353357
} catch (IOException e) {
354358
throw new CTFException(e.getMessage(), e);
355359
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,9 @@ public interface MetadataStrings {
128128
String VARIANT = "variant";
129129
/** enum */
130130
String ENUM = "enum";
131+
/** typealias */
132+
String TYPE_ALIAS = "typealias";
133+
/** env */
134+
String ENV = "env";
131135

132136
}

0 commit comments

Comments
 (0)