From 4aac4493c32c1e331db65ecb5289962a18676cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Wed, 4 Oct 2023 11:25:06 -0700 Subject: [PATCH] deps: update blazesym submodule to v0.2.0-alpha.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update the blazesym submodule to version 0.2.0-alpha.7. Signed-off-by: Daniel Müller --- blazesym | 2 +- examples/c/profile.c | 60 ++++++++++++----------- examples/rust/Cargo.lock | 47 +++++++++++++----- examples/rust/profile/src/main.rs | 80 +++++++++++++++++++------------ 4 files changed, 118 insertions(+), 71 deletions(-) diff --git a/blazesym b/blazesym index 3c6238fb..856f9ea5 160000 --- a/blazesym +++ b/blazesym @@ -1 +1 @@ -Subproject commit 3c6238fb7d12ffdb971e7195702bb452f9e76157 +Subproject commit 856f9ea5176932b5da0cfe6f1743bd4f0d8b1b29 diff --git a/examples/c/profile.c b/examples/c/profile.c index 9aba09e3..6cbc13da 100644 --- a/examples/c/profile.c +++ b/examples/c/profile.c @@ -34,8 +34,33 @@ static long perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu static struct blaze_symbolizer *symbolizer; +static void print_frame(const char *name, uintptr_t input_addr, uintptr_t addr, uint64_t offset, const blaze_symbolize_code_info* code_info) +{ + // If we have an input address we have a new symbol. + if (input_addr != 0) { + printf("%016lx: %s @ 0x%lx+0x%lx", input_addr, name, addr, offset); + if (code_info != NULL && code_info->dir != NULL && code_info->file != NULL) { + printf(" %s/%s:%u\n", code_info->dir, code_info->file, code_info->line); + } else if (code_info != NULL && code_info->file != NULL) { + printf(" %s:%u\n", code_info->file, code_info->line); + } else { + printf("\n"); + } + } else { + printf("%016s %s", "", name); + if (code_info != NULL && code_info->dir != NULL && code_info->file != NULL) { + printf("@ %s/%s:%u [inlined]\n", code_info->dir, code_info->file, code_info->line); + } else if (code_info != NULL && code_info->file != NULL) { + printf("@ %s:%u [inlined]\n", code_info->file, code_info->line); + } else { + printf("[inlined]\n"); + } + } +} + static void show_stack_trace(__u64 *stack, int stack_sz, pid_t pid) { + const struct blaze_symbolize_inlined_fn* inlined; const struct blaze_result *result; const struct blaze_sym *sym; int i, j; @@ -54,39 +79,18 @@ static void show_stack_trace(__u64 *stack, int stack_sz, pid_t pid) for (i = 0; i < stack_sz; i++) { - if (!result || result->size <= i || !result->entries[i].size) { + if (!result || result->cnt <= i || result->syms[i].name == NULL) { printf(" %2d [<%016llx>]\n", i, stack[i]); continue; } - if (result->entries[i].size == 1) { - sym = &result->entries[i].syms[0]; - - if (sym->dir && sym->dir[0] != '\0' && sym->file && sym->file[0] != '\0') { - printf(" %2d [<%016llx>] %s+0x%lx %s/%s:%u\n", i, stack[i], - sym->name, sym->offset, sym->dir, sym->file, sym->line); - } else if (sym->file && sym->file[0] != '\0') { - printf(" %2d [<%016llx>] %s+0x%lx %s:%u\n", i, stack[i], - sym->name, sym->offset, sym->file, sym->line); - } else { - printf(" %2d [<%016llx>] %s+0x%lx\n", i, stack[i], sym->name, sym->offset); - } - continue; - } + sym = &result->syms[i]; + print_frame(sym->name, stack[i], sym->addr, sym->offset, &sym->code_info); - printf(" %2d [<%016llx>]\n", i, stack[i]); - for (j = 0; j < result->entries[i].size; j++) { - sym = &result->entries[i].syms[j]; - if (sym->dir && sym->dir[0] != '\0' && sym->file && sym->file[0] != '\0') { - printf(" %s+0x%lx %s/%s:%u\n", sym->name, - sym->offset, sym->dir, sym->file, sym->line); - } else if (sym->file && sym->file[0] != '\0') { - printf(" %s+0x%lx %s:%u\n", sym->name, - sym->offset, sym->file, sym->line); - } else { - printf(" %s+0x%lx\n", sym->name, sym->offset); - } - } + for (j = 0; j < sym->inlined_cnt; j++) { + inlined = &sym->inlined[j]; + print_frame(sym->name, 0, 0, 0, &inlined->code_info); + } } blaze_result_free(result); diff --git a/examples/rust/Cargo.lock b/examples/rust/Cargo.lock index 09fee1a7..c64a6da8 100644 --- a/examples/rust/Cargo.lock +++ b/examples/rust/Cargo.lock @@ -28,6 +28,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + [[package]] name = "ansi_term" version = "0.12.1" @@ -74,7 +80,7 @@ checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" [[package]] name = "blazesym" -version = "0.2.0-alpha.5" +version = "0.2.0-alpha.7" dependencies = [ "cpp_demangle", "gimli", @@ -151,7 +157,7 @@ dependencies = [ "bitflags 1.3.2", "clap_derive 3.2.17", "clap_lex 0.2.4", - "indexmap", + "indexmap 1.9.1", "once_cell", "textwrap 0.15.0", ] @@ -243,6 +249,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "errno" version = "0.3.2" @@ -266,9 +278,9 @@ dependencies = [ [[package]] name = "fallible-iterator" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" [[package]] name = "fastrand" @@ -291,12 +303,12 @@ dependencies = [ [[package]] name = "gimli" -version = "0.27.3" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" dependencies = [ "fallible-iterator", - "indexmap", + "indexmap 2.0.2", "stable_deref_trait", ] @@ -308,11 +320,12 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.13.2" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" dependencies = [ "ahash", + "allocator-api2", ] [[package]] @@ -355,6 +368,16 @@ dependencies = [ "hashbrown 0.12.3", ] +[[package]] +name = "indexmap" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" +dependencies = [ + "equivalent", + "hashbrown 0.14.1", +] + [[package]] name = "instant" version = "0.1.12" @@ -467,11 +490,11 @@ checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" [[package]] name = "lru" -version = "0.10.1" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "718e8fae447df0c7e1ba7f5189829e63fd536945c8988d61444c19039f16b670" +checksum = "a4a83fb7698b3643a0e34f9ae6f2e8f0178c0fd42f8b59d493aa271ff3a5bf21" dependencies = [ - "hashbrown 0.13.2", + "hashbrown 0.14.1", ] [[package]] diff --git a/examples/rust/profile/src/main.rs b/examples/rust/profile/src/main.rs index b67f5906..54676047 100644 --- a/examples/rust/profile/src/main.rs +++ b/examples/rust/profile/src/main.rs @@ -1,6 +1,5 @@ use std::io::Error; use std::mem; -use std::path::PathBuf; use std::time::Duration; use blazesym::symbolize; @@ -24,6 +23,7 @@ use profile::*; const MAX_STACK_DEPTH: usize = 128; const TASK_COMM_LEN: usize = 16; +const ADDR_WIDTH: usize = 16; // A Rust version of stacktrace_event in profile.h #[repr(C)] @@ -69,6 +69,39 @@ fn attach_perf_event( .collect() } +fn print_frame(name: &str, addr_info: Option<(blazesym::Addr, blazesym::Addr, usize)>, code_info: &Option) { + let code_info = code_info.as_ref().map(|code_info| { + let path = code_info.to_path(); + let path = path.display(); + + match (code_info.line, code_info.column) { + (Some(line), Some(col)) => format!(" {path}:{line}:{col}"), + (Some(line), None) => format!(" {path}:{line}"), + (None, _) => format!(" {path}"), + } + }); + + if let Some((input_addr, addr, offset)) = addr_info { + // If we have various address information bits we have a new symbol. + println!( + "{input_addr:#0width$x}: {name} @ {addr:#x}+{offset:#x}{code_info}", + code_info = code_info.as_deref().unwrap_or(""), + width = ADDR_WIDTH + ) + } else { + // Otherwise we are dealing with an inlined call. + println!( + "{:width$} {name}{code_info} [inlined]", + " ", + code_info = code_info + .map(|info| format!(" @{info}")) + .as_deref() + .unwrap_or(""), + width = ADDR_WIDTH + ) + } +} + // Pid 0 means a kernel space stack. fn show_stack_trace(stack: &[u64], symbolizer: &symbolize::Symbolizer, pid: u32) { let converted_stack; @@ -101,36 +134,23 @@ fn show_stack_trace(stack: &[u64], symbolizer: &symbolize::Symbolizer, pid: u32) } }; - for (i, (addr, syms)) in stack.iter().zip(syms).enumerate() { - let mut addr_fmt = format!(" {i:2} [<{addr:016x}>]"); - if syms.is_empty() { - println!("{addr_fmt}") - } else { - for (i, sym) in syms.into_iter().enumerate() { - if i == 1 { - addr_fmt = addr_fmt.replace(|_c| true, " "); + for (input_addr, sym) in stack.iter().copied().zip(syms) { + match sym { + symbolize::Symbolized::Sym(symbolize::Sym { + name, + addr, + offset, + code_info, + inlined, + .. + }) => { + print_frame(&name, Some((input_addr, addr, offset)), &code_info); + for frame in inlined.iter() { + print_frame(&frame.name, None, &frame.code_info); } - - let path = match (sym.dir, sym.file) { - (Some(dir), Some(file)) => Some(dir.join(file)), - (dir, file) => dir.or_else(|| file.map(PathBuf::from)), - }; - - let src_loc = if let (Some(path), Some(line)) = (path, sym.line) { - if let Some(col) = sym.column { - format!(" {}:{line}:{col}", path.display()) - } else { - format!(" {}:{line}", path.display()) - } - } else { - String::new() - }; - - let symbolize::Sym { - name, addr, offset, .. - } = sym; - - println!("{addr_fmt} {name} @ {addr:#x}+{offset:#x}{src_loc}"); + } + symbolize::Symbolized::Unknown => { + println!("{input_addr:#0width$x}: ", width = ADDR_WIDTH) } } }