diff --git a/bundle.json b/bundle.json index 4a72b1644127ea90e6f54f6323817444611ce537..b526241514401b0c1cfb8e274446e5ee8be2a679 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 0cab989b44e5f4c18d4775e14af395dff1ef4010..5a6e767f15bedfd612ba527edb95d9362a4b8d8d 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 08c7b68f4d4fd248b53875abc6fa69be4c376fd8..7b05ec1b19d471629ffddd2db0f787ee4c3f0123 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 9e25aaed690c1d76fdaecb9de5ade1623da6bed3..8497054ac5453f8c4f7893c916e89433a7795fea 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 ce6573109ce836d39519514edb459821bccd46dd..bba4ef3591d97b422cdc37623b491841cae84ff6 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 000f9962f652ef01f8a013f91d7ebb9d6ced01fd..5f88b3049fbf3b490d66ade20f30b1309c1ce92d 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 eb12d70cb6b395a787b36368dec3f7e23f20a8dd..b3fa13ad7ef0884d909d40938f7f9e3151198213 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 b3dfd1992a153d728a534b0ec800a7ac0a3bb944..0ba22f0d772f6a333f601eee86db289d194e6004 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 5cef03982430c8d4ad2e60fd3bf5563535bd9840..6add7978086e0787f503adfbab1145feef5d5867 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 ec09bdbe12ef61975741da4518499da21435fbbb..2d3d06c04ce819cbdaa8fca98f79579d62f80da8 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)