vivarium_usdt 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/vivarium_usdt/src/lib.rs +23 -31
- data/lib/vivarium/usdt.rb +3 -70
- data/lib/vivarium/usdt_version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '039e9979c37827b5da754ff8374271504fadd703e2b6675f9f362d840e930bfc'
|
|
4
|
+
data.tar.gz: 169e40666e700b76e63b3306ff70c8c1981ff25fc9069b550224f14a6c72964c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: af717d63fdf635b8b1904d45540eea1d8ad58eb24190ff0e0a8d45b2c9b04b08cc3204a7f89e5a3a89e24d4e40e869b7678b6d479e1ffc8926608520d6250a18
|
|
7
|
+
data.tar.gz: 9d70c8c830f898a91588799d2b4cac0a37f70ccfa0fb7069b5ddf33e57f3dc5b9f3c9b6efcb39202e6a686f06b920c62c53802192e334d5cf1d3c940e0d9d2d0
|
|
@@ -7,64 +7,56 @@ fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
|
7
7
|
module.define_singleton_method("invoke_start_probe", function!(invoke_start_probe, 3))?;
|
|
8
8
|
module.define_singleton_method("invoke_stop_probe", function!(invoke_stop_probe, 3))?;
|
|
9
9
|
module.define_singleton_method("invoke_raise_probe", function!(invoke_raise_probe, 4))?;
|
|
10
|
-
|
|
11
|
-
let kernel = ruby.module_kernel();
|
|
12
|
-
kernel.define_method(
|
|
13
|
-
"__helper_get_hash_from_name",
|
|
14
|
-
function!(__helper_get_hash_from_name, 1),
|
|
15
|
-
)?;
|
|
16
10
|
Ok(())
|
|
17
11
|
}
|
|
18
12
|
|
|
19
|
-
|
|
13
|
+
fn to_fixed_cstr(s: &str) -> [u8; 128] {
|
|
14
|
+
let mut buf = [0u8; 128];
|
|
15
|
+
let bytes = s.as_bytes();
|
|
16
|
+
let len = bytes.len().min(127);
|
|
17
|
+
buf[..len].copy_from_slice(&bytes[..len]);
|
|
18
|
+
buf
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
pub(crate) fn invoke_start_probe(method_name: String, file: String, lineno: i64) -> Result<(), Error> {
|
|
20
22
|
#[cfg(target_os = "linux")]
|
|
21
23
|
{
|
|
22
24
|
use probe::probe;
|
|
23
|
-
|
|
25
|
+
let m = to_fixed_cstr(&method_name);
|
|
26
|
+
let f = to_fixed_cstr(&file);
|
|
27
|
+
probe::probe!(vivarium_usdt, start_probe, m.as_ptr(), f.as_ptr(), lineno);
|
|
24
28
|
}
|
|
25
29
|
Ok(())
|
|
26
30
|
}
|
|
27
31
|
|
|
28
|
-
pub(crate) fn invoke_stop_probe(
|
|
32
|
+
pub(crate) fn invoke_stop_probe(method_name: String, file: String, lineno: i64) -> Result<(), Error> {
|
|
29
33
|
#[cfg(target_os = "linux")]
|
|
30
34
|
{
|
|
31
35
|
use probe::probe;
|
|
32
|
-
|
|
36
|
+
let m = to_fixed_cstr(&method_name);
|
|
37
|
+
let f = to_fixed_cstr(&file);
|
|
38
|
+
probe::probe!(vivarium_usdt, stop_probe, m.as_ptr(), f.as_ptr(), lineno);
|
|
33
39
|
}
|
|
34
40
|
Ok(())
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
pub(crate) fn invoke_raise_probe(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
error_name: String,
|
|
45
|
+
message: String,
|
|
46
|
+
file: String,
|
|
41
47
|
lineno: i64,
|
|
42
48
|
) -> Result<(), Error> {
|
|
43
49
|
#[cfg(target_os = "linux")]
|
|
44
50
|
{
|
|
45
51
|
use probe::probe;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
message_id,
|
|
51
|
-
file_id,
|
|
52
|
-
lineno
|
|
53
|
-
);
|
|
52
|
+
let e = to_fixed_cstr(&error_name);
|
|
53
|
+
let msg = to_fixed_cstr(&message);
|
|
54
|
+
let f = to_fixed_cstr(&file);
|
|
55
|
+
probe::probe!(vivarium_usdt, raise_probe, e.as_ptr(), msg.as_ptr(), f.as_ptr(), lineno);
|
|
54
56
|
}
|
|
55
57
|
Ok(())
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
pub(crate) fn __helper_get_hash_from_name(name: String) -> Result<i64, Error> {
|
|
59
|
-
use std::collections::hash_map::DefaultHasher;
|
|
60
|
-
use std::hash::{Hash, Hasher};
|
|
61
|
-
|
|
62
|
-
let mut hasher = DefaultHasher::new();
|
|
63
|
-
name.hash(&mut hasher);
|
|
64
|
-
let hash = hasher.finish() as i64;
|
|
65
|
-
Ok(hash)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
60
|
#[cfg(test)]
|
|
69
61
|
mod tests {
|
|
70
62
|
use rb_sys_test_helpers::ruby_test;
|
data/lib/vivarium/usdt.rb
CHANGED
|
@@ -3,85 +3,18 @@ require "vivarium_usdt/vivarium_usdt"
|
|
|
3
3
|
module Vivarium
|
|
4
4
|
module Usdt
|
|
5
5
|
class << self
|
|
6
|
-
def __method_id_table
|
|
7
|
-
@__method_id_table ||= {}
|
|
8
|
-
end
|
|
9
|
-
private :__method_id_table
|
|
10
|
-
|
|
11
|
-
def __error_id_table
|
|
12
|
-
@__error_id_table ||= {}
|
|
13
|
-
end
|
|
14
|
-
private :__error_id_table
|
|
15
|
-
|
|
16
|
-
def __message_id_table
|
|
17
|
-
@__message_id_table ||= {}
|
|
18
|
-
end
|
|
19
|
-
private :__message_id_table
|
|
20
|
-
|
|
21
|
-
def __file_id_table
|
|
22
|
-
@__file_id_table ||= {}
|
|
23
|
-
end
|
|
24
|
-
private :__file_id_table
|
|
25
|
-
|
|
26
|
-
def get_method_name(u64)
|
|
27
|
-
__method_id_table[u64]
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def get_error_name(u64)
|
|
31
|
-
__error_id_table[u64]
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def get_message_name(u64)
|
|
35
|
-
__message_id_table[u64]
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def get_file_name(u64)
|
|
39
|
-
__file_id_table[u64]
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def register_or_resolve_method(method_signature)
|
|
43
|
-
id = __helper_get_hash_from_name(method_signature)
|
|
44
|
-
__method_id_table[id] ||= method_signature
|
|
45
|
-
id
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def register_or_resolve_error(error_name)
|
|
49
|
-
id = __helper_get_hash_from_name(error_name)
|
|
50
|
-
__error_id_table[id] ||= error_name
|
|
51
|
-
id
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def register_or_resolve_message(message)
|
|
55
|
-
id = __helper_get_hash_from_name(message)
|
|
56
|
-
__message_id_table[id] ||= message
|
|
57
|
-
id
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def register_or_resolve_file(file_name)
|
|
61
|
-
id = __helper_get_hash_from_name(file_name)
|
|
62
|
-
__file_id_table[id] ||= file_name
|
|
63
|
-
id
|
|
64
|
-
end
|
|
65
|
-
|
|
66
6
|
def start(defined_class, method_name, file: nil, lineno: -1)
|
|
67
7
|
method_signature = "#{defined_class}##{method_name}"
|
|
68
|
-
|
|
69
|
-
file_id = file ? register_or_resolve_file(file) : -1
|
|
70
|
-
::VivariumUsdt.invoke_start_probe(method_id, file_id, lineno)
|
|
8
|
+
::VivariumUsdt.invoke_start_probe(method_signature, file || "", lineno)
|
|
71
9
|
end
|
|
72
10
|
|
|
73
11
|
def stop(defined_class, method_name, file: nil, lineno: -1)
|
|
74
12
|
method_signature = "#{defined_class}##{method_name}"
|
|
75
|
-
|
|
76
|
-
file_id = file ? register_or_resolve_file(file) : -1
|
|
77
|
-
::VivariumUsdt.invoke_stop_probe(method_id, file_id, lineno)
|
|
13
|
+
::VivariumUsdt.invoke_stop_probe(method_signature, file || "", lineno)
|
|
78
14
|
end
|
|
79
15
|
|
|
80
16
|
def raise(error_name, message, file: nil, lineno: -1)
|
|
81
|
-
|
|
82
|
-
message_id = register_or_resolve_message(message)
|
|
83
|
-
file_id = file ? register_or_resolve_file(file) : -1
|
|
84
|
-
::VivariumUsdt.invoke_raise_probe(error_id, message_id, file_id, lineno)
|
|
17
|
+
::VivariumUsdt.invoke_raise_probe(error_name, message, file || "", lineno)
|
|
85
18
|
end
|
|
86
19
|
end
|
|
87
20
|
end
|