Skip to content

Commit 62b3c25

Browse files
committed
imp(ruby): add regex support
1 parent 7ab6760 commit 62b3c25

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

pyroscope_ffi/ruby/ext/rbspy/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pyroscope = { path = "../../../../" }
1414
pyroscope_rbspy = { path = "../../../../pyroscope_backends/pyroscope_rbspy" }
1515
ffikit = { path = "../../../ffikit" }
1616
pretty_env_logger = "0.4.0"
17+
regex = "1"
1718

1819
[patch.crates-io]
1920
read-process-memory = {git = "https://github.com/omarabid/read-process-memory.git", branch = "0.1.4-fix"}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use std::os::raw::c_char;
1010
#[no_mangle]
1111
pub extern "C" fn initialize_agent(
1212
application_name: *const c_char, server_address: *const c_char, auth_token: *const c_char,
13-
sample_rate: u32, detect_subprocesses: bool, on_cpu: bool, report_pid: bool,
14-
report_thread_id: bool, tags: *const c_char,
13+
directory_name: *const c_char, sample_rate: u32, detect_subprocesses: bool, on_cpu: bool,
14+
report_pid: bool, report_thread_id: bool, tags: *const c_char,
1515
) -> bool {
1616
// Initialize FFIKit
1717
let recv = ffikit::initialize_ffi().unwrap();
@@ -31,6 +31,11 @@ pub extern "C" fn initialize_agent(
3131
.unwrap()
3232
.to_string();
3333

34+
let directory_name = unsafe { CStr::from_ptr(directory_name) }
35+
.to_str()
36+
.unwrap()
37+
.to_string();
38+
3439
let tags_string = unsafe { CStr::from_ptr(tags) }
3540
.to_str()
3641
.unwrap()
@@ -52,6 +57,7 @@ pub extern "C" fn initialize_agent(
5257

5358
let mut agent_builder = PyroscopeAgent::builder(server_address, application_name)
5459
.backend(rbspy)
60+
.regex(regex::Regex::new(&directory_name).unwrap())
5561
.tags(tags);
5662

5763
if auth_token != "" {

pyroscope_ffi/ruby/lib/pyroscope.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Pyroscope
44
module Rust
55
extend FFI::Library
66
ffi_lib File.expand_path(File.dirname(__FILE__)) + "/rbspy/rbspy.#{RbConfig::CONFIG["DLEXT"]}"
7-
attach_function :initialize_agent, [:string, :string, :string, :int, :bool, :bool, :bool, :bool, :string], :bool
7+
attach_function :initialize_agent, [:string, :string, :string, :string, :int, :bool, :bool, :bool, :bool, :string], :bool
88
attach_function :add_thread_tag, [:uint64, :string, :string], :bool
99
attach_function :remove_thread_tag, [:uint64, :string, :string], :bool
1010
attach_function :add_global_tag, [:string, :string], :bool
@@ -18,11 +18,12 @@ module Utils
1818
attach_function :thread_id, [], :uint64
1919
end
2020

21-
Config = Struct.new(:application_name, :app_name, :server_address, :auth_token, :sample_rate, :detect_subprocesses, :on_cpu, :report_pid, :report_thread_id, :log_level, :tags) do
21+
Config = Struct.new(:application_name, :app_name, :server_address, :auth_token, :directory_name, :sample_rate, :detect_subprocesses, :on_cpu, :report_pid, :report_thread_id, :log_level, :tags) do
2222
def initialize(*)
2323
self.application_name = ''
2424
self.server_address = 'http://localhost:4040'
2525
self.auth_token = ''
26+
self.directory_name = __dir__
2627
self.sample_rate = 100
2728
self.detect_subprocesses = false
2829
self.on_cpu = true
@@ -45,6 +46,7 @@ def configure
4546
@config.app_name || @config.application_name || "",
4647
@config.server_address || "",
4748
@config.auth_token || "",
49+
@config.directory_name || __dir__,
4850
@config.sample_rate || 100,
4951
@config.detect_subprocesses || false,
5052
@config.on_cpu || false,

0 commit comments

Comments
 (0)