pyroscope 0.0.16 → 0.0.23
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 -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 +59 -15
- data/lib/pyroscope/version.rb +1 -1
- data/lib/pyroscope.rb +42 -16
- data/test.rb +60 -19
- 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: 6d225c19f37a67a395be38c34385f64890b39a2a62b4e0d2e2fb33ee6ea339bd
|
4
|
+
data.tar.gz: 16c2204608dd53eab9252c90188347524e90c7fa854dd0a51686129127193777
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 182168268e38e12e25101c30b508c550daa50c3b3406ba8f9409fbdd268b06f584ae28bd92dd73067e288029f962075bff7e4e7fe8446767ab047c70798ea7d4
|
7
|
+
data.tar.gz: daccec7b3a6c262ac4a0d03fd6459907fa4b450c7e0598180d58c4983d9c2148260a04198b7c7da25c962cdc5209e5c9af49748331915d1a3a9e23e89b7b8bed
|
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,90 @@ 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
|
+
int SetLoggerLevel(int);
|
15
|
+
char* BuildSummary();
|
12
16
|
|
13
17
|
static VALUE
|
14
|
-
pyroscope_start(VALUE self, VALUE appName, VALUE
|
18
|
+
pyroscope_start(VALUE self, VALUE appName, VALUE serverAddress, VALUE authToken, VALUE sampleRate, VALUE withSubprocesses, VALUE logLevel) {
|
15
19
|
VALUE r_appName = StringValue(appName);
|
16
20
|
char *c_appName = RSTRING_PTR(r_appName);
|
17
21
|
|
18
|
-
int
|
22
|
+
int c_sampleRate = FIX2INT(sampleRate);
|
23
|
+
int c_withSubprocesses = FIX2INT(withSubprocesses);
|
19
24
|
|
20
25
|
VALUE r_serverAddress = StringValue(serverAddress);
|
21
26
|
char *c_serverAddress = RSTRING_PTR(r_serverAddress);
|
22
27
|
|
23
|
-
|
28
|
+
VALUE r_authToken = StringValue(authToken);
|
29
|
+
char *c_authToken = RSTRING_PTR(r_authToken);
|
30
|
+
|
31
|
+
VALUE r_logLevel = StringValue(logLevel);
|
32
|
+
char *c_logLevel = RSTRING_PTR(r_logLevel);
|
33
|
+
|
34
|
+
int res = Start(c_appName, "rbspy", c_serverAddress, c_authToken, c_sampleRate, c_withSubprocesses, c_logLevel);
|
24
35
|
|
25
36
|
return INT2FIX(res);
|
26
37
|
}
|
27
38
|
|
28
39
|
static VALUE
|
29
|
-
pyroscope_stop(VALUE self
|
30
|
-
int
|
31
|
-
int res = Stop(c_pid);
|
40
|
+
pyroscope_stop(VALUE self) {
|
41
|
+
int res = Stop();
|
32
42
|
return INT2FIX(res);
|
33
43
|
}
|
34
44
|
|
35
45
|
static VALUE
|
36
|
-
pyroscope_change_name(VALUE self, VALUE appName
|
46
|
+
pyroscope_change_name(VALUE self, VALUE appName) {
|
37
47
|
VALUE r_appName = StringValue(appName);
|
38
48
|
char *c_appName = RSTRING_PTR(r_appName);
|
39
|
-
int c_pid = FIX2INT(pid);
|
40
49
|
|
41
|
-
int res = ChangeName(c_appName
|
50
|
+
int res = ChangeName(c_appName);
|
51
|
+
return INT2FIX(res);
|
52
|
+
}
|
53
|
+
|
54
|
+
static VALUE
|
55
|
+
pyroscope_set_tag(VALUE self, VALUE key, VALUE val) {
|
56
|
+
VALUE r_key = StringValue(key);
|
57
|
+
char *c_key = RSTRING_PTR(r_key);
|
58
|
+
VALUE r_val = StringValue(val);
|
59
|
+
char *c_val = RSTRING_PTR(r_val);
|
60
|
+
|
61
|
+
int res = SetTag(c_key, c_val);
|
62
|
+
return INT2FIX(res);
|
63
|
+
}
|
64
|
+
|
65
|
+
static VALUE
|
66
|
+
pyroscope_test_logger(VALUE self) {
|
67
|
+
int res = TestLogger();
|
42
68
|
return INT2FIX(res);
|
43
69
|
}
|
44
70
|
|
71
|
+
static VALUE
|
72
|
+
pyroscope_set_logger_level(VALUE self, VALUE level) {
|
73
|
+
int res = SetLoggerLevel(FIX2INT(level));
|
74
|
+
return INT2FIX(res);
|
75
|
+
}
|
76
|
+
|
77
|
+
static VALUE
|
78
|
+
pyroscope_build_summary(VALUE self) {
|
79
|
+
char *c_summary = BuildSummary();
|
80
|
+
VALUE r_summary = rb_str_new_cstr(c_summary);
|
81
|
+
free(c_summary);
|
82
|
+
return r_summary;
|
83
|
+
}
|
84
|
+
|
45
85
|
void
|
46
86
|
Init_pyroscope_c() {
|
47
87
|
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,
|
88
|
+
rb_define_module_function(rb_Pyroscope, "_start", pyroscope_start, 6);
|
89
|
+
rb_define_module_function(rb_Pyroscope, "_stop", pyroscope_stop, 0);
|
90
|
+
rb_define_module_function(rb_Pyroscope, "_change_name", pyroscope_change_name, 1);
|
91
|
+
rb_define_module_function(rb_Pyroscope, "_set_tag", pyroscope_set_tag, 2);
|
92
|
+
rb_define_module_function(rb_Pyroscope, "_test_logger", pyroscope_test_logger, 0);
|
93
|
+
rb_define_module_function(rb_Pyroscope, "_set_logger_level", pyroscope_set_logger_level, 1);
|
94
|
+
rb_define_module_function(rb_Pyroscope, "_build_summary", pyroscope_build_summary, 0);
|
51
95
|
}
|
data/lib/pyroscope/version.rb
CHANGED
data/lib/pyroscope.rb
CHANGED
@@ -2,23 +2,49 @@ 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 set_tag(key, val)
|
30
|
+
_set_tag(key, val)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_logger()
|
34
|
+
_test_logger
|
35
|
+
end
|
36
|
+
|
37
|
+
VALID_LOG_LEVELS = %i[none error info debug]
|
38
|
+
|
39
|
+
def set_logger_level(level)
|
40
|
+
i = VALID_LOG_LEVELS.index(level)
|
41
|
+
raise "Unknown log level (#{level.inspect}), valid values are #{VALID_LOG_LEVELS.inspect}" unless i
|
42
|
+
|
43
|
+
_set_logger_level(i - 1)
|
44
|
+
end
|
20
45
|
|
21
|
-
|
22
|
-
|
46
|
+
def build_summary
|
47
|
+
_build_summary
|
48
|
+
end
|
23
49
|
end
|
24
50
|
end
|
data/test.rb
CHANGED
@@ -5,11 +5,17 @@ puts "prestart #{Process.pid}"
|
|
5
5
|
Pyroscope.configure do |config|
|
6
6
|
config.app_name = "test.ruby.app{}"
|
7
7
|
config.server_address = "http://localhost:4040/"
|
8
|
+
config.log_level = "debug"
|
8
9
|
end
|
9
10
|
|
10
11
|
puts "start"
|
11
|
-
|
12
|
-
|
12
|
+
|
13
|
+
puts "Pyroscope.test_logger 1"
|
14
|
+
Pyroscope.test_logger
|
15
|
+
Pyroscope.set_logger_level(:debug)
|
16
|
+
puts "Pyroscope.test_logger 2"
|
17
|
+
Pyroscope.test_logger
|
18
|
+
|
13
19
|
|
14
20
|
def work(n)
|
15
21
|
i = 0
|
@@ -30,22 +36,57 @@ def sleep_job
|
|
30
36
|
sleep(rand()*10)
|
31
37
|
end
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
39
|
+
def main_loop(b)
|
40
|
+
puts "Starting main loop from: #{Process.pid}"
|
41
|
+
Pyroscope.set_tag("pid", Process.pid.to_s) if b
|
42
|
+
while true
|
43
|
+
r = rand
|
44
|
+
# if r > 0.9
|
45
|
+
# Pyroscope.set_logger_level(:test)
|
46
|
+
# end
|
47
|
+
if r < 0.1
|
48
|
+
sleep_job
|
49
|
+
elsif r < 0.5
|
50
|
+
puts(" * test.ruby.app{job=0} #{Process.pid}")
|
51
|
+
Pyroscope.set_tag("job", "0") if b
|
52
|
+
job_0
|
53
|
+
Pyroscope.set_tag("job", "") if b
|
54
|
+
else
|
55
|
+
puts(" * test.ruby.app{job=1} #{Process.pid}")
|
56
|
+
Pyroscope.set_tag("job", "1") if b
|
57
|
+
job_1
|
58
|
+
Pyroscope.set_tag("job", "") if b
|
59
|
+
end
|
50
60
|
end
|
51
61
|
end
|
62
|
+
|
63
|
+
fork do
|
64
|
+
puts "build_summary:"
|
65
|
+
puts Pyroscope.build_summary
|
66
|
+
# Pyroscope.configure do |config|
|
67
|
+
# config.app_name = "test.ruby.app2{}"
|
68
|
+
# config.server_address = "http://localhost:4040/"
|
69
|
+
# end
|
70
|
+
|
71
|
+
puts "Hello from fork pid: #{Process.pid}"
|
72
|
+
sleep 15
|
73
|
+
main_loop(false)
|
74
|
+
end
|
75
|
+
|
76
|
+
# sleep 5
|
77
|
+
# if ARGV.first == "subprocess"
|
78
|
+
# main_loop(true)
|
79
|
+
# else
|
80
|
+
# ssh_pid = Kernel.spawn("ruby", "test.rb", "subprocess")
|
81
|
+
# puts "spawned #{ssh_pid}"
|
82
|
+
|
83
|
+
# sleep(30)
|
84
|
+
# puts "killing #{ssh_pid}"
|
85
|
+
# Process.kill("TERM", ssh_pid)
|
86
|
+
|
87
|
+
|
88
|
+
# end
|
89
|
+
|
90
|
+
sleep 15
|
91
|
+
puts "The parent process just skips over it: #{Process.pid}"
|
92
|
+
main_loop(true)
|
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.0.23
|
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-02 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: []
|