LogEntry

Struct LogEntry 

Source
#[repr(C, align(8))]
pub struct LogEntry { seq: AtomicUsize, level: LogLevel, cpu_id: usize, length: usize, task_id: u32, timestamp: usize, message: [u8; 256], }
Expand description

带有元数据和消息的单个日志条目

该结构体经过精心布局,用于无锁同步:

  • seq 字段用作生产者和消费者之间的同步点
  • 带有 8 字节对齐的 C 表示形式确保了正确的原子访问
  • 字段顺序经过优化以最小化填充

Fields§

§seq: AtomicUsize

用于同步的序列号(必须是第一个字段)

§level: LogLevel

日志级别 (Emergency, Error, Info, 等)

§cpu_id: usize

生成此日志的 CPU ID

§length: usize

消息的实际长度(以字节为单位)

§task_id: u32

生成此日志的任务/进程 ID

§timestamp: usize

创建日志时的时间戳

§message: [u8; 256]

用于日志消息的固定大小缓冲区

Implementations§

Source§

impl LogEntry

Source

pub const fn empty() -> Self

创建一个空的日志条目(用于初始化)

这是一个 const fn,因此可以在编译时进行评估, 允许对全局缓冲区进行常数初始化。

Source

pub(super) fn from_args( level: LogLevel, cpu_id: usize, task_id: u32, timestamp: usize, args: Arguments<'_>, ) -> Self

从格式化参数创建日志条目

§参数
  • level - 日志级别
  • cpu_id - 生成日志的 CPU ID
  • task_id - 生成日志的任务 ID
  • timestamp - 日志的时间戳
  • args - 来自 format_args! 宏的格式化参数
Source

pub fn message(&self) -> &str

将日志消息作为字符串切片返回

Source

pub fn level(&self) -> LogLevel

返回日志级别

Source

pub fn cpu_id(&self) -> usize

返回生成此日志的 CPU ID

Source

pub fn task_id(&self) -> u32

返回生成此日志的任务 ID

Source

pub fn timestamp(&self) -> usize

返回此日志的时间戳

Source§

impl LogEntry

Source

pub(super) unsafe fn copy_data_to(&self, dest: *mut LogEntry)

将日志数据复制到缓冲区槽中(供内部使用)

复制除 seq 字段外的所有字段,seq 字段必须 通过 publish() 单独设置,以确保正确的内存顺序。

§安全性

dest 必须指向环形缓冲区中有效的 LogEntry

Source

pub(super) unsafe fn publish(&self, dest: *mut LogEntry, seq_num: usize)

通过设置其序列号来发布条目(供内部使用)

使用 Release 内存顺序,以确保在序列号更新之前, 所有数据写入对其他核心都是可见的。

§安全性

dest 必须指向环形缓冲区中有效的 LogEntry

Source

pub(super) unsafe fn is_ready( &self, slot_ptr: *const LogEntry, expected_seq: usize, ) -> bool

检查槽是否已准备好读取(供内部使用)

使用 Acquire 内存顺序与生产者在 publish() 中的 Release 存储配对, 确保正确的同步。

§安全性

slot_ptr 必须指向环形缓冲区中有效的 LogEntry

Trait Implementations§

Source§

impl Clone for LogEntry

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LogEntry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for LogEntry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for LogEntry

§

impl RefUnwindSafe for LogEntry

§

impl Send for LogEntry

§

impl Sync for LogEntry

§

impl Unpin for LogEntry

§

impl UnwindSafe for LogEntry

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.