yingjie@memoir
Skip to content

2026-04-06

赛事

uftrace LoongClaw

uftrace -d trace.data -P . ./target/uftrace/loongclaw

# DURATION     TID      FUNCTION
   0.568 us [ 251903] | __gmon_start__();
            [ 251903] | aws_lc_0_39_1_OPENSSL_cpuid_setup() {
   1.132 us [ 251903] |   OPENSSL_cpuid();
   0.810 us [ 251903] |   OPENSSL_cpuid();
   0.495 us [ 251903] |   OPENSSL_cpuid();
   0.164 us [ 251903] |   OPENSSL_xgetbv();
   0.122 us [ 251903] |   os_supports_avx512();
   2.390 us [ 251903] |   getenv();
  19.691 us [ 251903] | } /* aws_lc_0_39_1_OPENSSL_cpuid_setup */
            [ 251903] | main() {
            [ 251903] |   std::rt::lang_start() {
            [ 251903] |     std::rt::lang_start_internal() {
   4.648 us [ 251903] |       std::sys::pal::unix::stack_overflow::imp::make_handler();
            [ 251903] |       std::sys::pal::unix::stack_overflow::thread_info::set_current_info() {
   0.699 us [ 251903] |         _RNvCsdBezzDwma51_7___rustc35___rust_no_alloc_shim_is_unstable_v2();
            [ 251903] |         _RNvCsdBezzDwma51_7___rustc12___rust_alloc() {
   1.147 us [ 251903] |           _RNvCsdBezzDwma51_7___rustc11___rdl_alloc();
   1.768 us [ 251903] |         } /* _RNvCsdBezzDwma51_7___rustc12___rust_alloc */
   0.082 us [ 251903] |         _RNvCsdBezzDwma51_7___rustc35___rust_no_alloc_shim_is_unstable_v2();
            [ 251903] |         _RNvCsdBezzDwma51_7___rustc12___rust_alloc() {
   0.124 us [ 251903] |           _RNvCsdBezzDwma51_7___rustc11___rdl_alloc();
   0.257 us [ 251903] |         } /* _RNvCsdBezzDwma51_7___rustc12___rust_alloc */
   4.812 us [ 251903] |       } /* std::sys::pal::unix::stack_overflow::thread_info::set_current_info */
            [ 251903] |       std::rt::lang_start::_{{closure}}() {
            [ 251903] |         std::sys::backtrace::__rust_begin_short_backtrace() {
            [ 251903] |           core::ops::function::FnOnce::call_once() {
            [ 251903] |             loongclaw::main() {
            [ 251903] |               tokio::runtime::builder::Builder::new_multi_thread() {
            [ 251903] |                 tokio::runtime::builder::Builder::new() {
            [ 251903] |                   alloc::sync::Arc<T>::new() {
            [ 251903] |                     alloc::alloc::exchange_malloc() {
            [ 251903] |                       alloc::alloc::Global::alloc_impl() {
   0.102 us [ 251903] |                         _RNvCsdBezzDwma51_7___rustc35___rust_no_alloc_shim_is_unstable_v2();
            [ 251903] |                         _RNvCsdBezzDwma51_7___rustc12___rust_alloc() {
   0.122 us [ 251903] |                           _RNvCsdBezzDwma51_7___rustc11___rdl_alloc();
   0.246 us [ 251903] |                         } /* _RNvCsdBezzDwma51_7___rustc12___rust_alloc */
   0.814 us [ 251903] |                       } /* alloc::alloc::Global::alloc_impl */
   1.293 us [ 251903] |                     } /* alloc::alloc::exchange_malloc */
   2.334 us [ 251903] |                   } /* alloc::sync::Arc<T>::new */
            [ 251903] |                   tokio::loom::std::rand::seed() {
            [ 251903] |                     std::hash::random::RandomState::new() {
            [ 251903] |                       std::thread::local::LocalKey<T>::with() {
:

uftrace -d trace.data.match -P "*loongclaw*" ./target/uftrace/loongclaw chat 明显比上一个加载的速度快,更短时间进入loongclaw程序

目前的进展是可以展示LoongClaw运行中调用了哪些函数,下一步是对其进行过滤,只保留此项目中的函数。

bash
 uftrace record -P . -F 'loongclaw::*' --srcline --depth 3 --no-sched --no-event ./target/uftrace/loongclaw chat

可以通过 --hide来不显示某些库的调用,但我感觉应该有方法做到只展示本项目的内容。

bash
 # 只跟踪 loongclaw:: 开头的函数,深度设为1只看顶层
                                     uftrace record -P . -F 'loongclaw::.*' --depth 1 --srcline --no-sched --no-event ./target/uftrace/loongclaw chat
LOONGCLAW  v0.1.0-alpha.3 · dev · 6c09d14
interactive chat

目前在使用uftrace的时候还是遇到些问题,要么记录里有很多第三方库的内容,要么就是不见项目自己的函数,反而是一堆core之类的内容。

确定参数

想了一个方法,询问了几个不同的模型,完成这个需求需要哪些参数。 把参数记下来,去mannual手册里自己看一遍。

  • --srcline:显示函数对应的源代码行数,需要在record和replay中都启用才能看到
  • --no-libcall:不记录用户态共享库中的函数
  • -F/--filter:包含,接pattern
  • -N:不包含,接pattern
  • --match:指定pattern的类型regex或glob,默认regex
  • --depth:指定记录的深度
  • --no-event:通用事件,调度、页错误、系统调用、信号传递、进程退出等
  • --no-sched :调度事件,你的程序获得/失去CPU
  • -L/--location:使用路径来筛选