pyroscope 0.3.0-arm64-darwin → 0.3.1-arm64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/elflib/rbspy/manylinux.sh +8 -8
- data/elflib/thread_id/manylinux.sh +8 -8
- data/ext/rbspy/Cargo.toml +2 -0
- data/ext/rbspy/src/lib.rs +85 -70
- data/lib/pyroscope/version.rb +1 -1
- data/lib/pyroscope.rb +62 -59
- data/lib/rbspy/rbspy.bundle +0 -0
- data/lib/thread_id/thread_id.bundle +0 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b7eb0f69ff31b3fc5a6ac437cb4c4190da57cdfea4e81e87956259fcc2f19de
|
4
|
+
data.tar.gz: 9eab2b1c0dd80f29ccf88d9a6e52c37093b0effd70d54eb6fb718546f375453e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95f3c03936e81ffb9b1ee5fe3632c01e822548305d691db28ba721411e4ccba3964197aeee71b7d17ed6e771991441da03f50015108786ad0e05b5dd6d961905
|
7
|
+
data.tar.gz: 0d411ee574f66eb488bc05f905ec52142061374e2bcdde83d028cb120b4f58167444b88dfa24b8fb5f343f1263ad12771b794f0da73f79a636d8f97ed3df4b3d
|
data/elflib/rbspy/manylinux.sh
CHANGED
@@ -2,20 +2,20 @@
|
|
2
2
|
set -e
|
3
3
|
|
4
4
|
# Install tooling
|
5
|
-
|
5
|
+
yum -y -q install wget gcc libffi-devel openssl-devel
|
6
6
|
|
7
7
|
# Install Rust
|
8
|
-
|
9
|
-
|
8
|
+
curl https://sh.rustup.rs -sSf | sh -s -- -y
|
9
|
+
export PATH=~/.cargo/bin:$PATH
|
10
10
|
|
11
11
|
# Build wheels
|
12
|
-
|
12
|
+
/opt/python/cp37-cp37m/bin/python setup.py bdist_wheel
|
13
13
|
|
14
14
|
# Audit wheels
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
for wheel in dist/*.whl; do
|
16
|
+
auditwheel repair $wheel -w dist/
|
17
|
+
rm $wheel
|
18
|
+
done
|
19
19
|
|
20
20
|
# Extract wheels
|
21
21
|
for wheel in dist/*.whl; do
|
@@ -2,20 +2,20 @@
|
|
2
2
|
set -e
|
3
3
|
|
4
4
|
# Install tooling
|
5
|
-
|
5
|
+
yum -y -q install wget gcc libffi-devel openssl-devel
|
6
6
|
|
7
7
|
# Install Rust
|
8
|
-
|
9
|
-
|
8
|
+
curl https://sh.rustup.rs -sSf | sh -s -- -y
|
9
|
+
export PATH=~/.cargo/bin:$PATH
|
10
10
|
|
11
11
|
# Build wheels
|
12
|
-
|
12
|
+
/opt/python/cp37-cp37m/bin/python setup.py bdist_wheel
|
13
13
|
|
14
14
|
# Audit wheels
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
for wheel in dist/*.whl; do
|
16
|
+
auditwheel repair $wheel -w dist/
|
17
|
+
rm $wheel
|
18
|
+
done
|
19
19
|
|
20
20
|
# Extract wheels
|
21
21
|
for wheel in dist/*.whl; do
|
data/ext/rbspy/Cargo.toml
CHANGED
@@ -12,6 +12,8 @@ crate-type = ["cdylib"]
|
|
12
12
|
pyroscope = { path = "../../../../" }
|
13
13
|
#pyroscope_rbspy = { version = "0.2" }
|
14
14
|
pyroscope_rbspy = { path = "../../../../pyroscope_backends/pyroscope_rbspy" }
|
15
|
+
ffikit = { path = "../../../ffikit" }
|
16
|
+
pretty_env_logger = "0.4.0"
|
15
17
|
|
16
18
|
[patch.crates-io]
|
17
19
|
read-process-memory = {git = "https://github.com/omarabid/read-process-memory.git", branch = "0.1.4-fix"}
|
data/ext/rbspy/src/lib.rs
CHANGED
@@ -1,38 +1,11 @@
|
|
1
|
+
use ffikit::Signal;
|
1
2
|
use pyroscope::backend::Tag;
|
2
3
|
use pyroscope::PyroscopeAgent;
|
3
4
|
use pyroscope_rbspy::{rbspy_backend, RbspyConfig};
|
5
|
+
use std::collections::hash_map::DefaultHasher;
|
4
6
|
use std::ffi::CStr;
|
5
|
-
use std::
|
7
|
+
use std::hash::Hasher;
|
6
8
|
use std::os::raw::c_char;
|
7
|
-
use std::sync::mpsc::{sync_channel, Receiver, SyncSender};
|
8
|
-
use std::sync::{Mutex, Once};
|
9
|
-
|
10
|
-
pub enum Signal {
|
11
|
-
Kill,
|
12
|
-
AddTag(u64, String, String),
|
13
|
-
RemoveTag(u64, String, String),
|
14
|
-
}
|
15
|
-
|
16
|
-
pub struct SignalPass {
|
17
|
-
inner_sender: Mutex<SyncSender<Signal>>,
|
18
|
-
inner_receiver: Mutex<Receiver<Signal>>,
|
19
|
-
}
|
20
|
-
|
21
|
-
fn signalpass() -> &'static SignalPass {
|
22
|
-
static mut SIGNAL_PASS: MaybeUninit<SignalPass> = MaybeUninit::uninit();
|
23
|
-
static ONCE: Once = Once::new();
|
24
|
-
|
25
|
-
ONCE.call_once(|| unsafe {
|
26
|
-
let (sender, receiver) = sync_channel(1);
|
27
|
-
let singleton = SignalPass {
|
28
|
-
inner_sender: Mutex::new(sender),
|
29
|
-
inner_receiver: Mutex::new(receiver),
|
30
|
-
};
|
31
|
-
SIGNAL_PASS = MaybeUninit::new(singleton);
|
32
|
-
});
|
33
|
-
|
34
|
-
unsafe { SIGNAL_PASS.assume_init_ref() }
|
35
|
-
}
|
36
9
|
|
37
10
|
#[no_mangle]
|
38
11
|
pub extern "C" fn initialize_agent(
|
@@ -40,6 +13,9 @@ pub extern "C" fn initialize_agent(
|
|
40
13
|
sample_rate: u32, detect_subprocesses: bool, on_cpu: bool, report_pid: bool,
|
41
14
|
report_thread_id: bool, tags: *const c_char,
|
42
15
|
) -> bool {
|
16
|
+
// Initialize FFIKit
|
17
|
+
let recv = ffikit::initialize_ffi().unwrap();
|
18
|
+
|
43
19
|
let application_name = unsafe { CStr::from_ptr(application_name) }
|
44
20
|
.to_str()
|
45
21
|
.unwrap()
|
@@ -62,44 +38,50 @@ pub extern "C" fn initialize_agent(
|
|
62
38
|
|
63
39
|
let pid = std::process::id();
|
64
40
|
|
65
|
-
let
|
41
|
+
let rbspy_config = RbspyConfig::new(pid.try_into().unwrap())
|
42
|
+
.sample_rate(sample_rate)
|
43
|
+
.lock_process(false)
|
44
|
+
.with_subprocesses(detect_subprocesses)
|
45
|
+
.on_cpu(on_cpu)
|
46
|
+
.report_pid(report_pid)
|
47
|
+
.report_thread_id(report_thread_id);
|
66
48
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
.report_thread_id(report_thread_id);
|
75
|
-
|
76
|
-
let tags_ref = tags_string.as_str();
|
77
|
-
let tags = string_to_tags(tags_ref);
|
78
|
-
let rbspy = rbspy_backend(rbspy_config);
|
79
|
-
|
80
|
-
let mut agent_builder = PyroscopeAgent::builder(server_address, application_name)
|
81
|
-
.backend(rbspy)
|
82
|
-
.tags(tags);
|
83
|
-
|
84
|
-
if auth_token != "" {
|
85
|
-
agent_builder = agent_builder.auth_token(auth_token);
|
86
|
-
}
|
49
|
+
let tags_ref = tags_string.as_str();
|
50
|
+
let tags = string_to_tags(tags_ref);
|
51
|
+
let rbspy = rbspy_backend(rbspy_config);
|
52
|
+
|
53
|
+
let mut agent_builder = PyroscopeAgent::builder(server_address, application_name)
|
54
|
+
.backend(rbspy)
|
55
|
+
.tags(tags);
|
87
56
|
|
88
|
-
|
57
|
+
if auth_token != "" {
|
58
|
+
agent_builder = agent_builder.auth_token(auth_token);
|
59
|
+
}
|
60
|
+
|
61
|
+
let agent = agent_builder.build().unwrap();
|
89
62
|
|
90
|
-
|
63
|
+
let agent_running = agent.start().unwrap();
|
91
64
|
|
92
|
-
|
65
|
+
std::thread::spawn(move || {
|
66
|
+
while let Ok(signal) = recv.recv() {
|
93
67
|
match signal {
|
94
68
|
Signal::Kill => {
|
95
69
|
agent_running.stop().unwrap();
|
96
70
|
break;
|
97
71
|
}
|
98
|
-
Signal::
|
72
|
+
Signal::AddGlobalTag(name, value) => {
|
73
|
+
agent_running.add_global_tag(Tag::new(name, value)).unwrap();
|
74
|
+
}
|
75
|
+
Signal::RemoveGlobalTag(name, value) => {
|
76
|
+
agent_running
|
77
|
+
.remove_global_tag(Tag::new(name, value))
|
78
|
+
.unwrap();
|
79
|
+
}
|
80
|
+
Signal::AddThreadTag(thread_id, key, value) => {
|
99
81
|
let tag = Tag::new(key, value);
|
100
82
|
agent_running.add_thread_tag(thread_id, tag).unwrap();
|
101
83
|
}
|
102
|
-
Signal::
|
84
|
+
Signal::RemoveThreadTag(thread_id, key, value) => {
|
103
85
|
let tag = Tag::new(key, value);
|
104
86
|
agent_running.remove_thread_tag(thread_id, tag).unwrap();
|
105
87
|
}
|
@@ -112,40 +94,73 @@ pub extern "C" fn initialize_agent(
|
|
112
94
|
|
113
95
|
#[no_mangle]
|
114
96
|
pub extern "C" fn drop_agent() -> bool {
|
115
|
-
|
116
|
-
|
97
|
+
// Send Kill signal to the FFI merge channel.
|
98
|
+
ffikit::send(ffikit::Signal::Kill).unwrap();
|
99
|
+
|
117
100
|
true
|
118
101
|
}
|
119
102
|
|
120
103
|
#[no_mangle]
|
121
|
-
pub extern "C" fn
|
122
|
-
let s = signalpass();
|
104
|
+
pub extern "C" fn add_thread_tag(thread_id: u64, key: *const c_char, value: *const c_char) -> bool {
|
123
105
|
let key = unsafe { CStr::from_ptr(key) }.to_str().unwrap().to_owned();
|
124
106
|
let value = unsafe { CStr::from_ptr(value) }
|
125
107
|
.to_str()
|
126
108
|
.unwrap()
|
127
109
|
.to_owned();
|
128
|
-
|
129
|
-
|
110
|
+
|
111
|
+
let pid = std::process::id();
|
112
|
+
let mut hasher = DefaultHasher::new();
|
113
|
+
hasher.write_u64(thread_id % pid as u64);
|
114
|
+
let id = hasher.finish();
|
115
|
+
|
116
|
+
ffikit::send(ffikit::Signal::AddThreadTag(id, key, value)).unwrap();
|
117
|
+
|
118
|
+
true
|
119
|
+
}
|
120
|
+
|
121
|
+
#[no_mangle]
|
122
|
+
pub extern "C" fn remove_thread_tag(
|
123
|
+
thread_id: u64, key: *const c_char, value: *const c_char,
|
124
|
+
) -> bool {
|
125
|
+
let key = unsafe { CStr::from_ptr(key) }.to_str().unwrap().to_owned();
|
126
|
+
let value = unsafe { CStr::from_ptr(value) }
|
127
|
+
.to_str()
|
130
128
|
.unwrap()
|
131
|
-
.
|
132
|
-
|
129
|
+
.to_owned();
|
130
|
+
|
131
|
+
let pid = std::process::id();
|
132
|
+
let mut hasher = DefaultHasher::new();
|
133
|
+
hasher.write_u64(thread_id % pid as u64);
|
134
|
+
let id = hasher.finish();
|
135
|
+
|
136
|
+
ffikit::send(ffikit::Signal::RemoveThreadTag(id, key, value)).unwrap();
|
137
|
+
|
133
138
|
true
|
134
139
|
}
|
135
140
|
|
136
141
|
#[no_mangle]
|
137
|
-
pub extern "C" fn
|
138
|
-
let s = signalpass();
|
142
|
+
pub extern "C" fn add_global_tag(key: *const c_char, value: *const c_char) -> bool {
|
139
143
|
let key = unsafe { CStr::from_ptr(key) }.to_str().unwrap().to_owned();
|
140
144
|
let value = unsafe { CStr::from_ptr(value) }
|
141
145
|
.to_str()
|
142
146
|
.unwrap()
|
143
147
|
.to_owned();
|
144
|
-
|
145
|
-
|
148
|
+
|
149
|
+
ffikit::send(ffikit::Signal::AddGlobalTag(key, value)).unwrap();
|
150
|
+
|
151
|
+
true
|
152
|
+
}
|
153
|
+
|
154
|
+
#[no_mangle]
|
155
|
+
pub extern "C" fn remove_global_tag(key: *const c_char, value: *const c_char) -> bool {
|
156
|
+
let key = unsafe { CStr::from_ptr(key) }.to_str().unwrap().to_owned();
|
157
|
+
let value = unsafe { CStr::from_ptr(value) }
|
158
|
+
.to_str()
|
146
159
|
.unwrap()
|
147
|
-
.
|
148
|
-
|
160
|
+
.to_owned();
|
161
|
+
|
162
|
+
ffikit::send(ffikit::Signal::RemoveGlobalTag(key, value)).unwrap();
|
163
|
+
|
149
164
|
true
|
150
165
|
}
|
151
166
|
|
data/lib/pyroscope/version.rb
CHANGED
data/lib/pyroscope.rb
CHANGED
@@ -1,34 +1,36 @@
|
|
1
1
|
require 'ffi'
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module Pyroscope
|
4
|
+
module Rust
|
5
|
+
extend FFI::Library
|
6
|
+
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
|
8
|
+
attach_function :add_thread_tag, [:uint64, :string, :string], :bool
|
9
|
+
attach_function :remove_thread_tag, [:uint64, :string, :string], :bool
|
10
|
+
attach_function :add_global_tag, [:string, :string], :bool
|
11
|
+
attach_function :remove_global_tag, [:string, :string], :bool
|
12
|
+
attach_function :drop_agent, [], :bool
|
13
|
+
end
|
11
14
|
|
12
|
-
module Utils
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
15
|
+
module Utils
|
16
|
+
extend FFI::Library
|
17
|
+
ffi_lib File.expand_path(File.dirname(__FILE__)) + "/thread_id/thread_id.#{RbConfig::CONFIG["DLEXT"]}"
|
18
|
+
attach_function :thread_id, [], :uint64
|
19
|
+
end
|
17
20
|
|
18
|
-
module Pyroscope
|
19
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
|
20
22
|
def initialize(*)
|
23
|
+
self.application_name = ''
|
24
|
+
self.server_address = 'http://localhost:4040'
|
25
|
+
self.auth_token = ''
|
26
|
+
self.sample_rate = 100
|
27
|
+
self.detect_subprocesses = false
|
28
|
+
self.on_cpu = true
|
29
|
+
self.report_pid = false
|
30
|
+
self.report_thread_id = false
|
31
|
+
self.log_level = 'info'
|
32
|
+
self.tags = {}
|
21
33
|
super
|
22
|
-
self.application_name ||= ''
|
23
|
-
self.server_address ||= 'http://localhost:4040'
|
24
|
-
self.auth_token ||= ''
|
25
|
-
self.sample_rate ||= 100
|
26
|
-
self.detect_subprocesses ||= true
|
27
|
-
self.on_cpu ||= true
|
28
|
-
self.report_pid ||= false
|
29
|
-
self.report_thread_id ||= false
|
30
|
-
self.log_level ||= 'info'
|
31
|
-
self.tags ||= []
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
@@ -40,26 +42,25 @@ module Pyroscope
|
|
40
42
|
yield @config
|
41
43
|
|
42
44
|
Rust.initialize_agent(
|
43
|
-
@config.app_name || @config.application_name,
|
44
|
-
@config.server_address,
|
45
|
-
@config.auth_token,
|
46
|
-
@config.sample_rate,
|
47
|
-
@config.detect_subprocesses,
|
48
|
-
@config.on_cpu,
|
49
|
-
@config.report_pid,
|
50
|
-
@config.report_thread_id,
|
51
|
-
tags_to_string(@config.tags)
|
45
|
+
@config.app_name || @config.application_name || "",
|
46
|
+
@config.server_address || "",
|
47
|
+
@config.auth_token || "",
|
48
|
+
@config.sample_rate || 100,
|
49
|
+
@config.detect_subprocesses || false,
|
50
|
+
@config.on_cpu || false,
|
51
|
+
@config.report_pid || false,
|
52
|
+
@config.report_thread_id || false,
|
53
|
+
tags_to_string(@config.tags || {})
|
52
54
|
)
|
53
|
-
|
54
|
-
puts @config
|
55
55
|
end
|
56
56
|
|
57
57
|
def tag_wrapper(tags)
|
58
|
-
|
58
|
+
tid = thread_id
|
59
|
+
_add_tags(tid, tags)
|
59
60
|
begin
|
60
61
|
yield
|
61
62
|
ensure
|
62
|
-
|
63
|
+
_remove_tags(tid, tags)
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
@@ -67,31 +68,33 @@ module Pyroscope
|
|
67
68
|
warn("deprecated. Use `Pyroscope.tag_wrapper` instead.")
|
68
69
|
end
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
71
|
+
def remove_tags(*tags)
|
72
|
+
warn("deprecated. Use `Pyroscope.tag_wrapper` instead.")
|
73
|
+
end
|
74
74
|
|
75
|
-
#
|
76
|
-
def
|
77
|
-
|
78
|
-
end
|
75
|
+
# convert tags object to string
|
76
|
+
def tags_to_string(tags)
|
77
|
+
tags.map { |k, v| "#{k}=#{v}" }.join(',')
|
78
|
+
end
|
79
79
|
|
80
|
-
#
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
Rust.add_tag(thread_id, tag_name.to_s, tag_value.to_s)
|
85
|
-
end
|
86
|
-
end
|
80
|
+
# get thread id
|
81
|
+
def thread_id
|
82
|
+
return Utils.thread_id
|
83
|
+
end
|
87
84
|
|
88
|
-
#
|
89
|
-
def
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
85
|
+
# add tags
|
86
|
+
def _add_tags(thread_id, tags)
|
87
|
+
tags.each do |tag_name, tag_value|
|
88
|
+
Rust.add_thread_tag(thread_id, tag_name.to_s, tag_value.to_s)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# remove tags
|
93
|
+
def _remove_tags(thread_id, tags)
|
94
|
+
tags.each do |tag_name, tag_value|
|
95
|
+
Rust.remove_thread_tag(thread_id, tag_name.to_s, tag_value.to_s)
|
96
|
+
end
|
97
|
+
end
|
95
98
|
|
96
99
|
def drop
|
97
100
|
Rust.drop_agent
|
data/lib/rbspy/rbspy.bundle
CHANGED
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pyroscope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: arm64-darwin
|
6
6
|
authors:
|
7
7
|
- Pyroscope Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
|
-
rubygems_version: 3.
|
111
|
+
rubygems_version: 3.3.7
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Pyroscope
|