From 583ffc81774a073f7064bea44559b3fba2c5b178 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 9 May 2023 19:14:08 -0700 Subject: [PATCH] Reduce cpp logging overhead --- native/src/base/lib.rs | 2 +- native/src/base/logging.cpp | 2 +- native/src/base/logging.rs | 4 ++-- native/src/core/logging.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/native/src/base/lib.rs b/native/src/base/lib.rs index a1ddc7cc8..71d48c896 100644 --- a/native/src/base/lib.rs +++ b/native/src/base/lib.rs @@ -25,7 +25,7 @@ pub mod ffi { } extern "Rust" { - fn log_with_rs(level: LogLevel, msg: &str); + fn log_with_rs(level: LogLevel, msg: &[u8]); fn exit_on_error(b: bool); fn set_log_level_state(level: LogLevel, enabled: bool); fn cmdline_logging(); diff --git a/native/src/base/logging.cpp b/native/src/base/logging.cpp index 325554e66..11fb93cd9 100644 --- a/native/src/base/logging.cpp +++ b/native/src/base/logging.cpp @@ -14,7 +14,7 @@ using namespace std; static int fmt_and_log_with_rs(LogLevel level, const char *fmt, va_list ap) { char buf[4096]; int ret = vssprintf(buf, sizeof(buf), fmt, ap); - log_with_rs(level, rust::Str(buf, ret)); + log_with_rs(level, rust::Slice(reinterpret_cast(buf), ret)); return ret; } diff --git a/native/src/base/logging.rs b/native/src/base/logging.rs index eb04880b7..4175f4b2a 100644 --- a/native/src/base/logging.rs +++ b/native/src/base/logging.rs @@ -62,12 +62,12 @@ pub fn set_log_level_state(level: LogLevel, enabled: bool) { } } -pub fn log_with_rs(level: LogLevel, msg: &str) { +pub fn log_with_rs(level: LogLevel, msg: &[u8]) { let logger = unsafe { LOGGER }; if (logger.flags & level.to_disable_flag()) != 0 { return; } - (logger.write)(level, msg.as_bytes()); + (logger.write)(level, msg); if level == LogLevel::Error && (logger.flags & LogFlag::ExitOnError) != 0 { exit(1); } diff --git a/native/src/core/logging.rs b/native/src/core/logging.rs index 8b5a092af..eba12fffd 100644 --- a/native/src/core/logging.rs +++ b/native/src/core/logging.rs @@ -219,7 +219,7 @@ fn zygisk_log_write(prio: i32, msg: &[u8]) { // Consume SIGPIPE if exists, then restore mask unsafe { - let mut ts: timespec = std::mem::zeroed(); + let ts: timespec = std::mem::zeroed(); sigtimedwait(&mask, null_mut(), &ts); pthread_sigmask(SIG_SETMASK, &orig_mask, null_mut()); }