Skip to content
Snippets Groups Projects
Commit b29c6ae8 authored by Mick Jordan's avatar Mick Jordan
Browse files

Guard calls to RFFIUtils.trace.

parent cf507181
Branches
No related tags found
No related merge requests found
...@@ -32,28 +32,22 @@ import com.oracle.truffle.r.runtime.data.RPairList; ...@@ -32,28 +32,22 @@ import com.oracle.truffle.r.runtime.data.RPairList;
import com.oracle.truffle.r.runtime.data.RSymbol; import com.oracle.truffle.r.runtime.data.RSymbol;
import com.oracle.truffle.r.runtime.data.RTypedValue; import com.oracle.truffle.r.runtime.data.RTypedValue;
/**
* Mostly support for tracing R FFI up/down calls. Currently tracing of the arguments to calls is
* limited. The type of the argument is printed as is the value for types with simple (short)
* values. Potentially complex types, e.g, {@link RPairList} do not have their values printed.
*
*/
public class RFFIUtils { public class RFFIUtils {
private static boolean initialized;
/** /**
* Set this to {@code true} when it is not possible to set {@link FastROptions}. * Set this to {@code true} when it is not possible to set {@link FastROptions}.
*/ */
private static boolean alwaysTrace; private static boolean alwaysTrace;
/**
public static byte[] wrapChar(char v) { * Is set by initialization and caches whether we are tracing.
return new byte[]{(byte) v}; */
} private static boolean traceEnabled;
public static int[] wrapInt(int v) {
return new int[]{v};
}
public static double[] wrapDouble(double v) {
return new double[]{v};
}
@TruffleBoundary
public static IOException ioex(String errMsg) throws IOException {
throw new IOException(errMsg);
}
/** /**
* Places in /tmp because in embedded mode can't trust that cwd is writeable. Also, tag with * Places in /tmp because in embedded mode can't trust that cwd is writeable. Also, tag with
...@@ -63,14 +57,20 @@ public class RFFIUtils { ...@@ -63,14 +57,20 @@ public class RFFIUtils {
private static PrintWriter traceWriter; private static PrintWriter traceWriter;
private static void initialize() { private static void initialize() {
if (traceWriter == null) { if (!initialized) {
String tracePath = tracePathPrefix + Long.toString(System.currentTimeMillis()); traceEnabled = alwaysTrace || FastROptions.TraceNativeCalls.getBooleanValue();
try { if (traceEnabled) {
traceWriter = new PrintWriter(new FileWriter(tracePath)); if (traceWriter == null) {
} catch (IOException ex) { String tracePath = tracePathPrefix + Long.toString(System.currentTimeMillis());
System.err.println(ex.getMessage()); try {
System.exit(1); traceWriter = new PrintWriter(new FileWriter(tracePath));
} catch (IOException ex) {
System.err.println(ex.getMessage());
System.exit(1);
}
}
} }
initialized = true;
} }
} }
...@@ -99,9 +99,13 @@ public class RFFIUtils { ...@@ -99,9 +99,13 @@ public class RFFIUtils {
traceCall(CallMode.DOWN, name, args); traceCall(CallMode.DOWN, name, args);
} }
public static boolean traceEnabled() {
return traceEnabled;
}
private static void traceCall(CallMode mode, String name, Object... args) { private static void traceCall(CallMode mode, String name, Object... args) {
if (alwaysTrace || FastROptions.TraceNativeCalls.getBooleanValue()) { initialize();
initialize(); if (traceEnabled) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append("CallRFFI["); sb.append("CallRFFI[");
sb.append(mode.printName); sb.append(mode.printName);
...@@ -124,18 +128,33 @@ public class RFFIUtils { ...@@ -124,18 +128,33 @@ public class RFFIUtils {
sb.append(", "); sb.append(", ");
} }
sb.append(arg == null ? "" : arg.getClass().getSimpleName()); sb.append(arg == null ? "" : arg.getClass().getSimpleName());
if (arg instanceof RPairList) {
sb.append("[");
printArgs(sb, ((RPairList) arg).toRList().getDataCopy());
sb.append("]");
}
if (arg instanceof RSymbol) { if (arg instanceof RSymbol) {
RSymbol symbol = (RSymbol) arg; RSymbol symbol = (RSymbol) arg;
sb.append("\"" + symbol.getName() + "\")"); sb.append("(\"" + symbol.getName() + "\")");
} }
if (!(arg instanceof RTypedValue)) { if (!(arg instanceof RTypedValue)) {
sb.append("(" + arg + ")"); sb.append("(" + arg + ")");
} }
} }
} }
// Miscellaneous support functions
public static byte[] wrapChar(char v) {
return new byte[]{(byte) v};
}
public static int[] wrapInt(int v) {
return new int[]{v};
}
public static double[] wrapDouble(double v) {
return new double[]{v};
}
@TruffleBoundary
public static IOException ioex(String errMsg) throws IOException {
throw new IOException(errMsg);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment