Skip to main content

Module devtools_trace

Module devtools_trace 

Source
Expand description

Devtools 环形缓冲基础设施:push / peek / clear / enabled 开关 / 共享单调时钟。

设计原则(三处 trace 共享同一套纪律):

  • 默认关闭,关闭时 push 立即返回,不拿锁、不分配、不拷贝
  • 环形缓冲,满时挤最旧,始终保留最近 N 条
  • peek(max) 只读不 drain,devtools 面板每 250ms 调一次
  • 线程安全(std::sync::Mutex)——单 UI 线程场景下无竞争 ≈ RefCell
  • 共享单调时钟(LazyLock<Instant> 锚点跨所有 trace 可比较)

使用:

ⓘ
// 1. struct 上(EventLog 风格)
pub struct EventLog { inner: DevtoolsTrace<EventRecord> }

// 2. thread_local 全局(SignalTrace / FrameTimeline 风格)
thread_local! {
    static SIG_TRACE: DevtoolsTrace<SignalTraceEntry> = DevtoolsTrace::new(256);
}
pub fn push(entry: SignalTraceEntry) { SIG_TRACE.with(|t| t.push(entry)); }

Structs§

DevtoolsTrace
Devtools 环形缓冲:零开销开关 + 容量淘汰 + 线程安全。

Functions§

now_ms
进程启动锚点(EventLog / SignalTrace / FrameTimeline 共用同一个)。