zenoh perf 火焰图使用简单说明

默认zenoh 的构建是release的进行了一些优化,但是有些时候我们希望使用火焰图进行profile,以下是一些说明

项目配置调整

  • cargo 项目 .cargo/config.toml
[target.x86_64-unknown-linux-musl]
rustflags =" -Ctarget-feature=-crt-static"

[target.aarch64-unknown-linux-musl]
rustflags = " -Ctarget-feature=-crt-static"

Cargo.toml

[profile.release]
debug = true     # If you want debug symbol in release mode, set the env variable: RUSTFLAGS=-g
lto = false
codegen-units = 256
opt-level = 1
panic = "abort"

构建应用

推荐基于docker,可以使用rust:1.75.0-alpine3.19 确保rust 版本一致

  • 构建命令
cargo build --release --bins --lib  --target x86_64-unknown-linux-musl
  • docker 镜像

因为一些兼容问题addr2line 这个perf 依赖的,会有兼容问题,推荐基于rust 构建,然后拷贝到容器中

addr2line 构建

cargo install  addr2line --features="bin" 
PATH=$HOME/.cargo/bin:$PATH

dockerfile

FROM eclipse/zenoh:1.0.2
RUN apk add perf  musl-dev
COPY libzenoh_plugin_rest.so /libzenoh_plugin_rest.so
COPY libzenoh_plugin_storage_manager.so /libzenoh_plugin_storage_manager.so
COPY addr2line /usr/bin/addr2line
COPY cargo-flamegraph /usr/bin/cargo-flamegraph
COPY flamegraph /usr/bin/flamegraph
COPY zenohd /zenohd
RUN chmod +x /zenohd

perf 使用

perf record -ag -F 99 --call-graph dwarf  -p 1
perf script --header > my-zh-v3.perf

查看信息

可以通过flame-scope 可视化ui 服务

  • 一个效果

说明

以上是一个简单构建以及使用说明,有利于更好的学习zenoh 内部的一些工作机制,当然这个属于代码调用,实际对于网络请求的可以结合zenoh-dissector

参考资料

https://stackoverflow.com/questions/38803760/how-to-get-a-release-build-with-debugging-information-when-using-cargo

https://datafusion.apache.org/library-user-guide/profiling.html

https://nnethercote.github.io/perf-book/profiling.html

https://doc.rust-lang.org/cargo/reference/profiles.html

https://github.com/gimli-rs/addr2line

https://github.com/flamegraph-rs/flamegraph

https://bugzilla.kernel.org/show_bug.cgi?id=218996

https://github.com/ZettaScaleLabs/zenoh-dissector

posted on 2025-01-13 08:00  荣锋亮  阅读(76)  评论(0)    收藏  举报

导航