feat: add heap memory profiling with jemalloc#180
Conversation
🤖 Kimi Code ReviewReview SummaryThis PR adds jemalloc-based heap profiling capabilities to ethlambda. The implementation is well-structured with proper platform-specific handling. Here are my findings: Issues Found
Suggestions
Positive Aspects
Automated review by Kimi (Moonshot AI) · custom prompt |
🤖 Codex Code Review
Consensus-specific note: this PR does not modify fork choice, attestation validation, justification/finalization, state transition, XMSS, or SSZ logic, so I found no direct consensus-correctness regressions in scope. Automated review by OpenAI Codex · custom prompt |
🤖 Claude Code ReviewNow I have everything I need for the review. Here's my analysis: PR Review: feat: add heap memory profiling with jemallocSummary: Adds Issues
The allocator and // main.rs:8-11 — should also be cfg(target_os = "linux") to match the endpoints
#[cfg(not(target_env = "msvc"))]
#[allow(non_upper_case_globals)]
#[unsafe(export_name = "malloc_conf")]
static malloc_conf: &[u8] = b"prof:true,prof_active:true,lg_prof_sample:19\0";Suggestion: gate Unauthenticated debug endpoints on the shared metrics port ( The A comment or doc note warning that the debug endpoints should not be exposed publicly would be appropriate. Alternatively, bind the debug router to a separate listener address — though that adds complexity.
Adding # crates/net/rpc/Cargo.toml
[features]
heap-profiling = ["dep:jemalloc_pprof"]
[dependencies]
jemalloc_pprof = { workspace = true, optional = true }Minor Notes
SummaryThe main actionable items are:
The core implementation — the jemalloc allocator setup, the Automated review by Claude (Anthropic) · custom prompt |
Greptile SummaryThis PR integrates jemalloc as the global allocator for the Allocator & Profiling: Endpoints: The new Platform Inconsistency: The Confidence Score: 2/5
Sequence DiagramsequenceDiagram
participant Client
participant RpcServer
participant HeapProfilingHandler
participant JemallocProfCtl
Client->>RpcServer: GET /debug/pprof/allocs
RpcServer->>HeapProfilingHandler: handle_get_heap()
alt Linux
HeapProfilingHandler->>JemallocProfCtl: PROF_CTL.as_ref()
alt profiling enabled
JemallocProfCtl-->>HeapProfilingHandler: Some(prof_ctl)
HeapProfilingHandler->>JemallocProfCtl: lock().await
HeapProfilingHandler->>JemallocProfCtl: dump_pprof()
JemallocProfCtl-->>HeapProfilingHandler: Ok(pprof_bytes)
HeapProfilingHandler-->>RpcServer: 200 application/octet-stream
else profiling not enabled
JemallocProfCtl-->>HeapProfilingHandler: None
HeapProfilingHandler-->>RpcServer: 500 Internal Server Error
end
else non-Linux
HeapProfilingHandler-->>RpcServer: 501 Not Implemented
end
RpcServer-->>Client: Response
Client->>RpcServer: GET /debug/pprof/allocs/flamegraph
RpcServer->>HeapProfilingHandler: handle_get_heap_flamegraph()
alt Linux
HeapProfilingHandler->>JemallocProfCtl: dump_flamegraph()
JemallocProfCtl-->>HeapProfilingHandler: Ok(svg)
HeapProfilingHandler-->>RpcServer: 200 image/svg+xml
else non-Linux
HeapProfilingHandler-->>RpcServer: 501 Not Implemented
end
RpcServer-->>Client: Response
Last reviewed commit: 2110013 |
This PR adds jemalloc as a global allocator, with heap memory profiling, similar to how we use it in ethrex.