pyroscope 0.0.13 → 0.1.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/Rakefile +2 -8
- data/ext/pyroscope/extconf.rb +36 -25
- data/ext/pyroscope/lib/.gitkeep +0 -0
- data/ext/pyroscope/lib/libpyroscope.rbspy.a +0 -0
- data/ext/pyroscope/lib/libpyroscope.rbspy.combo.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 +51 -16
- data/test.rb +15 -34
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15d405da85cfd950ffe3b25c9ea6a3b5df68c57cfb52cd0b53f91cf26f22a955
|
4
|
+
data.tar.gz: 76422633bd992c1a1b148f66a9be25c6974bb47fba0d70e38e09c749fa389109
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67550275be573ffe4dac71dc62386dc917bed9cb0be052b155cd33d11d18107100e1323c0454d3dd55eaaa269c2c3a58b039fa48a54ba07170d755ac2f4d768c
|
7
|
+
data.tar.gz: a4d1a8a11ffc44762a7dcb30ea7d946960696e35e77936e56c67f520d94744161cde0255cdf6457482b6c419522341ba46051b569c36c9580f1dee0f89a48c58
|
data/Rakefile
CHANGED
@@ -42,14 +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
|
-
|
52
|
-
system "PYROSCOPE_RUBY_LOCAL=1 rake build && PYROSCOPE_RUBY_LOCAL=1 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"
|
53
47
|
end
|
54
48
|
|
55
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,38 +19,49 @@ 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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
["libpyroscope.rbspy.a", "librustdeps.a"].each do |name|
|
37
|
+
url = PREFIX+"/#{name}.gz"
|
38
|
+
req = Net::HTTP::Get.new(url)
|
39
|
+
http.request(req) do |resp|
|
40
|
+
raise "HTTP error: #{resp.code}" unless resp.code == "200"
|
41
|
+
|
42
|
+
r, w = IO.pipe
|
43
|
+
|
44
|
+
t = Thread.new do
|
45
|
+
zreader = Zlib::GzipReader.new(r)
|
46
|
+
File.open(File.join(ROOT, "lib/#{name}"), "wb") do |f|
|
47
|
+
loop do
|
48
|
+
begin
|
49
|
+
chunk = zreader.readpartial(32768)
|
50
|
+
break if chunk.nil?
|
51
|
+
rescue EOFError
|
52
|
+
break
|
53
|
+
end
|
54
|
+
f.write(chunk)
|
43
55
|
end
|
44
|
-
f.write(chunk)
|
45
56
|
end
|
46
57
|
end
|
47
|
-
end
|
48
58
|
|
49
|
-
|
50
|
-
|
51
|
-
|
59
|
+
resp.read_body do |chunk|
|
60
|
+
w.write(chunk)
|
61
|
+
end
|
52
62
|
|
53
|
-
|
63
|
+
t.join
|
64
|
+
end
|
54
65
|
end
|
55
66
|
end
|
56
67
|
end
|
@@ -60,7 +71,7 @@ end
|
|
60
71
|
|
61
72
|
dir_config('pyroscope', HEADER_DIRS, LIB_DIRS)
|
62
73
|
|
63
|
-
libs = ['-lpyroscope.rbspy
|
74
|
+
libs = ['-lpyroscope.rbspy', '-lrustdeps']
|
64
75
|
libs.each do |lib|
|
65
76
|
$LOCAL_LIBS << "#{lib} "
|
66
77
|
end
|
File without changes
|
Binary file
|
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,58 @@ 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)
|
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
|
+
end
|
20
|
+
|
21
|
+
def stop
|
22
|
+
_stop
|
23
|
+
end
|
24
|
+
|
25
|
+
def change_name(new_name)
|
26
|
+
_change_name(new_name)
|
27
|
+
end
|
28
|
+
|
29
|
+
def tag_wrapper(tags)
|
30
|
+
tag(tags)
|
31
|
+
|
32
|
+
begin
|
33
|
+
yield
|
34
|
+
ensure
|
35
|
+
remove_tags(*tags.keys)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def tag(tags)
|
40
|
+
tags.each_pair do |key, val|
|
41
|
+
_set_tag(key, val)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def remove_tags(*keys)
|
46
|
+
keys.each do |key|
|
47
|
+
_set_tag(key, "")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_logger
|
52
|
+
_test_logger
|
53
|
+
end
|
20
54
|
|
21
|
-
|
22
|
-
|
55
|
+
def build_summary
|
56
|
+
_build_summary
|
57
|
+
end
|
23
58
|
end
|
24
59
|
end
|
data/test.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
-
|
1
|
+
require 'pyroscope'
|
2
2
|
|
3
3
|
puts "prestart #{Process.pid}"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
puts "start"
|
11
|
-
iteration=0
|
12
|
-
st = Time.new
|
5
|
+
Pyroscope.configure do |config|
|
6
|
+
config.app_name = "test.ruby.app{}"
|
7
|
+
config.server_address = "http://localhost:4040/"
|
8
|
+
end
|
13
9
|
|
14
10
|
def work(n)
|
15
11
|
i = 0
|
@@ -18,34 +14,19 @@ def work(n)
|
|
18
14
|
end
|
19
15
|
end
|
20
16
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
def job_1
|
26
|
-
work(rand()*2_000_000)
|
17
|
+
def fast_function
|
18
|
+
Pyroscope.tag_wrapper({ "function" => "fast"}) do
|
19
|
+
work(20_000)
|
20
|
+
end
|
27
21
|
end
|
28
22
|
|
29
|
-
def
|
30
|
-
|
23
|
+
def slow_function
|
24
|
+
Pyroscope.tag({ "function" => "slow"})
|
25
|
+
work(80_000)
|
26
|
+
Pyroscope.remove_tags("function")
|
31
27
|
end
|
32
28
|
|
33
|
-
|
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.0
|
4
|
+
version: 0.1.0
|
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
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- Rakefile
|
95
95
|
- ext/pyroscope/Makefile.example
|
96
96
|
- ext/pyroscope/extconf.rb
|
97
|
+
- ext/pyroscope/lib/.gitkeep
|
97
98
|
- ext/pyroscope/lib/libpyroscope.rbspy.a
|
98
99
|
- ext/pyroscope/lib/libpyroscope.rbspy.combo.a
|
99
100
|
- ext/pyroscope/lib/librustdeps.a
|
@@ -106,7 +107,7 @@ homepage: http://rubygems.org/gems/pyroscope
|
|
106
107
|
licenses:
|
107
108
|
- Apache-2.0
|
108
109
|
metadata: {}
|
109
|
-
post_install_message:
|
110
|
+
post_install_message:
|
110
111
|
rdoc_options: []
|
111
112
|
require_paths:
|
112
113
|
- lib
|
@@ -122,8 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
123
|
- !ruby/object:Gem::Version
|
123
124
|
version: '0'
|
124
125
|
requirements: []
|
125
|
-
rubygems_version: 3.2.
|
126
|
-
signing_key:
|
126
|
+
rubygems_version: 3.2.22
|
127
|
+
signing_key:
|
127
128
|
specification_version: 4
|
128
129
|
summary: pyroscope
|
129
130
|
test_files: []
|