stackprof 0.2.20 → 0.2.21

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e627bf7fbeca0cb94e8be863b0a1db9160534d5172c1409ba4306e0f16a57ae0
4
- data.tar.gz: f881ec5ab3267f3b48f57794c3bce910b39f890db32817655b4e5253733fc466
3
+ metadata.gz: 33a342cae97be870781375a647e95936c6a6016ae711f27d60e41a891cb809f4
4
+ data.tar.gz: 867d55b7c7cdfc928ae35b3c36474bdda41ed4c4dc8e8b661b0c6580890b0b28
5
5
  SHA512:
6
- metadata.gz: 514c6697e4465fbce7990fffc2a71ca5aa544e1f526b338fde343c14bc801bb5056534e371e4d8fd5642f1b73b92126b2a5e476eb5292dde23bd0da734d7e236
7
- data.tar.gz: bed130e196f1004b3e74d2db466732fa8b23e582df3fcf944161112036053e95a5a05a3ed2ac175a6603e1f3b28b6062491aef89f4d30b764be3886aaf586b19
6
+ metadata.gz: 255835983ab93b52f7d1118a076f1881511c27b82a6db9e3f5db909f888bb563b26b855fc49dacbd0ef0b41f77af6c7638bf15721ff5085d012e916d4871592f
7
+ data.tar.gz: 7520e06a5bdf8fb240538b9a333f265675cc4056bc24b88c06d0d8c2e7cd5185346be6268707fe00f7f41bf6f8c8d70abc3925e53ac6684889ef4dc9e3ef6afd
@@ -8,7 +8,7 @@ jobs:
8
8
  strategy:
9
9
  fail-fast: false
10
10
  matrix:
11
- ruby: [ ruby-head, '3.1', '3.0', '2.7', '2.6', '2.5', '2.4', '2.3', '2.2' ]
11
+ ruby: [ ruby-head, '3.1', '3.0', '2.7', '2.6', '2.5', '2.4', '2.3', '2.2', truffleruby ]
12
12
  steps:
13
13
  - name: Checkout
14
14
  uses: actions/checkout@v2
data/Rakefile CHANGED
@@ -7,11 +7,21 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.test_files = FileList["test/**/test_*.rb"]
8
8
  end
9
9
 
10
- require "rake/extensiontask"
10
+ if RUBY_ENGINE == "truffleruby"
11
+ task :compile do
12
+ # noop
13
+ end
11
14
 
12
- Rake::ExtensionTask.new("stackprof") do |ext|
13
- ext.ext_dir = "ext/stackprof"
14
- ext.lib_dir = "lib/stackprof"
15
+ task :clean do
16
+ # noop
17
+ end
18
+ else
19
+ require "rake/extensiontask"
20
+
21
+ Rake::ExtensionTask.new("stackprof") do |ext|
22
+ ext.ext_dir = "ext/stackprof"
23
+ ext.lib_dir = "lib/stackprof"
24
+ end
15
25
  end
16
26
 
17
27
  task default: %i(compile test)
@@ -1,4 +1,10 @@
1
1
  require 'mkmf'
2
+
3
+ if RUBY_ENGINE == 'truffleruby'
4
+ File.write('Makefile', dummy_makefile($srcdir).join(""))
5
+ return
6
+ end
7
+
2
8
  if have_func('rb_postponed_job_register_one') &&
3
9
  have_func('rb_profile_frames') &&
4
10
  have_func('rb_tracepoint_new') &&
@@ -146,6 +146,7 @@ stackprof_start(int argc, VALUE *argv, VALUE self)
146
146
  VALUE opts = Qnil, mode = Qnil, interval = Qnil, metadata = rb_hash_new(), out = Qfalse;
147
147
  int ignore_gc = 0;
148
148
  int raw = 0, aggregate = 1;
149
+ VALUE metadata_val;
149
150
 
150
151
  if (_stackprof.running)
151
152
  return Qfalse;
@@ -160,7 +161,7 @@ stackprof_start(int argc, VALUE *argv, VALUE self)
160
161
  ignore_gc = 1;
161
162
  }
162
163
 
163
- VALUE metadata_val = rb_hash_aref(opts, sym_metadata);
164
+ metadata_val = rb_hash_aref(opts, sym_metadata);
164
165
  if (RTEST(metadata_val)) {
165
166
  if (!RB_TYPE_P(metadata_val, T_HASH))
166
167
  rb_raise(rb_eArgError, "metadata should be a hash");
@@ -597,14 +598,15 @@ stackprof_record_sample_for_stack(int num, uint64_t sample_timestamp, int64_t ti
597
598
  void
598
599
  stackprof_buffer_sample(void)
599
600
  {
601
+ uint64_t start_timestamp = 0;
602
+ int64_t timestamp_delta = 0;
603
+ int num;
604
+
600
605
  if (_stackprof.buffer_count > 0) {
601
606
  // Another sample is already pending
602
607
  return;
603
608
  }
604
609
 
605
- uint64_t start_timestamp = 0;
606
- int64_t timestamp_delta = 0;
607
- int num;
608
610
  if (_stackprof.raw) {
609
611
  struct timestamp_t t;
610
612
  capture_timestamp(&t);
@@ -828,15 +830,13 @@ stackprof_use_postponed_job_l(VALUE self)
828
830
  void
829
831
  Init_stackprof(void)
830
832
  {
833
+ size_t i;
831
834
  /*
832
835
  * As of Ruby 3.0, it should be safe to read stack frames at any time, unless YJIT is enabled
833
836
  * See https://github.com/ruby/ruby/commit/0e276dc458f94d9d79a0f7c7669bde84abe80f21
834
837
  */
835
- #if RUBY_API_VERSION_MAJOR < 3
836
- stackprof_use_postponed_job = 0;
837
- #endif
838
+ stackprof_use_postponed_job = RUBY_API_VERSION_MAJOR < 3;
838
839
 
839
- size_t i;
840
840
  #define S(name) sym_##name = ID2SYM(rb_intern(#name));
841
841
  S(object);
842
842
  S(custom);
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'pp'
4
- require 'digest/md5'
4
+ require 'digest/sha2'
5
5
  require 'json'
6
6
 
7
7
  module StackProf
@@ -52,7 +52,7 @@ module StackProf
52
52
  def normalized_frames
53
53
  id2hash = {}
54
54
  @data[:frames].each do |frame, info|
55
- id2hash[frame.to_s] = info[:hash] = Digest::MD5.hexdigest("#{info[:name]}#{info[:file]}#{info[:line]}")
55
+ id2hash[frame.to_s] = info[:hash] = Digest::SHA256.hexdigest("#{info[:name]}#{info[:file]}#{info[:line]}")
56
56
  end
57
57
  @data[:frames].inject(Hash.new) do |hash, (frame, info)|
58
58
  info = hash[id2hash[frame.to_s]] = info.dup
@@ -225,7 +225,7 @@ module StackProf
225
225
  end
226
226
  else
227
227
  frame = @data[:frames][val]
228
- child_name = "#{ frame[:name] } : #{ frame[:file] }"
228
+ child_name = "#{ frame[:name] } : #{ frame[:file] } : #{ frame[:line] }"
229
229
  child_data = convert_to_d3_flame_graph_format(child_name, child_stacks, depth + 1)
230
230
  weight += child_data["value"]
231
231
  children << child_data
@@ -0,0 +1,37 @@
1
+ module StackProf
2
+ # Define the same methods as stackprof.c
3
+ class << self
4
+ def running?
5
+ false
6
+ end
7
+
8
+ def run(*args)
9
+ unimplemented
10
+ end
11
+
12
+ def start(*args)
13
+ unimplemented
14
+ end
15
+
16
+ def stop
17
+ unimplemented
18
+ end
19
+
20
+ def results(*args)
21
+ unimplemented
22
+ end
23
+
24
+ def sample
25
+ unimplemented
26
+ end
27
+
28
+ def use_postponed_job!
29
+ # noop
30
+ end
31
+
32
+ private def unimplemented
33
+ raise "Use --cpusampler=flamegraph or --cpusampler instead of StackProf on TruffleRuby.\n" \
34
+ "See https://www.graalvm.org/tools/profiling/ and `ruby --help:cpusampler` for more details."
35
+ end
36
+ end
37
+ end
data/lib/stackprof.rb CHANGED
@@ -1,11 +1,15 @@
1
- require "stackprof/stackprof"
1
+ if RUBY_ENGINE == 'truffleruby'
2
+ require "stackprof/truffleruby"
3
+ else
4
+ require "stackprof/stackprof"
5
+ end
2
6
 
3
7
  if defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?
4
8
  StackProf.use_postponed_job!
5
9
  end
6
10
 
7
11
  module StackProf
8
- VERSION = '0.2.20'
12
+ VERSION = '0.2.21'
9
13
  end
10
14
 
11
15
  StackProf.autoload :Report, "stackprof/report.rb"
data/stackprof.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'stackprof'
3
- s.version = '0.2.20'
3
+ s.version = '0.2.21'
4
4
  s.homepage = 'http://github.com/tmm1/stackprof'
5
5
 
6
6
  s.authors = 'Aman Gupta'
@@ -308,4 +308,4 @@ class StackProfTest < MiniTest::Test
308
308
  r.close
309
309
  w.close
310
310
  end
311
- end
311
+ end unless RUBY_ENGINE == 'truffleruby'
@@ -0,0 +1,18 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'stackprof'
3
+ require 'minitest/autorun'
4
+
5
+ if RUBY_ENGINE == 'truffleruby'
6
+ class StackProfTruffleRubyTest < MiniTest::Test
7
+ def test_error
8
+ error = assert_raises RuntimeError do
9
+ StackProf.run(mode: :cpu) do
10
+ unreacheable
11
+ end
12
+ end
13
+
14
+ assert_match(/TruffleRuby/, error.message)
15
+ assert_match(/--cpusampler/, error.message)
16
+ end
17
+ end
18
+ end
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.20
4
+ version: 0.2.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aman Gupta
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-26 00:00:00.000000000 Z
11
+ date: 2022-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -80,6 +80,7 @@ files:
80
80
  - lib/stackprof/flamegraph/viewer.html
81
81
  - lib/stackprof/middleware.rb
82
82
  - lib/stackprof/report.rb
83
+ - lib/stackprof/truffleruby.rb
83
84
  - sample.rb
84
85
  - stackprof.gemspec
85
86
  - test/fixtures/profile.dump
@@ -87,6 +88,7 @@ files:
87
88
  - test/test_middleware.rb
88
89
  - test/test_report.rb
89
90
  - test/test_stackprof.rb
91
+ - test/test_truffleruby.rb
90
92
  - vendor/FlameGraph/README
91
93
  - vendor/FlameGraph/flamegraph.pl
92
94
  - vendor/gprof2dot/gprof2dot.py
@@ -96,10 +98,10 @@ licenses:
96
98
  - MIT
97
99
  metadata:
98
100
  bug_tracker_uri: https://github.com/tmm1/stackprof/issues
99
- changelog_uri: https://github.com/tmm1/stackprof/blob/v0.2.20/CHANGELOG.md
100
- documentation_uri: https://www.rubydoc.info/gems/stackprof/0.2.20
101
- source_code_uri: https://github.com/tmm1/stackprof/tree/v0.2.20
102
- post_install_message:
101
+ changelog_uri: https://github.com/tmm1/stackprof/blob/v0.2.21/CHANGELOG.md
102
+ documentation_uri: https://www.rubydoc.info/gems/stackprof/0.2.21
103
+ source_code_uri: https://github.com/tmm1/stackprof/tree/v0.2.21
104
+ post_install_message:
103
105
  rdoc_options: []
104
106
  require_paths:
105
107
  - lib
@@ -114,8 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
116
  - !ruby/object:Gem::Version
115
117
  version: '0'
116
118
  requirements: []
117
- rubygems_version: 3.0.3.1
118
- signing_key:
119
+ rubygems_version: 3.4.0.dev
120
+ signing_key:
119
121
  specification_version: 4
120
122
  summary: sampling callstack-profiler for ruby 2.2+
121
123
  test_files: []