Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Khouzam2018-04-14 11:51:52 -0400
committerMatthew Khouzam2018-07-09 10:30:46 -0400
commit24b54650e750cf8d03b48f48a3ca53ca4720f17c (patch)
tree108390f24823516848d3a75963b57c5df9946f25
parent3e95806c6b3d6dcefbad4dad6a4b2c339796a93c (diff)
downloadorg.eclipse.tracecompass.incubator-24b54650e750cf8d03b48f48a3ca53ca4720f17c.tar.gz
org.eclipse.tracecompass.incubator-24b54650e750cf8d03b48f48a3ca53ca4720f17c.tar.xz
org.eclipse.tracecompass.incubator-24b54650e750cf8d03b48f48a3ca53ca4720f17c.zip
ftrace: improve error messages
Handle trace-cmd.dat and fix a c-p error. Change-Id: I675c2b97b624f5bccb1f692895668472032a04ea Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com> Reviewed-on: https://git.eclipse.org/r/121175 Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net> Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net> Tested-by: CI Bot
-rw-r--r--tracetypes/org.eclipse.tracecompass.incubator.ftrace.core/src/org/eclipse/tracecompass/incubator/internal/ftrace/core/trace/FtraceTrace.java23
1 files changed, 19 insertions, 4 deletions
diff --git a/tracetypes/org.eclipse.tracecompass.incubator.ftrace.core/src/org/eclipse/tracecompass/incubator/internal/ftrace/core/trace/FtraceTrace.java b/tracetypes/org.eclipse.tracecompass.incubator.ftrace.core/src/org/eclipse/tracecompass/incubator/internal/ftrace/core/trace/FtraceTrace.java
index b77c211d..2a0319e9 100644
--- a/tracetypes/org.eclipse.tracecompass.incubator.ftrace.core/src/org/eclipse/tracecompass/incubator/internal/ftrace/core/trace/FtraceTrace.java
+++ b/tracetypes/org.eclipse.tracecompass.incubator.ftrace.core/src/org/eclipse/tracecompass/incubator/internal/ftrace/core/trace/FtraceTrace.java
@@ -9,6 +9,11 @@
package org.eclipse.tracecompass.incubator.internal.ftrace.core.trace;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -18,9 +23,6 @@ import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
-import java.io.File;
-import java.io.IOException;
-
/**
* Ftrace trace.
*
@@ -35,6 +37,8 @@ public class FtraceTrace extends GenericFtrace {
private static final int MAX_LINES = 100;
private static final int MAX_CONFIDENCE = 100;
+ private static final byte[] TRACE_CMD_DAT_MAGIC = {0x17, 0x08, 0x44, 't', 'r','a','c','i','n','g'};
+
@Override
public IStatus validate(IProject project, String path) {
File file = new File(path);
@@ -47,6 +51,17 @@ public class FtraceTrace extends GenericFtrace {
int confidence = 0;
try {
if (!TmfTraceUtils.isText(file)) {
+ int magicLength = TRACE_CMD_DAT_MAGIC.length;
+ if (file.length() > magicLength) {
+ try (FileInputStream fis = new FileInputStream(file)) {
+ byte[] start = new byte[magicLength];
+ int read = fis.read(start);
+ if (read == magicLength && Arrays.equals(TRACE_CMD_DAT_MAGIC, start)) {
+ // TODO: offer to do this programatically
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "This file looks like a binary trace-cmd, try running 'trace-cmd report -R' on it."); //$NON-NLS-1$
+ }
+ }
+ }
return new TraceValidationStatus(confidence, Activator.PLUGIN_ID);
}
} catch (IOException e) {
@@ -71,7 +86,7 @@ public class FtraceTrace extends GenericFtrace {
line = rafile.readLine();
}
if (matches == 0) {
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Most assuredly NOT a traceevent trace"); //$NON-NLS-1$
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Most assuredly NOT an fTrace text trace"); //$NON-NLS-1$
}
} catch (IOException e) {
Activator.getInstance().logError("Error validating file: " + path, e); //$NON-NLS-1$

Back to the top