Skip to content

Commit 2d268d7

Browse files
committed
chore: rbspy 0.2
1 parent b453009 commit 2d268d7

File tree

1 file changed

+15
-18
lines changed
  • pyroscope_backends/pyroscope_rbspy/src

1 file changed

+15
-18
lines changed

pyroscope_backends/pyroscope_rbspy/src/lib.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::{
1515
thread::JoinHandle,
1616
};
1717

18+
/// Short-hand function for creating a new Rbspy backend.
1819
pub fn rbspy_backend(config: RbspyConfig) -> BackendImpl<BackendUninitialized> {
1920
BackendImpl::new(Box::new(Rbspy::new(config)))
2021
}
@@ -55,24 +56,28 @@ impl RbspyConfig {
5556
}
5657
}
5758

59+
/// Set the sampling rate
5860
pub fn sample_rate(self, sample_rate: u32) -> Self {
5961
RbspyConfig {
6062
sample_rate,
6163
..self
6264
}
6365
}
6466

67+
/// Set the lock process flag
6568
pub fn lock_process(self, lock_process: bool) -> Self {
6669
RbspyConfig {
6770
lock_process,
6871
..self
6972
}
7073
}
7174

75+
/// Set the time limit
7276
pub fn time_limit(self, time_limit: Option<core::time::Duration>) -> Self {
7377
RbspyConfig { time_limit, ..self }
7478
}
7579

80+
/// Include subprocesses
7681
pub fn with_subprocesses(self, with_subprocesses: bool) -> Self {
7782
RbspyConfig {
7883
with_subprocesses,
@@ -89,7 +94,7 @@ pub struct Rbspy {
8994
/// Rbspy Sampler
9095
sampler: Option<Sampler>,
9196
/// StackTrace Receiver
92-
stack_receiver: Option<Receiver<rbspy::StackTrace>>,
97+
//stack_receiver: Option<Receiver<rbspy::StackTrace>>,
9398
/// Error Receiver
9499
error_receiver: Option<Receiver<std::result::Result<(), anyhow::Error>>>,
95100
/// Profiling buffer
@@ -105,10 +110,11 @@ impl std::fmt::Debug for Rbspy {
105110
}
106111

107112
impl Rbspy {
113+
/// Create a new Rbspy instance
108114
pub fn new(config: RbspyConfig) -> Self {
109115
Rbspy {
110116
sampler: None,
111-
stack_receiver: None,
117+
//stack_receiver: None,
112118
error_receiver: None,
113119
config,
114120
buffer: Arc::new(Mutex::new(StackBuffer::default())),
@@ -122,26 +128,31 @@ type ErrorSender = Sender<std::result::Result<(), anyhow::Error>>;
122128
type ErrorReceiver = Receiver<std::result::Result<(), anyhow::Error>>;
123129

124130
impl Backend for Rbspy {
131+
/// Return the backend name
125132
fn spy_name(&self) -> Result<String> {
126133
Ok("rbspy".to_string())
127134
}
128135

136+
/// Return the sample rate
129137
fn sample_rate(&self) -> Result<u32> {
130138
Ok(self.config.sample_rate)
131139
}
132140

141+
/// Add a rule to the ruleset
133142
fn add_rule(&self, rule: Rule) -> Result<()> {
134143
self.ruleset.add_rule(rule)?;
135144

136145
Ok(())
137146
}
138147

148+
/// Remove a rule from the ruleset
139149
fn remove_rule(&self, rule: Rule) -> Result<()> {
140150
self.ruleset.remove_rule(rule)?;
141151

142152
Ok(())
143153
}
144154

155+
/// Initialize the backend
145156
fn initialize(&mut self) -> Result<()> {
146157
// Check if a process ID is set
147158
if self.config.pid.is_none() {
@@ -174,7 +185,7 @@ impl Backend for Rbspy {
174185

175186
// Set Error and Stack Receivers
176187
//self.stack_receiver = Some(stack_receiver);
177-
//self.error_receiver = Some(error_receiver);
188+
self.error_receiver = Some(error_receiver);
178189

179190
// Get the Sampler
180191
let sampler = self
@@ -195,21 +206,7 @@ impl Backend for Rbspy {
195206
// ruleset reference
196207
let ruleset = self.ruleset.clone();
197208

198-
let a: JoinHandle<Result<()>> = std::thread::spawn(move || {
199-
// Send Errors to Log
200-
//let errors = error_receiver.iter();
201-
//for error in errors {
202-
//match error {
203-
//Ok(_) => {}
204-
//Err(e) => {
205-
//log::error!("Rbspy: Error in Sampler: {}", e);
206-
//}
207-
//}
208-
//}
209-
210-
// Collect the StackTrace from the receiver
211-
//let stack_trace = stack_receiver.iter();
212-
209+
let _: JoinHandle<Result<()>> = std::thread::spawn(move || {
213210
// Iterate over the StackTrace
214211
while let Ok(stack_trace) = stack_receiver.recv() {
215212
// convert StackTrace

0 commit comments

Comments
 (0)