Skip to content

Reimplement the pprof to support Python stacks#99

Open
reiase wants to merge 8 commits into
masterfrom
feature/py_pprof
Open

Reimplement the pprof to support Python stacks#99
reiase wants to merge 8 commits into
masterfrom
feature/py_pprof

Conversation

@reiase
Copy link
Copy Markdown
Owner

@reiase reiase commented Aug 11, 2025

No description provided.

reiase added 5 commits July 31, 2025 14:05
Adds a new `probing/crates/pprof` crate that provides signal handling
and timer management for CPU profiling. The crate includes:

- Signal handler setup for SIGPROF
- Timer management via setitimer
- Public API for controlling profiling frequency and handlers
The previous implementation had redundant checks and error handling.
Simplify the logic to only validate when the frequency is Nothing and
directly set the frequency otherwise.
The RawCallLocation fields need to be public for use in other modules.
Also added the Clone trait for copying instances.

Enable iter_map_windows feature and spawn pprof task

The iter_map_windows feature is needed for upcoming iterator operations.
The pprof_task is now spawned on server startup for profiling.
generation

- Replace pprof-rs with custom signal handler and backtrace collection
- Add new flamegraph generation implementation
- Improve stack merging logic for Python/native frames
- Update dependencies including cpp_demangle 0.4.4
- Add smallvec for efficient frame storage
- Implement async processing of profiling samples
- Add thread-safe caching of profiling records
This modifies the Content-Disposition header to display flamegraphs
directly in the browser rather than forcing a download.
@reiase reiase requested a review from yangrudan August 11, 2025 09:10
Copy link
Copy Markdown
Collaborator

@yangrudan yangrudan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

use probing_proto::prelude::CallFrame;

pub(crate) struct Report {
offset: i64,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offset是干啥的呢?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

计划用来选择计算火焰图使用的数据的范围,功能暂时未实现

pub fn pprof_handler() {
PPROF_HOLDER.setup(100);
log::debug!("Starting pprof task to receive records");
let backtrace_id: u64 = 0;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backtrace_id是什么设计含义呀

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

无用代码,我删除掉

@yangrudan
Copy link
Copy Markdown
Collaborator

自测日志如下

[RECEIVE]
[SEND]
收发运行中:
截图 2025-08-26 16-54-53

pub const MAX_DEPTH: usize = 512;

#[allow(static_mut_refs)]
unsafe extern "C" fn pprof_handler() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reiase 侯老师, 我好像知道为什么提高采样频率会出现卡死的问题了, 参考pr105, pprof这里作为信号的handler函数, 直接调用backtrace库是不安全的. https://www.github.com/rust-lang/backtrace-rs/issues/742

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants