diff --git a/Cargo.lock b/Cargo.lock index 8540ecd..8e5ef0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -615,7 +615,7 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "perf-event-rs" version = "0.0.0" -source = "git+https://github.com/OptimatistOpenSource/perf-event-rs.git?rev=f6be76525e5540dbc8d8a34f755da919102572ec#f6be76525e5540dbc8d8a34f755da919102572ec" +source = "git+https://github.com/OptimatistOpenSource/perf-event-rs.git?rev=d6881f34b8a9cde1d70dab5fb1415271e6b0bb25#d6881f34b8a9cde1d70dab5fb1415271e6b0bb25" dependencies = [ "bindgen", "libc", diff --git a/proto/psh.proto b/proto/psh.proto index a86f997..2439fc7 100644 --- a/proto/psh.proto +++ b/proto/psh.proto @@ -101,7 +101,7 @@ message LineProtocolData { message ElfFile { string filename = 1; - bytes build_id = 2; + optional string build_id = 2; string arch = 3; // use for disasm bytes bytes = 4; } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 37002d0..b14322d 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -84,6 +84,16 @@ impl From for MMapEvent { } } +pub fn build_id_to_str(build_id: [u8; 20]) -> String { + use std::fmt::Write; + + let mut string = String::with_capacity(40); + for ele in build_id { + write!(string, "{ele:02x}").unwrap(); + } + string +} + impl From for MMapEvent { fn from(body: perf_event_rs::sampling::record::mmap2::Body) -> Self { let (maj, min, ino, ino_generation, build_id) = match body.anon_enum { @@ -94,8 +104,12 @@ impl From for MMapEvent { ino_generation, } => (Some(maj), Some(min), Some(ino), Some(ino_generation), None), perf_event_rs::sampling::record::mmap2::AnonEnum::BuildId(items) => { - let build_id = String::from_utf8(items).ok(); - (None, None, None, None, build_id) + let mut bid = [0; 20]; + for (i, &ele) in items.iter().enumerate() { + bid[i] = ele; + } + let build_id: String = build_id_to_str(bid); + (None, None, None, None, build_id.into()) } }; MMapEvent {