Skip to content
Draft
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
Qualcomm AI Engine Direct - Enable QNN log to logcat.
Summary:
- Modify the existing tag to indicate qnn compiler plugin's log and qnn
  log.
  • Loading branch information
graham0824 committed Mar 16, 2026
commit 9c9bdfae6ed2bd7857bf756866aff5e525052bfe
4 changes: 4 additions & 0 deletions litert/vendors/qualcomm/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ cc_library(
name = "common",
srcs = ["common.cc"],
hdrs = ["common.h"],
linkopts = select({
"@org_tensorflow//tensorflow:android": ["-llog"],
"//conditions:default": [],
}),
deps = [
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
Expand Down
31 changes: 31 additions & 0 deletions litert/vendors/qualcomm/core/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,34 @@
#include <string>
#include <vector>

#if defined(__ANDROID__)
#include <android/log.h>
#endif // defined(__ANDROID__)

#include "absl/strings/str_format.h" // from @com_google_absl
#include "absl/strings/str_join.h" // from @com_google_absl
#include "absl/strings/string_view.h" // from @com_google_absl

namespace qnn {
namespace {

#if defined(__ANDROID__)
int GetAndroidLogPriority(QnnLog_Level_t level) {
switch (level) {
case QNN_LOG_LEVEL_ERROR:
return ANDROID_LOG_ERROR;
case QNN_LOG_LEVEL_WARN:
return ANDROID_LOG_WARN;
case QNN_LOG_LEVEL_INFO:
return ANDROID_LOG_INFO;
case QNN_LOG_LEVEL_VERBOSE:
return ANDROID_LOG_VERBOSE;
default:
return ANDROID_LOG_DEBUG;
}
}
#endif // defined(__ANDROID__)

void DefaultStdOutLogger(const char* fmt, QnnLog_Level_t level,
uint64_t timestamp, va_list argp) {
const char* levelStr = "";
Expand All @@ -39,6 +60,16 @@ void DefaultStdOutLogger(const char* fmt, QnnLog_Level_t level,
levelStr = "UNKNOWN";
break;
}

#if defined(__ANDROID__)
// Log to Android logcat.
va_list argp_copy;
va_copy(argp_copy, argp);
__android_log_vprint(GetAndroidLogPriority(level), "qnn", fmt, argp_copy);
va_end(argp_copy);
#endif // defined(__ANDROID__)

// Also print to stdout for console output.
char buffer1[256];
char buffer2[256];
double ms = timestamp;
Expand Down
2 changes: 1 addition & 1 deletion litert/vendors/qualcomm/core/utils/log_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void QNNLogger::Log(::qnn::LogLevel severity, const char* format, ...) {
// First log to Android's explicit log(cat) API.
va_list args_copy;
va_copy(args_copy, args);
__android_log_vprint(GetPlatformSeverity(severity), "qnn", format, args_copy);
__android_log_vprint(GetPlatformSeverity(severity), "lrt-qc", format, args_copy);
va_end(args_copy);

// Print to file pointer.
Expand Down