Skip to content

Commit 160fa82

Browse files
committed
wip(lib): minor refactoring
1 parent b4fb3eb commit 160fa82

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
# v0.5.4
2+
## New Features
3+
- Add report transfromation function which allows changing the report before
4+
sending it to the Pyroscope Server.
5+
- Add Gzip support.
6+
7+
## Bug Fixes
8+
- Use URL Builder. ([786c89b](https://github.com/pyroscope-io/pyroscope-rs/commit/786c89bb99839c45778410012a6da60267d395df))
9+
110
# v0.5.3
2-
## New features
11+
## New Features
312
- Add BackendConfig to make reporting of pid, thread_id and thread_name
413
optional.
514
- Backends can add a suffix to the "application_name"

pyroscope_ffi/ffikit/src/lib.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ static ONCE: Once = Once::new();
2323

2424
lazy_static! {
2525
/// Root Sender
26+
/// This is the sender to the main loop. It is lazily initialized inside a Mutex.
2627
static ref SENDER: Mutex<Option<Sender<Signal>>> = Mutex::new(None);
2728
}
2829

30+
/// Signal enum.
31+
/// This enum is used to send signals to the main loop. It is used to add/remove global or thread
32+
/// tags and to exit the main loop.
2933
#[derive(Debug, Encode, Decode, PartialEq, Clone)]
3034
pub enum Signal {
3135
Kill,
@@ -52,7 +56,7 @@ pub fn initialize_ffi() -> Result<Receiver<Signal>> {
5256

5357
// Listen for signals on the main parent process.
5458
let fn_sender = merge_sender.clone();
55-
let channel_listener: JoinHandle<Result<()>> = std::thread::spawn(move || {
59+
let _channel_listener: JoinHandle<Result<()>> = std::thread::spawn(move || {
5660
log::trace!("Spawned FFI listener thread.");
5761

5862
while let Ok(signal) = receiver.recv() {
@@ -81,7 +85,7 @@ pub fn initialize_ffi() -> Result<Receiver<Signal>> {
8185

8286
// Listen for signals on local socket
8387
let socket_sender = merge_sender.clone();
84-
let socket_listener: JoinHandle<Result<()>> = std::thread::spawn(move || {
88+
let _socket_listener: JoinHandle<Result<()>> = std::thread::spawn(move || {
8589
let socket_address = format!("/tmp/PYROSCOPE-{}", get_parent_pid());
8690

8791
log::trace!(
@@ -158,7 +162,16 @@ pub fn send(signal: Signal) -> Result<()> {
158162
conn.flush()?;
159163
} else {
160164
// Send signal through parent process.
161-
SENDER.lock()?.as_ref().unwrap().send(signal)?;
165+
if let Some(sender) = &*SENDER.lock()? {
166+
log::trace!(
167+
target: LOG_TAG,
168+
"Sending signal {:?} through FFI channel",
169+
signal
170+
);
171+
sender.send(signal)?;
172+
} else {
173+
log::error!(target: LOG_TAG, "FFI channel not initialized");
174+
}
162175
}
163176

164177
Ok(())

src/backend/backend.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,14 @@ use std::{
1212
use super::Report;
1313

1414
/// Backend Config
15-
#[derive(Debug, Copy, Clone)]
15+
#[derive(Debug, Copy, Clone, Default)]
1616
pub struct BackendConfig {
1717
pub report_thread_id: bool,
1818
pub report_thread_name: bool,
1919
pub report_pid: bool,
2020
pub report_oncpu: bool,
2121
}
2222

23-
impl Default for BackendConfig {
24-
fn default() -> Self {
25-
Self {
26-
report_thread_id: false,
27-
report_thread_name: false,
28-
report_pid: false,
29-
report_oncpu: false,
30-
}
31-
}
32-
}
33-
3423
/// Backend Trait
3524
pub trait Backend: Send + Debug {
3625
/// Backend Spy Name

src/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl Session {
156156
let mut report_owned = report.to_owned();
157157

158158
// Apply function to the report
159-
if let Some(func) = self.config.func.clone() {
159+
if let Some(func) = self.config.func {
160160
report_owned = func(report_owned);
161161
}
162162

0 commit comments

Comments
 (0)