Skip to content

Commit 2f03a84

Browse files
committed
imp(pprof): add sample_rate helper function to config builder
1 parent a6d9f78 commit 2f03a84

File tree

10 files changed

+26
-10
lines changed

10 files changed

+26
-10
lines changed

examples/async.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn hash_rounds2(n: u64) -> u64 {
3535
#[tokio::main]
3636
async fn main() -> Result<()> {
3737
let mut agent = PyroscopeAgent::builder("http://localhost:4040", "example.async")
38-
.backend(Pprof::new(PprofConfig::new(100)))
38+
.backend(Pprof::new(PprofConfig::new().sample_rate(100)))
3939
.tags([("TagA", "ValueA"), ("TagB", "ValueB")].to_vec())
4040
.build()?;
4141

examples/backend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn hash_rounds(n: u64) -> u64 {
2020

2121
fn main() -> Result<()> {
2222
let mut agent = PyroscopeAgent::builder("http://localhost:4040", "example.backend")
23-
.backend(Pprof::new(PprofConfig::new(113)))
23+
.backend(Pprof::new(PprofConfig::new().sample_rate(113)))
2424
.tags([("TagA", "ValueA"), ("TagB", "ValueB")].to_vec())
2525
.build()?;
2626

examples/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn hash_rounds(n: u64) -> u64 {
2020

2121
fn main() -> Result<()> {
2222
let mut agent = PyroscopeAgent::builder("http://localhost:4040", "example.basic")
23-
.backend(Pprof::new(PprofConfig::new(100)))
23+
.backend(Pprof::new(PprofConfig::new().sample_rate(100)))
2424
.tags([("TagA", "ValueA"), ("TagB", "ValueB")].to_vec())
2525
.build()?;
2626

examples/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn main() -> Result<()> {
1818
pretty_env_logger::init_timed();
1919

2020
let mut agent = PyroscopeAgent::builder("http://invalid_url", "example.error")
21-
.backend(Pprof::new(PprofConfig::new(100)))
21+
.backend(Pprof::new(PprofConfig::new().sample_rate(100)))
2222
.build()
2323
.unwrap();
2424
// Start Agent

examples/internal/backend-pprof.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn fibonacci(n: u64) -> u64 {
1313

1414
fn main() -> Result<()> {
1515
// Create Pprof configuration
16-
let backend_config = PprofConfig::new(113);
16+
let backend_config = PprofConfig::new().sample_rate(100);
1717

1818
// Create backend
1919
let mut backend = Pprof::new(backend_config);

examples/multi-thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn hash_rounds2(n: u64) -> u64 {
3838

3939
fn main() -> Result<()> {
4040
let mut agent = PyroscopeAgent::builder("http://localhost:4040", "example.multithread")
41-
.backend(Pprof::new(PprofConfig::new(100)))
41+
.backend(Pprof::new(PprofConfig::new().sample_rate(100)))
4242
.build()?;
4343

4444
// Start Agent

examples/tags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn hash_rounds(n: u64) -> u64 {
2020

2121
fn main() -> Result<()> {
2222
let mut agent = PyroscopeAgent::builder("http://localhost:4040", "example.tags")
23-
.backend(Pprof::new(PprofConfig::new(100)))
23+
.backend(Pprof::new(PprofConfig::new().sample_rate(100)))
2424
.tags([("Hostname", "pyroscope")].to_vec())
2525
.build()?;
2626

examples/with-logger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() -> Result<()> {
3131

3232
// Create a new agent.
3333
let mut agent = PyroscopeAgent::builder("http://localhost:4040", "example.logger")
34-
.backend(Pprof::new(PprofConfig::new(100)))
34+
.backend(Pprof::new(PprofConfig::new().sample_rate(100)))
3535
.build()?;
3636

3737
// Start Agent

pyroscope_backends/pyroscope_pprofrs/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ impl Default for PprofConfig {
1818
}
1919

2020
impl PprofConfig {
21-
pub fn new(sample_rate: u32) -> Self {
22-
PprofConfig { sample_rate }
21+
pub fn new() -> Self {
22+
PprofConfig::default()
23+
}
24+
25+
pub fn sample_rate(self, sample_rate: u32) -> Self {
26+
PprofConfig {
27+
sample_rate,
28+
..self
29+
}
2330
}
2431
}
2532

src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22
//!
33
//! # Quick Start
44
//!
5+
//! ## Add Pyroscope and pprof-rs backend to Cargo.toml
6+
//!
7+
//! ```toml
8+
//! [dependencies]
9+
//! pyroscope = "0.4"
10+
//! pyroscope-pprofrs = "0.1"
11+
//! ```
12+
//!
513
//! ## Configure a Pyroscope Agent
614
//!
715
//! ```ignore
816
//! let mut agent =
917
//! PyroscopeAgent::builder("http://localhost:4040", "myapp")
18+
//! .backend(Pprof::new(PprofConfig::new().sample_rate(100)))
1019
//! .build()?;
1120
//! ```
1221
//!

0 commit comments

Comments
 (0)