Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class ExecutorchRuntimeException extends RuntimeException {
}

static class ErrorHelper {
private static final boolean ENABLE_READ_LOG_BUFFER = false;
private static final boolean ENABLE_READ_LOG_BUFFER_LOGS = true;
// Reusable StringBuilder instance
private static final StringBuilder sb = new StringBuilder();

Expand All @@ -94,10 +94,12 @@ static String formatMessage(int errorCode, String details) {
.append(baseMessage)
.append(": ")
.append(details);
if (ENABLE_READ_LOG_BUFFER) {
if (ENABLE_READ_LOG_BUFFER_LOGS) {
try {
sb.append("\nDetailed Logs:\n");
String[] logEntries = readLogBuffer(); // JNI call
String[] logEntries = Module.readLogBufferStatic(); // JNI call
if (logEntries != null && logEntries.length > 0) {
sb.append("\n Detailed logs:\n");
}
formatLogEntries(sb, logEntries);
} catch (Exception e) {
sb.append("Failed to retrieve detailed logs: ").append(e.getMessage());
Expand All @@ -108,9 +110,6 @@ static String formatMessage(int errorCode, String details) {
}
}

// Native JNI method declaration
private static native String[] readLogBuffer();

// Append log entries to the provided StringBuilder
private static void formatLogEntries(StringBuilder sb, String[] logEntries) {
if (logEntries == null || logEntries.length == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ public MethodMetadata getMethodMetadata(String name) {
return mMethodMetadata.get(name);
}

@DoNotStrip
private static native String[] readLogBufferStaticNative();

public static String[] readLogBufferStatic() {
return readLogBufferStaticNative();
}

/** Retrieve the in-memory log buffer, containing the most recent ExecuTorch log entries. */
public String[] readLogBuffer() {
return readLogBufferNative();
Expand Down
12 changes: 12 additions & 0 deletions extension/android/jni/jni_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,16 @@ class ExecuTorchJni : public facebook::jni::HybridClass<ExecuTorchJni> {

facebook::jni::local_ref<facebook::jni::JArrayClass<jstring>>
readLogBuffer() {
return readLogBufferUtil();
}

static facebook::jni::local_ref<facebook::jni::JArrayClass<jstring>>
readLogBufferStatic(facebook::jni::alias_ref<jclass>) {
return readLogBufferUtil();
}

static facebook::jni::local_ref<facebook::jni::JArrayClass<jstring>>
readLogBufferUtil() {
#ifdef __ANDROID__

facebook::jni::local_ref<facebook::jni::JArrayClass<jstring>> ret;
Expand Down Expand Up @@ -500,6 +510,8 @@ class ExecuTorchJni : public facebook::jni::HybridClass<ExecuTorchJni> {
makeNativeMethod("executeNative", ExecuTorchJni::execute),
makeNativeMethod("loadMethodNative", ExecuTorchJni::load_method),
makeNativeMethod("readLogBufferNative", ExecuTorchJni::readLogBuffer),
makeNativeMethod(
"readLogBufferStaticNative", ExecuTorchJni::readLogBufferStatic),
makeNativeMethod("etdump", ExecuTorchJni::etdump),
makeNativeMethod("getMethods", ExecuTorchJni::getMethods),
makeNativeMethod("getUsedBackends", ExecuTorchJni::getUsedBackends),
Expand Down
Loading