Skip to content
Open
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 @@ -227,6 +227,28 @@ public String[] readLogBuffer() {
@DoNotStrip
public native boolean etdump();

/**
* Dump the ExecuTorch ETDump file to {@code outputPath}.
*
* @param outputPath absolute path to write the etdump file to.
* @return true if the etdump was successfully written, false otherwise.
*/
@Experimental
public boolean etdump(String outputPath) {
mLock.lock();
try {
if (!mHybridData.isValid()) {
throw new IllegalStateException("Module has been destroyed");
}
return etdumpToNative(outputPath);
} finally {
mLock.unlock();
}
}

@DoNotStrip
private native boolean etdumpToNative(String outputPath);

/**
* Explicitly destroys the native Module object. Calling this method is not required, as the
* native object will be destroyed when this object is garbage-collected. However, the timing of
Expand Down
74 changes: 48 additions & 26 deletions extension/android/jni/jni_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,34 +466,15 @@ class ExecuTorchJni : public facebook::jni::HybridClass<ExecuTorchJni> {
}

jboolean etdump() {
#ifdef EXECUTORCH_ANDROID_PROFILING
executorch::etdump::ETDumpGen* etdumpgen =
(executorch::etdump::ETDumpGen*)module_->event_tracer();
auto etdump_data = etdumpgen->get_etdump_data();
return etdump_to_path("/data/local/tmp/result.etdump");
}

if (etdump_data.buf != nullptr && etdump_data.size > 0) {
int etdump_file =
open("/data/local/tmp/result.etdump", O_WRONLY | O_CREAT, 0644);
if (etdump_file == -1) {
ET_LOG(Error, "Cannot create result.etdump error: %d", errno);
return false;
}
ssize_t bytes_written =
write(etdump_file, (uint8_t*)etdump_data.buf, etdump_data.size);
if (bytes_written == -1) {
ET_LOG(Error, "Cannot write result.etdump error: %d", errno);
return false;
} else {
ET_LOG(Info, "ETDump written %d bytes to file.", bytes_written);
}
close(etdump_file);
free(etdump_data.buf);
return true;
} else {
ET_LOG(Error, "No ETDump data available!");
jboolean etdumpTo(facebook::jni::alias_ref<jstring> outputPath) {
if (!outputPath) {
ET_LOG(Error, "etdumpTo called with null outputPath");
return false;
}
#endif
return false;
return etdump_to_path(outputPath->toStdString().c_str());
}

facebook::jni::local_ref<facebook::jni::JArrayClass<jstring>> getMethods() {
Expand Down Expand Up @@ -565,10 +546,51 @@ class ExecuTorchJni : public facebook::jni::HybridClass<ExecuTorchJni> {
makeNativeMethod(
"readLogBufferStaticNative", ExecuTorchJni::readLogBufferStatic),
makeNativeMethod("etdump", ExecuTorchJni::etdump),
makeNativeMethod("etdumpToNative", ExecuTorchJni::etdumpTo),
makeNativeMethod("getMethods", ExecuTorchJni::getMethods),
makeNativeMethod("getUsedBackends", ExecuTorchJni::getUsedBackends),
});
}

private:
jboolean etdump_to_path(const char* path) {
#ifdef EXECUTORCH_ANDROID_PROFILING
auto* tracer = module_->event_tracer();
if (!tracer) {
ET_LOG(Error, "ETDump not available: no event tracer attached");
return false;
}
auto* etdumpgen = static_cast<executorch::etdump::ETDumpGen*>(tracer);
auto etdump_data = etdumpgen->get_etdump_data();

if (etdump_data.buf != nullptr && etdump_data.size > 0) {
int etdump_file = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (etdump_file == -1) {
ET_LOG(Error, "Cannot create %s error: %d", path, errno);
free(etdump_data.buf);
return false;
}
ssize_t bytes_written =
write(etdump_file, (uint8_t*)etdump_data.buf, etdump_data.size);
if (bytes_written == -1) {
ET_LOG(Error, "Cannot write %s error: %d", path, errno);
close(etdump_file);
free(etdump_data.buf);
return false;
} else {
ET_LOG(Info, "ETDump written %zd bytes to %s.", bytes_written, path);
}
close(etdump_file);
free(etdump_data.buf);
return true;
} else {
ET_LOG(Error, "No ETDump data available!");
}
#else
(void)path;
#endif
return false;
}
};
} // namespace executorch::extension

Expand Down
3 changes: 3 additions & 0 deletions scripts/build_android_library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ build_android_native_library() {

cmake . -DCMAKE_INSTALL_PREFIX="${CMAKE_OUT}" \
-DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \
-DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" \
--preset "android-${ANDROID_ABI}" \
-DANDROID_PLATFORM=android-26 \
-DEXECUTORCH_ENABLE_EVENT_TRACER="${EXECUTORCH_ANDROID_PROFILING:-OFF}" \
-DEXECUTORCH_ANDROID_PROFILING="${EXECUTORCH_ANDROID_PROFILING:-OFF}" \
-DEXECUTORCH_BUILD_EXTENSION_LLM="${EXECUTORCH_BUILD_EXTENSION_LLM:-ON}" \
-DEXECUTORCH_BUILD_EXTENSION_LLM_RUNNER="${EXECUTORCH_BUILD_EXTENSION_LLM:-ON}" \
-DEXECUTORCH_BUILD_EXTENSION_ASR_RUNNER="${EXECUTORCH_BUILD_EXTENSION_LLM:-ON}" \
Expand All @@ -51,6 +53,7 @@ build_android_native_library() {
-DQNN_SDK_ROOT="${QNN_SDK_ROOT}" \
-DEXECUTORCH_BUILD_VULKAN="${EXECUTORCH_BUILD_VULKAN}" \
-DXNNPACK_ENABLE_ARM_SME2="${XNNPACK_ENABLE_ARM_SME2}" \
-DFLATCC_ALLOW_WERROR=OFF \
-DSUPPORT_REGEX_LOOKAHEAD=ON \
-DCMAKE_BUILD_TYPE="${EXECUTORCH_CMAKE_BUILD_TYPE}" \
-B"${CMAKE_OUT}"
Expand Down
1 change: 1 addition & 0 deletions third-party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ ExternalProject_Add(
-DFLATCC_TEST=OFF
-DFLATCC_REFLECTION=OFF
-DFLATCC_DEBUG_CLANG_SANITIZE=OFF
-DFLATCC_ALLOW_WERROR=OFF
-DFLATCC_INSTALL=ON
-DCMAKE_POLICY_VERSION_MINIMUM=3.5
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
Expand Down
4 changes: 2 additions & 2 deletions tools/cmake/common/preset.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ macro(define_overridable_option NAME DESCRIPTION VALUE_TYPE DEFAULT_VALUE)
if(DEFINED ${NAME} AND NOT DEFINED CACHE{${NAME}})
set(${NAME}
${${NAME}}
CACHE ${VALUE_TYPE} ${DESCRIPTION} FORCE
CACHE ${VALUE_TYPE} "${DESCRIPTION}" FORCE
)
else()
set(${NAME}
${DEFAULT_VALUE}
CACHE ${VALUE_TYPE} ${DESCRIPTION}
CACHE ${VALUE_TYPE} "${DESCRIPTION}"
)
endif()

Expand Down
Loading