From a24b6a9385fc212c5703539c273d1bac64b8c4f7 Mon Sep 17 00:00:00 2001 From: Francesco Vigliaturo Date: Mon, 6 Jun 2022 11:23:45 +0200 Subject: [PATCH 1/3] Adds timing info to each sample Signed-off-by: Francesco Vigliaturo --- src/frames.rs | 7 +++++++ src/profiler.rs | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/frames.rs b/src/frames.rs index 83ed61a9..94887585 100644 --- a/src/frames.rs +++ b/src/frames.rs @@ -5,6 +5,7 @@ use std::fmt::{self, Debug, Display, Formatter}; use std::hash::{Hash, Hasher}; use std::os::raw::c_void; use std::path::PathBuf; +use std::time::SystemTime; use smallvec::SmallVec; use symbolic_demangle::demangle; @@ -18,6 +19,7 @@ pub struct UnresolvedFrames { pub thread_name: [u8; MAX_THREAD_NAME], pub thread_name_length: usize, pub thread_id: u64, + pub sample_timestamp: SystemTime, } impl Default for UnresolvedFrames { @@ -28,6 +30,7 @@ impl Default for UnresolvedFrames { thread_name: [0; MAX_THREAD_NAME], thread_name_length: 0, thread_id: 0, + sample_timestamp: SystemTime::now(), } } } @@ -43,6 +46,7 @@ impl UnresolvedFrames { frames: SmallVec<[::Frame; MAX_DEPTH]>, tn: &[u8], thread_id: u64, + sample_timestamp: SystemTime, ) -> Self { let thread_name_length = tn.len(); let mut thread_name = [0; MAX_THREAD_NAME]; @@ -53,6 +57,7 @@ impl UnresolvedFrames { thread_name, thread_name_length, thread_id, + sample_timestamp, } } } @@ -164,6 +169,7 @@ pub struct Frames { pub frames: Vec>, pub thread_name: String, pub thread_id: u64, + pub sample_timestamp: SystemTime, } impl Frames { @@ -210,6 +216,7 @@ impl From for Frames { thread_name: String::from_utf8_lossy(&frames.thread_name[0..frames.thread_name_length]) .into_owned(), thread_id: frames.thread_id, + sample_timestamp: frames.sample_timestamp, } } } diff --git a/src/profiler.rs b/src/profiler.rs index 2e1f03e8..25c7b123 100644 --- a/src/profiler.rs +++ b/src/profiler.rs @@ -2,6 +2,7 @@ use std::convert::TryInto; use std::os::raw::c_int; +use std::time::SystemTime; use nix::sys::signal; use once_cell::sync::Lazy; @@ -284,6 +285,8 @@ extern "C" fn perf_signal_handler( let mut bt: SmallVec<[::Frame; MAX_DEPTH]> = SmallVec::with_capacity(MAX_DEPTH); let mut index = 0; + + let sample_timestamp: SystemTime = SystemTime::now(); TraceImpl::trace(ucontext, |frame| { let ip = Frame::ip(frame); if profiler.is_blocklisted(ip) { @@ -306,7 +309,7 @@ extern "C" fn perf_signal_handler( write_thread_name(current_thread, &mut name); let name = unsafe { std::ffi::CStr::from_ptr(name_ptr) }; - profiler.sample(bt, name.to_bytes(), current_thread as u64); + profiler.sample(bt, name.to_bytes(), current_thread as u64, sample_timestamp); } } } @@ -392,8 +395,9 @@ impl Profiler { backtrace: SmallVec<[::Frame; MAX_DEPTH]>, thread_name: &[u8], thread_id: u64, + sample_timestamp: SystemTime, ) { - let frames = UnresolvedFrames::new(backtrace, thread_name, thread_id); + let frames = UnresolvedFrames::new(backtrace, thread_name, thread_id, sample_timestamp); self.sample_counter += 1; if let Ok(()) = self.data.add(frames, 1) {} From f43cbbebc24a172ee44b3c61f36abb2edc4cbe6c Mon Sep 17 00:00:00 2001 From: Francesco Vigliaturo Date: Thu, 9 Jun 2022 10:33:10 +0200 Subject: [PATCH 2/3] Updates the CHANGELOG.md Signed-off-by: Francesco Vigliaturo --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10b68860..ffeaef98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Remove `backtrace-rs` feature, as the default choice when not specified (#130) +### Added +- Add `sample_timestamp` to Frames and UnresolvedFrames in order to have more fine-grained info on when the samples are collected + ## [0.9.1] - 2022-05-19 ### Fixed From 32352a92c22a92e2ad7d6547045fe5199ed8fe80 Mon Sep 17 00:00:00 2001 From: Francesco Vigliaturo Date: Thu, 9 Jun 2022 10:46:17 +0200 Subject: [PATCH 3/3] Add PR info to updated CHANGELOG.md Signed-off-by: Francesco Vigliaturo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffeaef98..de80b0d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Remove `backtrace-rs` feature, as the default choice when not specified (#130) ### Added -- Add `sample_timestamp` to Frames and UnresolvedFrames in order to have more fine-grained info on when the samples are collected +- Add `sample_timestamp` to Frames and UnresolvedFrames in order to have more fine-grained info on when the samples are collected (#133) ## [0.9.1] - 2022-05-19