From 8ec0ac9a90ef5cd18937d908ab94ee428f83aba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=9C=AA=E6=9D=A5?= Date: Mon, 18 Sep 2023 11:18:44 +0800 Subject: [PATCH] =?UTF-8?q?hilog=E6=97=A5=E5=BF=97=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 徐未来 --- bundle.json | 2 +- ylong_io/BUILD.gn | 3 +++ ylong_io/src/lib.rs | 9 +++++++++ ylong_io/src/sys/linux/mod.rs | 4 +++- ylong_io/src/sys/windows/iocp.rs | 4 +++- ylong_io/src/sys/windows/mod.rs | 8 ++++++-- ylong_runtime/BUILD.gn | 3 +++ ylong_runtime/src/lib.rs | 9 +++++++++ ylong_runtime/src/sync/mutex.rs | 6 +++++- ylong_runtime/src/sync/rwlock.rs | 6 +++++- 10 files changed, 47 insertions(+), 7 deletions(-) diff --git a/bundle.json b/bundle.json index 4a72b16..b526241 100644 --- a/bundle.json +++ b/bundle.json @@ -25,7 +25,7 @@ "rom": "100KB", "ram": "~200KB", "deps": { - "components": [], + "components": ["hilog"], "third_party": [] }, "build": { diff --git a/ylong_io/BUILD.gn b/ylong_io/BUILD.gn index 0cab989..5a6e767 100644 --- a/ylong_io/BUILD.gn +++ b/ylong_io/BUILD.gn @@ -25,6 +25,9 @@ ohos_rust_static_library("ylong_io") { "udp", ] + external_deps = [ + "hilog:hilog_rust", + ] sources = [ "src/lib.rs" ] deps = [ "//third_party/rust/crates/libc:lib" ] } diff --git a/ylong_io/src/lib.rs b/ylong_io/src/lib.rs index 08c7b68..7b05ec1 100644 --- a/ylong_io/src/lib.rs +++ b/ylong_io/src/lib.rs @@ -13,6 +13,9 @@ //! Event-driven nonblocking net-io components. +extern crate hilog_rust; +use hilog_rust::*; + mod poll; pub use poll::Poll; @@ -37,3 +40,9 @@ pub use waker::Waker; #[cfg(not(any(feature = "tcp", feature = "udp")))] std::compile_error!("tcp and udp feature must be enabled one of them for this crate."); + +pub(crate) const LOG_LABEL: hilog_rust::HiLogLabel = hilog_rust::HiLogLabel { + log_type: hilog_rust::LogType::LogCore, + domain: 0xd003200, + tag: "ylong_io" +}; diff --git a/ylong_io/src/sys/linux/mod.rs b/ylong_io/src/sys/linux/mod.rs index 9e25aae..8497054 100644 --- a/ylong_io/src/sys/linux/mod.rs +++ b/ylong_io/src/sys/linux/mod.rs @@ -17,7 +17,9 @@ macro_rules! syscall { ($fn: ident ( $($arg: expr),* $(,)* ) ) => {{ let res = unsafe { libc::$fn($($arg, )*) }; if res == -1 { - Err(std::io::Error::last_os_error()) + let err = std::io::Error::last_os_error(); + hilog_rust::error!(crate::LOG_LABEL, "syscall: {} system call failed: {}.", stringify!($fn), err); + Err(err) } else { Ok(res) } diff --git a/ylong_io/src/sys/windows/iocp.rs b/ylong_io/src/sys/windows/iocp.rs index ce65731..bba4ef3 100644 --- a/ylong_io/src/sys/windows/iocp.rs +++ b/ylong_io/src/sys/windows/iocp.rs @@ -36,7 +36,9 @@ impl CompletionPort { pub(crate) fn new() -> io::Result { let handle = unsafe { CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0, 0) }; if handle == 0 { - Err(io::Error::last_os_error()) + let err = io::Error::last_os_error(); + hilog_rust::error!(crate::LOG_LABEL, "CreateIoCompletionPort system call failed: {}.", err); + Err(err) } else { Ok(CompletionPort { handle: Handle::new(handle), diff --git a/ylong_io/src/sys/windows/mod.rs b/ylong_io/src/sys/windows/mod.rs index 000f996..5f88b30 100644 --- a/ylong_io/src/sys/windows/mod.rs +++ b/ylong_io/src/sys/windows/mod.rs @@ -15,7 +15,9 @@ macro_rules! syscall { ($fn: ident ( $($arg: expr),* $(,)* ), $ret: expr) => {{ let res = unsafe { $fn($($arg, )*) }; if res == 0 { - Err(io::Error::last_os_error()) + let err = io::Error::last_os_error(); + hilog_rust::error!(crate::LOG_LABEL, "syscall: {} system call failed: {}.", stringify!($fn), err); + Err(err) } else { Ok($ret) } @@ -50,7 +52,9 @@ cfg_net! { ($fn: ident ( $($arg: expr),* $(,)* ), $err_fn: path, $err_val: expr) => {{ let res = unsafe { $fn($($arg, )*) }; if $err_fn(&res, &$err_val) { - Err(io::Error::last_os_error()) + let err = io::Error::last_os_error(); + hilog_rust::error!(crate::LOG_LABEL, "socket_syscall: {} system call failed: {}.", stringify!($fn), err); + Err(err) } else { Ok(res) } diff --git a/ylong_runtime/BUILD.gn b/ylong_runtime/BUILD.gn index eb12d70..b3fa13a 100644 --- a/ylong_runtime/BUILD.gn +++ b/ylong_runtime/BUILD.gn @@ -29,6 +29,9 @@ ohos_rust_shared_library("ylong_runtime") { "time", ] + external_deps = [ + "hilog:hilog_rust", + ] sources = [ "src/lib.rs" ] deps = [ "../ylong_io:ylong_io", diff --git a/ylong_runtime/src/lib.rs b/ylong_runtime/src/lib.rs index b3dfd19..0ba22f0 100644 --- a/ylong_runtime/src/lib.rs +++ b/ylong_runtime/src/lib.rs @@ -26,6 +26,9 @@ compile_error!("Feature ffrt only works on linux currently"); #[cfg(all(feature = "ffrt", feature = "metrics"))] compile_error!("Feature ffrt can not be enabled with feature metrics"); +extern crate hilog_rust; +use hilog_rust::*; + extern crate core; use std::future::Future; @@ -97,3 +100,9 @@ where let rt = executor::global_default_async(); rt.block_on(task) } + +pub(crate) const LOG_LABEL: hilog_rust::HiLogLabel = hilog_rust::HiLogLabel { + log_type: hilog_rust::LogType::LogCore, + domain: 0xd003200, + tag: "ylong_runtime" +}; diff --git a/ylong_runtime/src/sync/mutex.rs b/ylong_runtime/src/sync/mutex.rs index 5cef039..6add797 100644 --- a/ylong_runtime/src/sync/mutex.rs +++ b/ylong_runtime/src/sync/mutex.rs @@ -96,6 +96,7 @@ impl Mutex { // The result of `acquire()` will be `Err()` only when the semaphore is closed. // `Mutex` will not close, so the result of `acquire()` must be `Ok(())`. self.sem.acquire().await.unwrap(); + hilog_rust::debug!(crate::LOG_LABEL, "Mutex lock get."); MutexGuard(self) } @@ -121,7 +122,10 @@ impl Mutex { /// ``` pub fn try_lock(&self) -> Result, LockError> { match self.sem.try_acquire() { - Ok(_) => Ok(MutexGuard(self)), + Ok(_) => { + hilog_rust::debug!(crate::LOG_LABEL, "Mutex try_lock get."); + Ok(MutexGuard(self)) + }, Err(_) => Err(LockError), } } diff --git a/ylong_runtime/src/sync/rwlock.rs b/ylong_runtime/src/sync/rwlock.rs index ec09bdb..2d3d06c 100644 --- a/ylong_runtime/src/sync/rwlock.rs +++ b/ylong_runtime/src/sync/rwlock.rs @@ -183,6 +183,7 @@ impl RwLock { if read_count >= 0 && self.read_wait.fetch_add(read_count, Release) != -read_count { self.write_sem.acquire().await.unwrap(); } + hilog_rust::debug!(crate::LOG_LABEL, "Rwlock write get."); RwLockWriteGuard(self) } @@ -208,7 +209,10 @@ impl RwLock { .read_count .compare_exchange(0, -MAX_READS, AcqRel, Acquire) { - Ok(_) => Ok(RwLockWriteGuard(self)), + Ok(_) => { + hilog_rust::debug!(crate::LOG_LABEL, "Rwlock try_write get."); + Ok(RwLockWriteGuard(self)) + }, Err(_) => { self.write_mutex.release(); Err(LockError) -- Gitee