pyroscope 0.0.14 → 0.1.1
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/README.md +1 -1
- data/Rakefile +2 -10
- data/ext/pyroscope/extconf.rb +11 -3
- data/ext/pyroscope/lib/libpyroscope.rbspy.a +0 -0
- data/ext/pyroscope/lib/librustdeps.a +0 -0
- data/ext/pyroscope/pyroscope.c +51 -15
- data/lib/pyroscope/version.rb +1 -1
- data/lib/pyroscope.rb +52 -16
- data/test.rb +14 -33
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 743ff4c97e82300fb18a63cb6ebe626f241ce77a1bf0fd034198db698b5c5aca
|
|
4
|
+
data.tar.gz: 76d3705d25132cb5779b9e430eb2972894597d4bd4732a30c28a8995ec18fcaa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4bc08bbdc5fa0081806d4e2030eef6a6032c1e5fb68d53784fc5e0565f7ed4d57a85171d87ff91213d3fc0209967d47279593ac2025739a611588771d36e8c0d
|
|
7
|
+
data.tar.gz: 5d27f0e63129001f60bb11fab6f19e837b82a350bc746b6ac7a1bd0e072c1ea7546b3d0b9ea32ff4d864c8feb1b71c718f2a67e9d606d98b2b518c689b9e49fc
|
data/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
# pyroscope-ruby
|
|
2
2
|
|
|
3
|
-
This is a repo for pyroscope ruby integration.
|
|
3
|
+
This is a repo for pyroscope ruby integration. See [examples/ruby](https://github.com/pyroscope-io/pyroscope/tree/main/examples/ruby) in the main repo for examples.
|
data/Rakefile
CHANGED
|
@@ -42,16 +42,8 @@ task :build => [:clean, :compile]
|
|
|
42
42
|
task :default => [:build, :spec]
|
|
43
43
|
|
|
44
44
|
task :test do
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
# system "cd ../pyroscope && rm out/*.a"
|
|
48
|
-
# system "cd ../pyroscope && ENABLED_SPIES=rbspy make build-rust-dependencies"
|
|
49
|
-
# system "cd ../pyroscope && make build-rbspy-static-library"
|
|
50
|
-
# system "cd ../pyroscope && cp third_party/rustdeps/target/x86_64-unknown-linux-gnu/release/librustdeps.a ./out/librustdeps.a"
|
|
51
|
-
extra_env = "PYROSCOPE_RUBY_LOCAL=1"
|
|
52
|
-
extra_env = ""
|
|
53
|
-
|
|
54
|
-
system "#{extra_env} rake build && #{extra_env} sudo -E gem install pkg/pyroscope-#{Pyroscope::VERSION}.gem && sudo -E ruby test.rb"
|
|
45
|
+
sudo = RUBY_PLATFORM =~ /darwin/ ? "sudo -E" : ""
|
|
46
|
+
system "rake build && #{sudo} gem install pkg/pyroscope-#{Pyroscope::VERSION}.gem && #{sudo} ruby test.rb"
|
|
55
47
|
end
|
|
56
48
|
|
|
57
49
|
task :test_exec do
|
data/ext/pyroscope/extconf.rb
CHANGED
|
@@ -9,7 +9,7 @@ HEADER_DIRS = [INCLUDEDIR]
|
|
|
9
9
|
|
|
10
10
|
LIB_DIRS = [LIBDIR, File.expand_path(File.join(File.dirname(__FILE__), "lib"))]
|
|
11
11
|
|
|
12
|
-
COMMIT = "
|
|
12
|
+
COMMIT = "df45c48"
|
|
13
13
|
|
|
14
14
|
# TODO: this is not very accurate, but it works for now
|
|
15
15
|
OS = RUBY_PLATFORM.include?("darwin") ? "mac" : "linux"
|
|
@@ -19,10 +19,18 @@ PREFIX = "/static-libs/#{COMMIT}/#{OS}-#{ARCH}"
|
|
|
19
19
|
|
|
20
20
|
ROOT = File.expand_path("..", __FILE__)
|
|
21
21
|
|
|
22
|
+
def run(str)
|
|
23
|
+
system(str) || fail("command failed: #{str}")
|
|
24
|
+
end
|
|
25
|
+
|
|
22
26
|
if ENV["PYROSCOPE_RUBY_LOCAL"]
|
|
23
27
|
puts "PYROSCOPE_RUBY_LOCAL yes"
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
# TODO: make configurable
|
|
29
|
+
pyroscope_path = "#{ENV["HOME"]}/pyroscope"
|
|
30
|
+
run("rm -rf #{File.join(ROOT, "build")}")
|
|
31
|
+
run("cd #{pyroscope_path} && make build-rust-dependencies-docker")
|
|
32
|
+
run("cp #{pyroscope_path}/out/libpyroscope.rbspy.a #{File.join(ROOT, "lib/libpyroscope.rbspy.a")}")
|
|
33
|
+
run("cp #{pyroscope_path}/out/librustdeps.a #{File.join(ROOT, "lib/librustdeps.a")}")
|
|
26
34
|
else
|
|
27
35
|
Net::HTTP.start("dl.pyroscope.io", 443, :use_ssl => true) do |http|
|
|
28
36
|
["libpyroscope.rbspy.a", "librustdeps.a"].each do |name|
|
|
Binary file
|
|
Binary file
|
data/ext/pyroscope/pyroscope.c
CHANGED
|
@@ -6,46 +6,82 @@ static VALUE rb_Pyroscope;
|
|
|
6
6
|
#include <stdio.h>
|
|
7
7
|
#include <string.h>
|
|
8
8
|
|
|
9
|
-
int Start(char*,
|
|
10
|
-
int Stop(
|
|
11
|
-
int ChangeName(char
|
|
9
|
+
int Start(char*, char*, char*, char*, int, int, char*);
|
|
10
|
+
int Stop();
|
|
11
|
+
int ChangeName(char*);
|
|
12
|
+
int SetTag(char*, char*);
|
|
13
|
+
int TestLogger();
|
|
14
|
+
char* BuildSummary();
|
|
12
15
|
|
|
13
16
|
static VALUE
|
|
14
|
-
pyroscope_start(VALUE self, VALUE appName, VALUE
|
|
17
|
+
pyroscope_start(VALUE self, VALUE appName, VALUE serverAddress, VALUE authToken, VALUE sampleRate, VALUE withSubprocesses, VALUE logLevel) {
|
|
15
18
|
VALUE r_appName = StringValue(appName);
|
|
16
19
|
char *c_appName = RSTRING_PTR(r_appName);
|
|
17
20
|
|
|
18
|
-
int
|
|
21
|
+
int c_sampleRate = FIX2INT(sampleRate);
|
|
22
|
+
int c_withSubprocesses = FIX2INT(withSubprocesses);
|
|
19
23
|
|
|
20
24
|
VALUE r_serverAddress = StringValue(serverAddress);
|
|
21
25
|
char *c_serverAddress = RSTRING_PTR(r_serverAddress);
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
VALUE r_authToken = StringValue(authToken);
|
|
28
|
+
char *c_authToken = RSTRING_PTR(r_authToken);
|
|
29
|
+
|
|
30
|
+
VALUE r_logLevel = StringValue(logLevel);
|
|
31
|
+
char *c_logLevel = RSTRING_PTR(r_logLevel);
|
|
32
|
+
|
|
33
|
+
int res = Start(c_appName, "rbspy", c_serverAddress, c_authToken, c_sampleRate, c_withSubprocesses, c_logLevel);
|
|
24
34
|
|
|
25
35
|
return INT2FIX(res);
|
|
26
36
|
}
|
|
27
37
|
|
|
28
38
|
static VALUE
|
|
29
|
-
pyroscope_stop(VALUE self
|
|
30
|
-
int
|
|
31
|
-
int res = Stop(c_pid);
|
|
39
|
+
pyroscope_stop(VALUE self) {
|
|
40
|
+
int res = Stop();
|
|
32
41
|
return INT2FIX(res);
|
|
33
42
|
}
|
|
34
43
|
|
|
35
44
|
static VALUE
|
|
36
|
-
pyroscope_change_name(VALUE self, VALUE appName
|
|
45
|
+
pyroscope_change_name(VALUE self, VALUE appName) {
|
|
37
46
|
VALUE r_appName = StringValue(appName);
|
|
38
47
|
char *c_appName = RSTRING_PTR(r_appName);
|
|
39
|
-
int c_pid = FIX2INT(pid);
|
|
40
48
|
|
|
41
|
-
int res = ChangeName(c_appName
|
|
49
|
+
int res = ChangeName(c_appName);
|
|
50
|
+
return INT2FIX(res);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static VALUE
|
|
54
|
+
pyroscope_set_tag(VALUE self, VALUE key, VALUE val) {
|
|
55
|
+
VALUE r_key = StringValue(key);
|
|
56
|
+
char *c_key = RSTRING_PTR(r_key);
|
|
57
|
+
VALUE r_val = StringValue(val);
|
|
58
|
+
char *c_val = RSTRING_PTR(r_val);
|
|
59
|
+
|
|
60
|
+
int res = SetTag(c_key, c_val);
|
|
42
61
|
return INT2FIX(res);
|
|
43
62
|
}
|
|
44
63
|
|
|
64
|
+
static VALUE
|
|
65
|
+
pyroscope_test_logger(VALUE self) {
|
|
66
|
+
int res = TestLogger();
|
|
67
|
+
return INT2FIX(res);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static VALUE
|
|
71
|
+
pyroscope_build_summary(VALUE self) {
|
|
72
|
+
char *c_summary = BuildSummary();
|
|
73
|
+
VALUE r_summary = rb_str_new_cstr(c_summary);
|
|
74
|
+
free(c_summary);
|
|
75
|
+
return r_summary;
|
|
76
|
+
}
|
|
77
|
+
|
|
45
78
|
void
|
|
46
79
|
Init_pyroscope_c() {
|
|
47
80
|
rb_Pyroscope = rb_define_module("Pyroscope");
|
|
48
|
-
rb_define_module_function(rb_Pyroscope, "_start", pyroscope_start,
|
|
49
|
-
rb_define_module_function(rb_Pyroscope, "_stop", pyroscope_stop,
|
|
50
|
-
rb_define_module_function(rb_Pyroscope, "_change_name", pyroscope_change_name,
|
|
81
|
+
rb_define_module_function(rb_Pyroscope, "_start", pyroscope_start, 6);
|
|
82
|
+
rb_define_module_function(rb_Pyroscope, "_stop", pyroscope_stop, 0);
|
|
83
|
+
rb_define_module_function(rb_Pyroscope, "_change_name", pyroscope_change_name, 1);
|
|
84
|
+
rb_define_module_function(rb_Pyroscope, "_set_tag", pyroscope_set_tag, 2);
|
|
85
|
+
rb_define_module_function(rb_Pyroscope, "_test_logger", pyroscope_test_logger, 0);
|
|
86
|
+
rb_define_module_function(rb_Pyroscope, "_build_summary", pyroscope_build_summary, 0);
|
|
51
87
|
}
|
data/lib/pyroscope/version.rb
CHANGED
data/lib/pyroscope.rb
CHANGED
|
@@ -2,23 +2,59 @@ require "pyroscope/version"
|
|
|
2
2
|
require "pyroscope_c"
|
|
3
3
|
|
|
4
4
|
module Pyroscope
|
|
5
|
-
Config = Struct.new(:app_name, :server_address)
|
|
6
|
-
|
|
7
|
-
def self.configure
|
|
8
|
-
@configuration = Config.new
|
|
9
|
-
yield @configuration
|
|
10
|
-
_start(
|
|
11
|
-
@configuration.app_name,
|
|
12
|
-
Process.pid,
|
|
13
|
-
@configuration.server_address,
|
|
14
|
-
)
|
|
15
|
-
end
|
|
5
|
+
Config = Struct.new(:app_name, :server_address, :auth_token, :sample_rate, :with_subprocesses, :log_level, :tags)
|
|
16
6
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
class << self
|
|
8
|
+
def configure
|
|
9
|
+
@configuration = Config.new
|
|
10
|
+
yield @configuration
|
|
11
|
+
_start(
|
|
12
|
+
@configuration.app_name,
|
|
13
|
+
@configuration.server_address,
|
|
14
|
+
@configuration.auth_token || "",
|
|
15
|
+
@configuration.sample_rate || 100,
|
|
16
|
+
@configuration.with_subprocesses || 0,
|
|
17
|
+
@configuration.log_level || "error",
|
|
18
|
+
)
|
|
19
|
+
tag(@configuration.tags) if @configuration.tags
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def stop
|
|
23
|
+
_stop
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def change_name(new_name)
|
|
27
|
+
_change_name(new_name)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def tag_wrapper(tags)
|
|
31
|
+
tag(tags)
|
|
32
|
+
|
|
33
|
+
begin
|
|
34
|
+
yield
|
|
35
|
+
ensure
|
|
36
|
+
remove_tags(*tags.keys)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def tag(tags)
|
|
41
|
+
tags.each_pair do |key, val|
|
|
42
|
+
_set_tag(key.to_s, val.to_s)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def remove_tags(*keys)
|
|
47
|
+
keys.each do |key|
|
|
48
|
+
_set_tag(key.to_s, "")
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_logger
|
|
53
|
+
_test_logger
|
|
54
|
+
end
|
|
20
55
|
|
|
21
|
-
|
|
22
|
-
|
|
56
|
+
def build_summary
|
|
57
|
+
_build_summary
|
|
58
|
+
end
|
|
23
59
|
end
|
|
24
60
|
end
|
data/test.rb
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
require
|
|
2
|
-
|
|
3
|
-
puts "prestart #{Process.pid}"
|
|
1
|
+
require "pyroscope"
|
|
4
2
|
|
|
5
3
|
Pyroscope.configure do |config|
|
|
6
|
-
config.app_name = "test.ruby.app
|
|
7
|
-
config.server_address = "http://
|
|
4
|
+
config.app_name = "test.ruby.app"
|
|
5
|
+
config.server_address = "http://pyroscope:4040/"
|
|
6
|
+
config.tags = {
|
|
7
|
+
:region => "us-east-1",
|
|
8
|
+
:hostname => ENV["hostname"]
|
|
9
|
+
}
|
|
8
10
|
end
|
|
9
11
|
|
|
10
|
-
puts "start"
|
|
11
|
-
iteration=0
|
|
12
|
-
st = Time.new
|
|
13
|
-
|
|
14
12
|
def work(n)
|
|
15
13
|
i = 0
|
|
16
14
|
while i < n
|
|
@@ -18,34 +16,17 @@ def work(n)
|
|
|
18
16
|
end
|
|
19
17
|
end
|
|
20
18
|
|
|
21
|
-
def
|
|
22
|
-
work(
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def job_1
|
|
26
|
-
work(rand()*2_000_000)
|
|
19
|
+
def fast_function
|
|
20
|
+
work(20000)
|
|
27
21
|
end
|
|
28
22
|
|
|
29
|
-
def
|
|
30
|
-
|
|
23
|
+
def slow_function
|
|
24
|
+
work(80000)
|
|
31
25
|
end
|
|
32
26
|
|
|
27
|
+
Pyroscope.tag({ "region" => "us-east-1" })
|
|
33
28
|
|
|
34
29
|
while true
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
r = rand
|
|
38
|
-
if r < 0.1
|
|
39
|
-
sleep_job
|
|
40
|
-
elsif r < 0.5
|
|
41
|
-
puts(" * test.ruby.app{job=0}")
|
|
42
|
-
Pyroscope.change_name("test.ruby.app{job=0}")
|
|
43
|
-
job_0
|
|
44
|
-
Pyroscope.change_name("test.ruby.app{}")
|
|
45
|
-
else
|
|
46
|
-
puts(" * test.ruby.app{job=1}")
|
|
47
|
-
Pyroscope.change_name("test.ruby.app{job=1}")
|
|
48
|
-
job_1
|
|
49
|
-
Pyroscope.change_name("test.ruby.app{}")
|
|
50
|
-
end
|
|
30
|
+
fast_function
|
|
31
|
+
slow_function
|
|
51
32
|
end
|
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.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Pyroscope Team
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-09-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -107,7 +107,7 @@ homepage: http://rubygems.org/gems/pyroscope
|
|
|
107
107
|
licenses:
|
|
108
108
|
- Apache-2.0
|
|
109
109
|
metadata: {}
|
|
110
|
-
post_install_message:
|
|
110
|
+
post_install_message:
|
|
111
111
|
rdoc_options: []
|
|
112
112
|
require_paths:
|
|
113
113
|
- lib
|
|
@@ -123,8 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
123
123
|
- !ruby/object:Gem::Version
|
|
124
124
|
version: '0'
|
|
125
125
|
requirements: []
|
|
126
|
-
rubygems_version: 3.2.
|
|
127
|
-
signing_key:
|
|
126
|
+
rubygems_version: 3.2.22
|
|
127
|
+
signing_key:
|
|
128
128
|
specification_version: 4
|
|
129
129
|
summary: pyroscope
|
|
130
130
|
test_files: []
|