From 240fd2be6f46ad7d152f11a41f768e89430b5192 Mon Sep 17 00:00:00 2001 From: dqhl76 Date: Mon, 1 Dec 2025 14:52:53 +0800 Subject: [PATCH 1/2] chore: post process frames after explain perf --- Cargo.lock | 2 +- Cargo.toml | 2 +- .../base/src/runtime/perf/query_perf.rs | 45 +++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b97349d475426..ba2e8dec0c8aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12251,7 +12251,7 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "pprof" version = "0.15.0" -source = "git+https://github.com/datafuse-extras/pprof-rs?rev=fe22b23#fe22b23cfa294122547a1add1377918aca0493b6" +source = "git+https://github.com/datafuse-extras/pprof-rs?rev=edecd74#edecd74268ea5dcd31836bc4cb8acdcb21c51b24" dependencies = [ "aligned-vec", "backtrace", diff --git a/Cargo.toml b/Cargo.toml index f9030d33c3a56..dfcde08e41730 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -425,7 +425,7 @@ petgraph = { version = "0.6.2", features = ["serde-1"] } pin-project = "1" pin-project-lite = "0.2.9" poem = { version = "3.0", features = ["openssl-tls", "multipart", "compression", "cookie"] } -pprof = { git = "https://github.com/datafuse-extras/pprof-rs", rev = "fe22b23", features = [ +pprof = { git = "https://github.com/datafuse-extras/pprof-rs", rev = "edecd74", features = [ "flamegraph", "protobuf-codec", "protobuf", diff --git a/src/common/base/src/runtime/perf/query_perf.rs b/src/common/base/src/runtime/perf/query_perf.rs index 1d20c387fab9d..991a601c21dbc 100644 --- a/src/common/base/src/runtime/perf/query_perf.rs +++ b/src/common/base/src/runtime/perf/query_perf.rs @@ -17,6 +17,7 @@ use databend_common_exception::Result; use log::debug; use pprof::ProfilerGuard; use pprof::ProfilerGuardBuilder; +use regex::Regex; use crate::runtime::ThreadTracker; use crate::runtime::TrackingGuard; @@ -65,6 +66,7 @@ impl QueryPerf { pub fn dump(profiler_guard: &ProfilerGuard<'static>) -> Result { let reporter = profiler_guard .report() + .frames_post_processor(frames_post_processor()) .build() .map_err(|_e| ErrorCode::Internal("Failed to report profiler data"))?; debug!("perf stop, begin to dump flamegraph"); @@ -126,6 +128,49 @@ impl QueryPerf { } } +const PPROF_TRACE_SYMBOL: &str = + "::trace"; + +fn frames_post_processor() -> impl Fn(&mut pprof::Frames) { + // If pprof cannot get thread name, it will use thread id as fallback + // this will make the flamegraph hard to read, so we rename such threads to "threads" + let thread_rename = [(Regex::new(r"^\d+$").unwrap(), "threads")]; + + move |frames| { + for (regex, name) in thread_rename.iter() { + if regex.is_match(&frames.thread_name) { + frames.thread_name = name.to_string(); + } + } + + // Remove frames introduced by pprof's own stack collection to keep user stacks clean. + if let Some(pos) = frames.frames.iter().position(|frame| { + frame + .iter() + .any(|symbol| symbol.name() == PPROF_TRACE_SYMBOL) + }) { + frames.frames.drain(..=pos); + } + + // Mark inlined functions with "(inlined)" suffix + for inline_frames in frames.frames.iter_mut() { + if inline_frames.len() <= 1 { + continue; + } + + // Mark every symbol except the outermost one as inlined. + let last_symbol_index = inline_frames.len() - 1; + for symbol in inline_frames.iter_mut().take(last_symbol_index) { + let symbol_name = symbol.name(); + if symbol_name.ends_with(" (inlined)") { + continue; + } + symbol.name = Some(format!("{symbol_name} (inlined)").into_bytes()); + } + } + } +} + #[cfg(test)] mod tests { use crate::runtime::QueryPerf; From 4ad73791158f76dbf1d5a298255b53af072c450e Mon Sep 17 00:00:00 2001 From: Liuqing Yue Date: Mon, 1 Dec 2025 20:30:06 +0800 Subject: [PATCH 2/2] ci: add a flag to allow skip trim debug info --- .github/actions/build_linux/action.yml | 5 +++++ .github/workflows/cloud.yml | 1 + 2 files changed, 6 insertions(+) diff --git a/.github/actions/build_linux/action.yml b/.github/actions/build_linux/action.yml index e1cbac6700c14..3fddf31e56e49 100644 --- a/.github/actions/build_linux/action.yml +++ b/.github/actions/build_linux/action.yml @@ -23,6 +23,10 @@ inputs: description: "Category to upload" required: false default: "default" + trim_debug: + description: "Trim debug info" + required: false + default: "true" runs: using: "composite" steps: @@ -95,6 +99,7 @@ runs: ldd ./target/${{ inputs.target }}/${{ env.BUILD_PROFILE }}/databend-query || true - name: Spilt Binary Symbols + if: inputs.trim_debug == 'true' shell: bash run: | objcopy --only-keep-debug ./target/${{ inputs.target }}/${{ env.BUILD_PROFILE }}/databend-query ./target/${{ inputs.target }}/${{ env.BUILD_PROFILE }}/databend-query.debug diff --git a/.github/workflows/cloud.yml b/.github/workflows/cloud.yml index 6bc75b519f5c0..fe470c1cec314 100644 --- a/.github/workflows/cloud.yml +++ b/.github/workflows/cloud.yml @@ -77,6 +77,7 @@ jobs: artifacts: meta,query category: docker features: python-udf + trim_debug: false docker: needs: [ info, build ]