Skip to content

Commit b93c41c

Browse files
committed
wip: FFI update
1 parent 6ff6f85 commit b93c41c

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

pyroscope_ffi/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ name = "pyroscope_ffi"
1818
crate-type = ["cdylib"]
1919

2020
[dependencies]
21+
pyroscope = { path = "../" }
22+
pyroscope_backends = { path = "../pyroscope_backends" }

pyroscope_ffi/src/ffi.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use crate::PyroscopeAgent;
2-
use pyroscope_backends::pyspy::Pyspy;
1+
use pyroscope::PyroscopeAgent;
2+
use pyroscope_backends::pyspy::PyspyConfig;
33
use pyroscope_backends::rbspy::Rbspy;
4+
use pyroscope_backends::{pyspy::Pyspy, rbspy::RbspyConfig};
45

56
use std::sync::{Arc, Mutex};
67

@@ -16,12 +17,14 @@ pub fn add(x: i32, y: i32) -> i32 {
1617
#[no_mangle]
1718
pub fn initialize_agent(pid: i32) -> bool {
1819
std::thread::spawn(move || {
20+
let config = RbspyConfig::new(pid, 100, false, None, true);
21+
1922
let mut agent = PyroscopeAgent::builder("http://localhost:4040", "rbspy.basic")
20-
.backend(Rbspy::new(pid))
23+
.backend(Rbspy::new(config))
2124
.build()
2225
.unwrap();
2326

24-
agent.start();
27+
agent.start().unwrap();
2528

2629
// should instead block here until a stop signal is received
2730
loop {
@@ -36,13 +39,21 @@ pub fn initialize_agent(pid: i32) -> bool {
3639
#[no_mangle]
3740
pub fn initialize_python(pid: i32) -> bool {
3841
std::thread::spawn(move || {
42+
let config = PyspyConfig::new(pid)
43+
.sample_rate(100)
44+
.lock_process(true)
45+
.time_limit(None)
46+
.with_subprocesses(true)
47+
.include_idle(false)
48+
.native(false);
49+
3950
let mut agent = PyroscopeAgent::builder("http://localhost:4040", "python.basic")
40-
.backend(Pyspy::new(pid))
51+
.backend(Pyspy::new(config))
4152
.build()
4253
.unwrap();
4354
std::thread::sleep(std::time::Duration::from_millis(5000));
4455

45-
agent.start();
56+
agent.start().unwrap();
4657

4758
// should instead block here until a stop signal is received
4859
loop {

pyroscope_ffi/src/lib.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
#[cfg(test)]
2-
mod tests {
3-
#[test]
4-
fn it_works() {
5-
let result = 2 + 2;
6-
assert_eq!(result, 4);
7-
}
8-
}
1+
mod ffi;

0 commit comments

Comments
 (0)