Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/executor/wall_time/perf/save_artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,36 @@ fn save_symbols(
mappings_by_pid
}

fn is_libc_path(path: &Path) -> bool {
let Some(filename) = path.file_name().and_then(|n| n.to_str()) else {
return false;
};
// Match libc.so.6, libc-2.31.so, etc. but not unrelated libs like libc-client.so
filename.starts_with("libc.so")
|| (filename.starts_with("libc-")
&& filename.as_bytes().get(5).is_some_and(u8::is_ascii_digit))
Comment on lines +133 to +134
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

The filename.as_bytes().get(5) check relies on the hard-coded index immediately after the "libc-" prefix, which is a bit opaque. Consider rewriting using strip_prefix("libc-") + bytes().next() (or similar) to make the intent clearer and avoid manual indexing.

Suggested change
|| (filename.starts_with("libc-")
&& filename.as_bytes().get(5).is_some_and(u8::is_ascii_digit))
|| filename
.strip_prefix("libc-")
.and_then(|rest| rest.bytes().next())
.is_some_and(|b| b.is_ascii_digit())

Copilot uses AI. Check for mistakes.
}

Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

is_libc_path() introduces non-trivial filename matching logic, but there are no unit tests for the accepted/rejected patterns (e.g., libc.so.6, libc-2.31.so should match; libc-client.so should not). Adding a small #[cfg(test)] module with table-driven cases would help prevent future regressions and clarify the intended matching behavior.

Suggested change
#[cfg(test)]
mod tests {
use super::is_libc_path;
use std::path::Path;
#[test]
fn is_libc_path_accepts_expected_libc_filenames() {
let cases = [
"/lib/x86_64-linux-gnu/libc.so",
"/lib/x86_64-linux-gnu/libc.so.6",
"/usr/lib/libc-2.31.so",
"libc-2.so",
];
for case in cases {
assert!(is_libc_path(Path::new(case)), "expected match for {case}");
}
}
#[test]
fn is_libc_path_rejects_non_libc_filenames() {
let cases = [
"/usr/lib/libc-client.so",
"/usr/lib/libcrypt.so",
"/usr/lib/libc-.so",
"/usr/lib/libc-a.so",
"/usr/lib/not-libc.so.6",
"/",
"",
];
for case in cases {
assert!(!is_libc_path(Path::new(case)), "unexpected match for {case}");
}
}
}

Copilot uses AI. Check for mistakes.
fn warn_missing_libc_debug_info(
loaded_modules_by_path: &HashMap<PathBuf, LoadedModule>,
debug_info_by_elf_path: &HashMap<PathBuf, ModuleDebugInfo>,
) {
for (path, loaded_module) in loaded_modules_by_path {
if !is_libc_path(path) || loaded_module.module_symbols.is_none() {
continue;
}
if debug_info_by_elf_path.contains_key(path) {
continue;
}
warn!(
"libc debug info not found for {}. Flamegraphs may contain \
unsymbolicated libc frames. Install debug symbols \
(e.g., `apt install libc6-dbg`) to fix this.",
Comment on lines +149 to +151
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

The warning suggests installing libc6-dbg via apt will fix missing DWARF, but debug_info_by_path() only attempts to read DWARF sections from the mapped ELF at path (it doesn't resolve .gnu_debuglink/build-id or /usr/lib/debug files). On Debian/Ubuntu, installing libc6-dbg typically provides a separate debug file, so this message may be misleading/unactionable (and apt is distro-specific). Consider either (a) implementing lookup of external debug files for libc (debuglink/build-id) or (b) adjusting the warning text to be OS/distro-agnostic and accurately describe what data is missing and where the tool looks for it.

Suggested change
"libc debug info not found for {}. Flamegraphs may contain \
unsymbolicated libc frames. Install debug symbols \
(e.g., `apt install libc6-dbg`) to fix this.",
"No DWARF debug info was found in the mapped libc ELF at {}. \
Flamegraphs may contain unsymbolicated libc frames. \
This tool currently reads debug info from the mapped ELF path only.",

Copilot uses AI. Check for mistakes.
path.display()
);
}
}

/// Compute debug info from symbols and build per-pid debug info mappings.
fn save_debug_info(
loaded_modules_by_path: &HashMap<PathBuf, LoadedModule>,
Expand All @@ -136,6 +166,8 @@ fn save_debug_info(

let debug_info_by_elf_path = debug_info_by_path(loaded_modules_by_path);

warn_missing_libc_debug_info(loaded_modules_by_path, &debug_info_by_elf_path);

for path in debug_info_by_elf_path.keys() {
get_or_insert_key(path_to_key, path);
}
Expand Down
Loading