Skip to content

Commit 500d4a4

Browse files
authored
Merge pull request #56 from pyroscope-io/0.5.4
0.5.4
2 parents 66b592b + 6abac67 commit 500d4a4

File tree

15 files changed

+155
-52
lines changed

15 files changed

+155
-52
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"

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ log = "0.4"
5656
names = "0.13.0"
5757
reqwest = { version = "0.11", features = ["blocking", "rustls-tls-native-roots"]}
5858
url = "2.2.2"
59+
libflate = "1.2.0"
5960
libc = "^0.2.124"
6061

6162
[dev-dependencies]

examples/internal/pyspy-connect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ fn main() -> Result<()> {
2020
.sample_rate(100)
2121
.lock_process(true)
2222
.time_limit(None)
23-
.with_subprocesses(true)
24-
.include_idle(false)
23+
.detect_subprocesses(true)
24+
.oncpu(false)
2525
.native(false);
2626

2727
let agent = PyroscopeAgent::builder("http://localhost:4040", "pyspy.basic")

examples/internal/rbspy-connect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main() -> Result<()> {
1919
let config = RbspyConfig::new(pid)
2020
.sample_rate(100)
2121
.lock_process(true)
22-
.with_subprocesses(true);
22+
.detect_subprocesses(true);
2323

2424
let agent = PyroscopeAgent::builder("http://localhost:4040", "rbspy.basic")
2525
.tags([("Host", "Ruby")].to_vec())

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(())

pyroscope_ffi/python/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = pyroscope-io
3-
version= 0.7.2
3+
version= 0.7.3
44
description = Pyroscope Python integration
55
long_description = file: README.md
66
long_description_content_type = text/markdown

pyroscope_ffi/ruby/ext/rbspy/src/lib.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
use ffikit::Signal;
2-
use pyroscope::backend::{Report, StackFrame, Tag};
3-
use pyroscope::PyroscopeAgent;
4-
use pyroscope_rbspy::{rbspy_backend, RbspyConfig};
51
use std::collections::hash_map::DefaultHasher;
62
use std::env;
73
use std::ffi::CStr;
84
use std::hash::Hasher;
95
use std::os::raw::c_char;
6+
use std::str::FromStr;
7+
8+
use ffikit::Signal;
9+
use pyroscope_rbspy::{rbspy_backend, RbspyConfig};
10+
11+
use pyroscope::{pyroscope::Compression, PyroscopeAgent};
12+
use pyroscope::backend::{Report, StackFrame, Tag};
1013

1114
pub fn transform_report(report: Report) -> Report {
1215
let cwd = env::current_dir().unwrap();
@@ -104,7 +107,7 @@ pub extern "C" fn initialize_logging(logging_level: u32) -> bool {
104107
pub extern "C" fn initialize_agent(
105108
application_name: *const c_char, server_address: *const c_char, auth_token: *const c_char,
106109
sample_rate: u32, detect_subprocesses: bool, oncpu: bool, report_pid: bool,
107-
report_thread_id: bool, tags: *const c_char,
110+
report_thread_id: bool, tags: *const c_char, compression: *const c_char
108111
) -> bool {
109112
// Initialize FFIKit
110113
let recv = ffikit::initialize_ffi().unwrap();
@@ -129,6 +132,13 @@ pub extern "C" fn initialize_agent(
129132
.unwrap()
130133
.to_string();
131134

135+
let compression_string = unsafe { CStr::from_ptr(compression) }
136+
.to_str()
137+
.unwrap()
138+
.to_string();
139+
140+
let compression = Compression::from_str(&compression_string);
141+
132142
let pid = std::process::id();
133143

134144
let rbspy_config = RbspyConfig::new(pid.try_into().unwrap())
@@ -152,6 +162,10 @@ pub extern "C" fn initialize_agent(
152162
agent_builder = agent_builder.auth_token(auth_token);
153163
}
154164

165+
if let Ok(compression) = compression {
166+
agent_builder = agent_builder.compression(compression);
167+
}
168+
155169
let agent = agent_builder.build().unwrap();
156170

157171
let agent_running = agent.start().unwrap();

pyroscope_ffi/ruby/lib/pyroscope.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Rust
88
extend FFI::Library
99
ffi_lib File.expand_path(File.dirname(__FILE__)) + "/rbspy/rbspy.#{RbConfig::CONFIG["DLEXT"]}"
1010
attach_function :initialize_logging, [:int], :bool
11-
attach_function :initialize_agent, [:string, :string, :string, :int, :bool, :bool, :bool, :bool, :string], :bool
11+
attach_function :initialize_agent, [:string, :string, :string, :int, :bool, :bool, :bool, :bool, :string, :string], :bool
1212
attach_function :add_thread_tag, [:uint64, :string, :string], :bool
1313
attach_function :remove_thread_tag, [:uint64, :string, :string], :bool
1414
attach_function :add_global_tag, [:string, :string], :bool
@@ -22,8 +22,10 @@ module Utils
2222
attach_function :thread_id, [], :uint64
2323
end
2424

25-
Config = Struct.new(:application_name, :app_name, :server_address, :auth_token, :log_level, :sample_rate, :detect_subprocesses, :oncpu, :report_pid, :report_thread_id, :tags) do
25+
Config = Struct.new(:application_name, :app_name, :server_address, :auth_token, :log_level, :sample_rate, :detect_subprocesses, :oncpu, :report_pid, :report_thread_id, :tags, :compression) do
2626
def initialize(*)
27+
super
28+
# defaults:
2729
self.application_name = ''
2830
self.server_address = 'http://localhost:4040'
2931
self.auth_token = ''
@@ -34,7 +36,7 @@ def initialize(*)
3436
self.report_thread_id = false
3537
self.log_level = 'error'
3638
self.tags = {}
37-
super
39+
self.compression = 'gzip'
3840
end
3941
end
4042

@@ -63,10 +65,11 @@ def configure
6365

6466
# Initialize Logging
6567
Rust.initialize_logging(@log_level)
66-
68+
6769

6870
# initialize Pyroscope Agent
6971
Rust.initialize_agent(
72+
# these are defaults in case user-provided values are nil:
7073
@config.app_name || @config.application_name || "",
7174
@config.server_address || "",
7275
@config.auth_token || "",
@@ -75,7 +78,8 @@ def configure
7578
@config.oncpu || false,
7679
@config.report_pid || false,
7780
@config.report_thread_id || false,
78-
tags_to_string(@config.tags || {})
81+
tags_to_string(@config.tags || {}),
82+
@config.compression || ""
7983
)
8084
end
8185

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Pyroscope
2-
VERSION = '0.3.2'.freeze
2+
VERSION = '0.4.1'.freeze
33
end

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

0 commit comments

Comments
 (0)