Skip to content

Commit 99b8f61

Browse files
committed
refactor(clippy): fix clippy warnings
1 parent d7d0a05 commit 99b8f61

File tree

6 files changed

+47
-47
lines changed

6 files changed

+47
-47
lines changed

examples/internal/pyspy-connect.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn main() -> Result<()> {
2424
.include_idle(false)
2525
.native(false);
2626

27-
let mut agent = PyroscopeAgent::builder("http://localhost:4040", "pyspy.basic")
27+
let agent = PyroscopeAgent::builder("http://localhost:4040", "pyspy.basic")
2828
.tags([("Host", "Python")].to_vec())
2929
.backend(pyspy_backend(config))
3030
.build()?;
@@ -37,30 +37,29 @@ fn main() -> Result<()> {
3737
println!("Start Time: {}", start);
3838

3939
// Start Agent
40-
agent.start()?;
40+
let agent_running = agent.start()?;
4141

4242
// Profile for around 1 minute
43-
std::thread::sleep(std::time::Duration::from_secs(20));
43+
std::thread::sleep(std::time::Duration::from_secs(60));
4444

45-
println!("Stopping agent");
46-
// Stop Agent
47-
agent.stop()?;
48-
49-
println!("Done");
50-
51-
agent.start()?;
52-
std::thread::sleep(std::time::Duration::from_secs(40));
45+
// Show stop time
46+
let stop = std::time::SystemTime::now()
47+
.duration_since(std::time::UNIX_EPOCH)
48+
.unwrap()
49+
.as_secs();
50+
println!("Stop Time: {}", stop);
5351

54-
agent.stop()?;
52+
// Stop Agent
53+
let agent_ready = agent_running.stop()?;
5554

56-
drop(agent);
55+
// Shutdown the Agent
56+
agent_ready.shutdown();
5757

5858
// Show program exit time
5959
let exit = std::time::SystemTime::now()
6060
.duration_since(std::time::UNIX_EPOCH)
6161
.unwrap()
6262
.as_secs();
63-
6463
println!("Exit Time: {}", exit);
6564

6665
Ok(())

examples/internal/rbspy-connect.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn main() -> Result<()> {
2121
.lock_process(true)
2222
.with_subprocesses(true);
2323

24-
let mut agent = PyroscopeAgent::builder("http://localhost:4040", "rbspy.basic")
24+
let agent = PyroscopeAgent::builder("http://localhost:4040", "rbspy.basic")
2525
.tags([("Host", "Ruby")].to_vec())
2626
.backend(rbspy_backend(config))
2727
.build()?;
@@ -34,21 +34,29 @@ fn main() -> Result<()> {
3434
println!("Start Time: {}", start);
3535

3636
// Start Agent
37-
agent.start()?;
37+
let agent_running = agent.start()?;
3838

3939
// Profile for around 1 minute
40-
std::thread::sleep(std::time::Duration::from_secs(120));
40+
std::thread::sleep(std::time::Duration::from_secs(60));
4141

42-
agent.stop()?;
42+
// Show stop time
43+
let stop = std::time::SystemTime::now()
44+
.duration_since(std::time::UNIX_EPOCH)
45+
.unwrap()
46+
.as_secs();
47+
println!("Stop Time: {}", stop);
4348

44-
drop(agent);
49+
// Stop Agent
50+
let agent_ready = agent_running.stop()?;
51+
52+
// Shutdown the Agent
53+
agent_ready.shutdown();
4554

4655
// Show program exit time
4756
let exit = std::time::SystemTime::now()
4857
.duration_since(std::time::UNIX_EPOCH)
4958
.unwrap()
5059
.as_secs();
51-
5260
println!("Exit Time: {}", exit);
5361

5462
Ok(())

examples/tags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extern crate pyroscope;
22

3-
use pyroscope::{backend::Tag, PyroscopeAgent, Result};
3+
use pyroscope::{PyroscopeAgent, Result};
44
use pyroscope_pprofrs::{pprof_backend, PprofConfig};
55
use std::hash::{Hash, Hasher};
66

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//!
77
//! ```toml
88
//! [dependencies]
9-
//! pyroscope = "0.4"
9+
//! pyroscope = "0.5"
1010
//! pyroscope-pprofrs = "0.1"
1111
//! ```
1212
//!

src/pyroscope.rs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ impl PyroscopeAgentBuilder {
191191
session_manager,
192192
tx: None,
193193
handle: None,
194-
running: Arc::new((Mutex::new(false), Condvar::new())),
194+
running: Arc::new((
195+
#[allow(clippy::mutex_atomic)]
196+
Mutex::new(false),
197+
Condvar::new(),
198+
)),
195199
_state: PhantomData,
196200
})
197201
}
@@ -208,16 +212,21 @@ impl PyroscopeAgentState for PyroscopeAgentRunning {}
208212
/// PyroscopeAgent is the main object of the library. It is used to start and stop the profiler, schedule the timer, and send the profiler data to the server.
209213
#[derive(Debug)]
210214
pub struct PyroscopeAgent<S: PyroscopeAgentState> {
215+
/// Instance of the Timer
211216
timer: Timer,
217+
/// Instance of the SessionManager
212218
session_manager: SessionManager,
219+
/// Channel sender for the timer thread
213220
tx: Option<Sender<TimerSignal>>,
221+
/// Handle to the thread that runs the Pyroscope Agent
214222
handle: Option<JoinHandle<Result<()>>>,
223+
/// A structure to signal thread termination
215224
running: Arc<(Mutex<bool>, Condvar)>,
216-
217225
/// Profiler backend
218226
pub backend: BackendImpl<BackendReady>,
219227
/// Configuration Object
220228
pub config: PyroscopeConfig,
229+
/// PyroscopeAgent State
221230
_state: PhantomData<S>,
222231
}
223232

@@ -280,7 +289,7 @@ impl<S: PyroscopeAgentState> PyroscopeAgent<S> {
280289
}
281290
}
282291

283-
log::debug!(target: LOG_TAG, "Agent Dropped");
292+
log::debug!(target: LOG_TAG, "Agent Shutdown");
284293
}
285294
}
286295

@@ -387,7 +396,8 @@ impl PyroscopeAgent<PyroscopeAgentRunning> {
387396
// get tx and send termination signal
388397
if let Some(sender) = self.tx.take() {
389398
// Send last session
390-
let _ = sender.send(TimerSignal::NextSnapshot(get_time_range(0)?.until));
399+
sender.send(TimerSignal::NextSnapshot(get_time_range(0)?.until))?;
400+
// Terminate PyroscopeAgent internal thread
391401
sender.send(TimerSignal::Terminate)?;
392402
} else {
393403
log::error!("PyroscopeAgent - Missing sender")
@@ -398,20 +408,6 @@ impl PyroscopeAgent<PyroscopeAgentRunning> {
398408
let (lock, cvar) = &*pair;
399409
let _guard = cvar.wait_while(lock.lock()?, |running| *running)?;
400410

401-
// Create a clone of Backend
402-
//let backend = Arc::clone(&self.backend);
403-
404-
//let agent_running = PyroscopeAgent {
405-
//timer: self.timer,
406-
//session_manager: self.session_manager,
407-
//tx: self.tx,
408-
//handle: self.handle,
409-
//running: self.running,
410-
//backend: self.backend,
411-
//config: self.config,
412-
//_state: PhantomData,
413-
//};
414-
415411
Ok(self.transition())
416412
}
417413

@@ -444,29 +440,28 @@ impl PyroscopeAgent<PyroscopeAgentRunning> {
444440
)
445441
}
446442

447-
// TODO: change &mut self to &self
448-
pub fn add_global_tag(&mut self, tag: Tag) -> Result<()> {
443+
pub fn add_global_tag(&self, tag: Tag) -> Result<()> {
449444
let rule = Rule::GlobalTag(tag);
450445
self.backend.add_rule(rule)?;
451446

452447
Ok(())
453448
}
454449

455-
pub fn remove_global_tag(&mut self, tag: Tag) -> Result<()> {
450+
pub fn remove_global_tag(&self, tag: Tag) -> Result<()> {
456451
let rule = Rule::GlobalTag(tag);
457452
self.backend.remove_rule(rule)?;
458453

459454
Ok(())
460455
}
461456

462-
pub fn add_thread_tag(&mut self, thread_id: u64, tag: Tag) -> Result<()> {
457+
pub fn add_thread_tag(&self, thread_id: u64, tag: Tag) -> Result<()> {
463458
let rule = Rule::ThreadTag(thread_id, tag);
464459
self.backend.add_rule(rule)?;
465460

466461
Ok(())
467462
}
468463

469-
pub fn remove_thread_tag(&mut self, thread_id: u64, tag: Tag) -> Result<()> {
464+
pub fn remove_thread_tag(&self, thread_id: u64, tag: Tag) -> Result<()> {
470465
let rule = Rule::ThreadTag(thread_id, tag);
471466
self.backend.remove_rule(rule)?;
472467

src/utils.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use crate::backend::Tag;
22
use crate::{error::Result, PyroscopeError};
33

4-
use std::collections::HashMap;
5-
64
/// Format application_name with tags.
75
pub fn merge_tags_with_app_name(application_name: String, tags: Vec<Tag>) -> Result<String> {
86
// tags empty, return application_name

0 commit comments

Comments
 (0)