stackprof 0.2.21 → 0.2.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/bin/stackprof +116 -81
- data/ext/stackprof/stackprof.c +19 -1
- data/lib/stackprof/autorun.rb +19 -0
- data/lib/stackprof.rb +1 -1
- data/stackprof.gemspec +1 -1
- 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: db2506be248e74ed4aefacbb3b7adc4936c88b1acb3517fde5510a225704b6bf
|
4
|
+
data.tar.gz: 55aaefff3de2d6887cb9a861eb615faa85e48411eeadf778990bc1439e7c456e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e761d5f7da7687ecb51ecc493c3dc4ff8e86798b57cd65c429b90e29e4021827df58525b5ddd2d21d597cba4a31e251909daa33d518157d63c53e74944784fde
|
7
|
+
data.tar.gz: a8c9da37e92aa2bcc64b2532367f749e5568cfa4e02758dca80d3d3f1b4f399b860dd215f880cea814356d50766103dc684f0192a04660075b5be6e43a7db121
|
data/bin/stackprof
CHANGED
@@ -2,94 +2,129 @@
|
|
2
2
|
require 'optparse'
|
3
3
|
require 'stackprof'
|
4
4
|
|
5
|
-
|
5
|
+
if ARGV.first == "run"
|
6
|
+
ARGV.shift
|
7
|
+
env = {}
|
8
|
+
parser = OptionParser.new(ARGV) do |o|
|
9
|
+
o.banner = "Usage: stackprof run [--mode=MODE|--out=FILE|--interval=INTERVAL|--format=FORMAT] -- COMMAND"
|
10
|
+
o.banner = "Usage: stackprof [file.dump]+ [--text|--method=NAME|--callgrind|--graphviz]"
|
6
11
|
|
7
|
-
|
8
|
-
|
12
|
+
o.on('--mode [MODE]', String, 'Mode of sampling: cpu, wall, object, default to wall') do |mode|
|
13
|
+
env["STACKPROF_MODE"] = mode
|
14
|
+
end
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
o.on('--limit [num]', Integer, 'Limit --text, --files, or --graphviz output to N entries'){ |n| options[:limit] = n }
|
14
|
-
o.on('--sort-total', "Sort --text or --files output on total samples\n\n"){ options[:sort] = true }
|
15
|
-
o.on('--method [grep]', 'Zoom into specified method'){ |f| options[:format] = :method; options[:filter] = f }
|
16
|
-
o.on('--file [grep]', "Show annotated code for specified file"){ |f| options[:format] = :file; options[:filter] = f }
|
17
|
-
o.on('--walk', "Walk the stacktrace interactively\n\n"){ |f| options[:walk] = true }
|
18
|
-
o.on('--callgrind', 'Callgrind output (use with kcachegrind, stackprof-gprof2dot.py)'){ options[:format] = :callgrind }
|
19
|
-
o.on('--graphviz', "Graphviz output (use with dot)"){ options[:format] = :graphviz }
|
20
|
-
o.on('--node-fraction [frac]', OptionParser::DecimalNumeric, 'Drop nodes representing less than [frac] fraction of samples'){ |n| options[:node_fraction] = n }
|
21
|
-
o.on('--stackcollapse', 'stackcollapse.pl compatible output (use with stackprof-flamegraph.pl)'){ options[:format] = :stackcollapse }
|
22
|
-
o.on('--timeline-flamegraph', "timeline-flamegraph output (js)"){ options[:format] = :timeline_flamegraph }
|
23
|
-
o.on('--alphabetical-flamegraph', "alphabetical-flamegraph output (js)"){ options[:format] = :alphabetical_flamegraph }
|
24
|
-
o.on('--flamegraph', "alias to --timeline-flamegraph"){ options[:format] = :timeline_flamegraph }
|
25
|
-
o.on('--flamegraph-viewer [f.js]', String, "open html viewer for flamegraph output"){ |file|
|
26
|
-
puts("open file://#{File.expand_path('../../lib/stackprof/flamegraph/viewer.html', __FILE__)}?data=#{File.expand_path(file)}")
|
27
|
-
exit
|
28
|
-
}
|
29
|
-
o.on('--d3-flamegraph', "flamegraph output (html using d3-flame-graph)\n\n"){ options[:format] = :d3_flamegraph }
|
30
|
-
o.on('--select-files []', String, 'Show results of matching files'){ |path| (options[:select_files] ||= []) << File.expand_path(path) }
|
31
|
-
o.on('--reject-files []', String, 'Exclude results of matching files'){ |path| (options[:reject_files] ||= []) << File.expand_path(path) }
|
32
|
-
o.on('--select-names []', Regexp, 'Show results of matching method names'){ |regexp| (options[:select_names] ||= []) << regexp }
|
33
|
-
o.on('--reject-names []', Regexp, 'Exclude results of matching method names'){ |regexp| (options[:reject_names] ||= []) << regexp }
|
34
|
-
o.on('--dump', 'Print marshaled profile dump (combine multiple profiles)'){ options[:format] = :dump }
|
35
|
-
o.on('--debug', 'Pretty print raw profile data'){ options[:format] = :debug }
|
36
|
-
end
|
16
|
+
o.on('--out [FILENAME]', String, 'The target file, which will be overwritten. Defaults to a random temporary file') do |out|
|
17
|
+
env['STACKPROF_OUT'] = out
|
18
|
+
end
|
37
19
|
|
38
|
-
|
39
|
-
|
20
|
+
o.on('--interval [MILLISECONDS]', Integer, 'Mode-relative sample rate') do |interval|
|
21
|
+
env['STACKPROF_INTERVAL'] = interval.to_s
|
22
|
+
end
|
40
23
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
24
|
+
o.on('--raw', 'collects the extra data required by the --flamegraph and --stackcollapse report types') do |raw|
|
25
|
+
env['STACKPROF_RAW'] = raw.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
o.on('--ignore-gc', 'Ignore garbage collection frames') do |gc|
|
29
|
+
env['STACKPROF_IGNORE_GC'] = gc.to_s
|
30
|
+
end
|
48
31
|
end
|
49
|
-
|
50
|
-
|
32
|
+
parser.parse!
|
33
|
+
parser.abort(parser.help) if ARGV.empty?
|
34
|
+
stackprof_path = File.expand_path('../lib', __dir__)
|
35
|
+
env['RUBYOPT'] = "-I #{stackprof_path} -r stackprof/autorun #{ENV['RUBYOPT']}"
|
36
|
+
Kernel.exec(env, *ARGV)
|
37
|
+
else
|
38
|
+
options = {}
|
51
39
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
:limit => 30
|
56
|
-
}
|
40
|
+
parser = OptionParser.new(ARGV) do |o|
|
41
|
+
o.banner = "Usage: stackprof run [--mode|--out|--interval] -- COMMAND"
|
42
|
+
o.banner = "Usage: stackprof [file.dump]+ [--text|--method=NAME|--callgrind|--graphviz]"
|
57
43
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
44
|
+
o.on('--text', 'Text summary per method (default)'){ options[:format] = :text }
|
45
|
+
o.on('--json', 'JSON output (use with web viewers)'){ options[:format] = :json }
|
46
|
+
o.on('--files', 'List of files'){ |f| options[:format] = :files }
|
47
|
+
o.on('--limit [num]', Integer, 'Limit --text, --files, or --graphviz output to N entries'){ |n| options[:limit] = n }
|
48
|
+
o.on('--sort-total', "Sort --text or --files output on total samples\n\n"){ options[:sort] = true }
|
49
|
+
o.on('--method [grep]', 'Zoom into specified method'){ |f| options[:format] = :method; options[:filter] = f }
|
50
|
+
o.on('--file [grep]', "Show annotated code for specified file"){ |f| options[:format] = :file; options[:filter] = f }
|
51
|
+
o.on('--walk', "Walk the stacktrace interactively\n\n"){ |f| options[:walk] = true }
|
52
|
+
o.on('--callgrind', 'Callgrind output (use with kcachegrind, stackprof-gprof2dot.py)'){ options[:format] = :callgrind }
|
53
|
+
o.on('--graphviz', "Graphviz output (use with dot)"){ options[:format] = :graphviz }
|
54
|
+
o.on('--node-fraction [frac]', OptionParser::DecimalNumeric, 'Drop nodes representing less than [frac] fraction of samples'){ |n| options[:node_fraction] = n }
|
55
|
+
o.on('--stackcollapse', 'stackcollapse.pl compatible output (use with stackprof-flamegraph.pl)'){ options[:format] = :stackcollapse }
|
56
|
+
o.on('--timeline-flamegraph', "timeline-flamegraph output (js)"){ options[:format] = :timeline_flamegraph }
|
57
|
+
o.on('--alphabetical-flamegraph', "alphabetical-flamegraph output (js)"){ options[:format] = :alphabetical_flamegraph }
|
58
|
+
o.on('--flamegraph', "alias to --timeline-flamegraph"){ options[:format] = :timeline_flamegraph }
|
59
|
+
o.on('--flamegraph-viewer [f.js]', String, "open html viewer for flamegraph output"){ |file|
|
60
|
+
puts("open file://#{File.expand_path('../../lib/stackprof/flamegraph/viewer.html', __FILE__)}?data=#{File.expand_path(file)}")
|
61
|
+
exit
|
62
|
+
}
|
63
|
+
o.on('--d3-flamegraph', "flamegraph output (html using d3-flame-graph)\n\n"){ options[:format] = :d3_flamegraph }
|
64
|
+
o.on('--select-files []', String, 'Show results of matching files'){ |path| (options[:select_files] ||= []) << File.expand_path(path) }
|
65
|
+
o.on('--reject-files []', String, 'Exclude results of matching files'){ |path| (options[:reject_files] ||= []) << File.expand_path(path) }
|
66
|
+
o.on('--select-names []', Regexp, 'Show results of matching method names'){ |regexp| (options[:select_names] ||= []) << regexp }
|
67
|
+
o.on('--reject-names []', Regexp, 'Exclude results of matching method names'){ |regexp| (options[:reject_names] ||= []) << regexp }
|
68
|
+
o.on('--dump', 'Print marshaled profile dump (combine multiple profiles)'){ options[:format] = :dump }
|
69
|
+
o.on('--debug', 'Pretty print raw profile data'){ options[:format] = :debug }
|
70
|
+
end
|
62
71
|
|
63
|
-
|
64
|
-
|
72
|
+
parser.parse!
|
73
|
+
parser.abort(parser.help) if ARGV.empty?
|
65
74
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
options
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
75
|
+
reports = []
|
76
|
+
while ARGV.size > 0
|
77
|
+
begin
|
78
|
+
file = ARGV.pop
|
79
|
+
reports << StackProf::Report.from_file(file)
|
80
|
+
rescue TypeError => e
|
81
|
+
STDERR.puts "** error parsing #{file}: #{e.inspect}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
report = reports.inject(:+)
|
85
|
+
|
86
|
+
default_options = {
|
87
|
+
:format => :text,
|
88
|
+
:sort => false,
|
89
|
+
:limit => 30
|
90
|
+
}
|
91
|
+
|
92
|
+
if options[:format] == :graphviz
|
93
|
+
default_options[:limit] = 120
|
94
|
+
default_options[:node_fraction] = 0.005
|
95
|
+
end
|
96
|
+
|
97
|
+
options = default_options.merge(options)
|
98
|
+
options.delete(:limit) if options[:limit] == 0
|
99
|
+
|
100
|
+
case options[:format]
|
101
|
+
when :text
|
102
|
+
report.print_text(options[:sort], options[:limit], options[:select_files], options[:reject_files], options[:select_names], options[:reject_names])
|
103
|
+
when :json
|
104
|
+
report.print_json
|
105
|
+
when :debug
|
106
|
+
report.print_debug
|
107
|
+
when :dump
|
108
|
+
report.print_dump
|
109
|
+
when :callgrind
|
110
|
+
report.print_callgrind
|
111
|
+
when :graphviz
|
112
|
+
report.print_graphviz(options)
|
113
|
+
when :stackcollapse
|
114
|
+
report.print_stackcollapse
|
115
|
+
when :timeline_flamegraph
|
116
|
+
report.print_timeline_flamegraph
|
117
|
+
when :alphabetical_flamegraph
|
118
|
+
report.print_alphabetical_flamegraph
|
119
|
+
when :d3_flamegraph
|
120
|
+
report.print_d3_flamegraph
|
121
|
+
when :method
|
122
|
+
options[:walk] ? report.walk_method(options[:filter]) : report.print_method(options[:filter])
|
123
|
+
when :file
|
124
|
+
report.print_file(options[:filter])
|
125
|
+
when :files
|
126
|
+
report.print_files(options[:sort], options[:limit])
|
127
|
+
else
|
128
|
+
raise ArgumentError, "unknown format: #{options[:format]}"
|
129
|
+
end
|
95
130
|
end
|
data/ext/stackprof/stackprof.c
CHANGED
@@ -125,6 +125,8 @@ static struct {
|
|
125
125
|
sample_time_t buffer_time;
|
126
126
|
VALUE frames_buffer[BUF_SIZE];
|
127
127
|
int lines_buffer[BUF_SIZE];
|
128
|
+
|
129
|
+
pthread_t target_thread;
|
128
130
|
} _stackprof;
|
129
131
|
|
130
132
|
static VALUE sym_object, sym_wall, sym_cpu, sym_custom, sym_name, sym_file, sym_line;
|
@@ -219,6 +221,7 @@ stackprof_start(int argc, VALUE *argv, VALUE self)
|
|
219
221
|
_stackprof.ignore_gc = ignore_gc;
|
220
222
|
_stackprof.metadata = metadata;
|
221
223
|
_stackprof.out = out;
|
224
|
+
_stackprof.target_thread = pthread_self();
|
222
225
|
|
223
226
|
if (raw) {
|
224
227
|
capture_timestamp(&_stackprof.last_sample_at);
|
@@ -721,7 +724,22 @@ stackprof_signal_handler(int sig, siginfo_t *sinfo, void *ucontext)
|
|
721
724
|
_stackprof.overall_signals++;
|
722
725
|
|
723
726
|
if (!_stackprof.running) return;
|
724
|
-
|
727
|
+
|
728
|
+
if (_stackprof.mode == sym_wall) {
|
729
|
+
// In "wall" mode, the SIGALRM signal will arrive at an arbitrary thread.
|
730
|
+
// In order to provide more useful results, especially under threaded web
|
731
|
+
// servers, we want to forward this signal to the original thread
|
732
|
+
// StackProf was started from.
|
733
|
+
// According to POSIX.1-2008 TC1 pthread_kill and pthread_self should be
|
734
|
+
// async-signal-safe.
|
735
|
+
if (pthread_self() != _stackprof.target_thread) {
|
736
|
+
pthread_kill(_stackprof.target_thread, sig);
|
737
|
+
return;
|
738
|
+
}
|
739
|
+
} else {
|
740
|
+
if (!ruby_native_thread_p()) return;
|
741
|
+
}
|
742
|
+
|
725
743
|
if (pthread_mutex_trylock(&lock)) return;
|
726
744
|
|
727
745
|
if (!_stackprof.ignore_gc && rb_during_gc()) {
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "stackprof"
|
2
|
+
|
3
|
+
options = {}
|
4
|
+
options[:mode] = ENV["STACKPROF_MODE"].to_sym if ENV.key?("STACKPROF_MODE")
|
5
|
+
options[:interval] = Integer(ENV["STACKPROF_INTERVAL"]) if ENV.key?("STACKPROF_INTERVAL")
|
6
|
+
options[:raw] = true if ENV["STACKPROF_RAW"]
|
7
|
+
options[:ignore_gc] = true if ENV["STACKPROF_IGNORE_GC"]
|
8
|
+
|
9
|
+
at_exit do
|
10
|
+
StackProf.stop
|
11
|
+
output_path = ENV.fetch("STACKPROF_OUT") do
|
12
|
+
require "tempfile"
|
13
|
+
Tempfile.create(["stackprof", ".dump"]).path
|
14
|
+
end
|
15
|
+
StackProf.results(output_path)
|
16
|
+
$stderr.puts("StackProf results dumped at: #{output_path}")
|
17
|
+
end
|
18
|
+
|
19
|
+
StackProf.start(**options)
|
data/lib/stackprof.rb
CHANGED
data/stackprof.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stackprof
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aman Gupta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- ext/stackprof/extconf.rb
|
77
77
|
- ext/stackprof/stackprof.c
|
78
78
|
- lib/stackprof.rb
|
79
|
+
- lib/stackprof/autorun.rb
|
79
80
|
- lib/stackprof/flamegraph/flamegraph.js
|
80
81
|
- lib/stackprof/flamegraph/viewer.html
|
81
82
|
- lib/stackprof/middleware.rb
|
@@ -98,9 +99,9 @@ licenses:
|
|
98
99
|
- MIT
|
99
100
|
metadata:
|
100
101
|
bug_tracker_uri: https://github.com/tmm1/stackprof/issues
|
101
|
-
changelog_uri: https://github.com/tmm1/stackprof/blob/v0.2.
|
102
|
-
documentation_uri: https://www.rubydoc.info/gems/stackprof/0.2.
|
103
|
-
source_code_uri: https://github.com/tmm1/stackprof/tree/v0.2.
|
102
|
+
changelog_uri: https://github.com/tmm1/stackprof/blob/v0.2.23/CHANGELOG.md
|
103
|
+
documentation_uri: https://www.rubydoc.info/gems/stackprof/0.2.23
|
104
|
+
source_code_uri: https://github.com/tmm1/stackprof/tree/v0.2.23
|
104
105
|
post_install_message:
|
105
106
|
rdoc_options: []
|
106
107
|
require_paths:
|
@@ -116,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
117
|
- !ruby/object:Gem::Version
|
117
118
|
version: '0'
|
118
119
|
requirements: []
|
119
|
-
rubygems_version: 3.
|
120
|
+
rubygems_version: 3.3.23
|
120
121
|
signing_key:
|
121
122
|
specification_version: 4
|
122
123
|
summary: sampling callstack-profiler for ruby 2.2+
|