Skip to content

Commit e198f61

Browse files
committed
[GR-32856] Fix --cpusampler test and use the ruby that runs jt to run rubocop
PullRequest: truffleruby/2840
2 parents e40943b + 9cbbadc commit e198f61

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

doc/contributor/profiling.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,9 @@ Creating the flame graph is a multi-stage process. First, we need to profile the
4848
with the JSON formatter:
4949

5050
```bash
51-
jt ruby --cpusampler --cpusampler.Mode=roots --cpusampler.Output=json -e 'p :hello' > simple-app.json
51+
jt ruby --cpusampler --cpusampler.Output=json -e 'p :hello' > simple-app.json
5252
```
5353

54-
The `--cpusampler.Mode=roots` option will sample roots, including inlined functions,
55-
which can often give a better idea of what is contributing to the overall method execution time.
56-
5754
The JSON profiler formatter encodes call graph information that isn't available in the
5855
histogram format. To make a flame graph out of this output, however, we need to transform
5956
it into a format that folds the call stack samples into single lines. This can be done

spec/truffle/gc/time_spec.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# truffleruby_primitives: true
2+
13
# Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:
@@ -16,11 +18,7 @@
1618

1719
it "increases as collections are run" do
1820
time_before = GC.time
19-
i = 0
20-
while GC.time <= time_before and i < 10
21-
GC.start
22-
i += 1
23-
end
21+
Primitive.gc_force
2422
GC.time.should > time_before
2523
end
2624

spec/truffle/objspace/undefine_finalizer_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# truffleruby_primitives: true
2+
13
# Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:
@@ -25,7 +27,7 @@
2527
ObjectSpace.undefine_finalizer object
2628
ObjectSpace.reachable_objects_from(object).should_not include(finalizer)
2729
end
28-
GC.start
30+
Primitive.gc_force
2931
Truffle::Debug.drain_finalization_queue # Not needed for correctness
3032
channel.try_receive.should be_nil
3133
end

spec/truffle/tools_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
code = <<~RUBY
6060
def foo
6161
n = 0
62-
loop { itself { n += 1 } }
62+
loop { yield_self { n += 1 } }
6363
n
6464
end
6565
t = Thread.new { foo }
@@ -68,9 +68,9 @@ def foo
6868
t.kill
6969
t.join
7070
RUBY
71-
out = ruby_exe(code, options: "--cpusampler --cpusampler.Mode=roots")
71+
out = ruby_exe(code, options: "--cpusampler")
7272
out.should.include?(":kill")
73-
out.should.include?("block in Object#foo")
73+
out.should.include?("block (2 levels) in Object#foo")
7474
out.should_not.include?('KillException')
7575
$?.should.success?
7676
end

tool/jt.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
JDEBUG = '--vm.agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=y'
4141
METRICS_REPS = Integer(ENV['TRUFFLERUBY_METRICS_REPS'] || 10)
42-
DEFAULT_PROFILE_OPTIONS = %w[--cpusampler --cpusampler.Mode=roots --cpusampler.Output=json]
42+
DEFAULT_PROFILE_OPTIONS = %w[--cpusampler --cpusampler.Output=json]
4343

4444
RUBOCOP_INCLUDE_LIST = %w[
4545
lib/cext
@@ -2304,15 +2304,18 @@ def rubocop(*args)
23042304
args += RUBOCOP_INCLUDE_LIST
23052305
end
23062306

2307+
ruby = RbConfig.ruby
2308+
23072309
if gem_test_pack?
23082310
gem_home = "#{gem_test_pack}/rubocop-gems"
23092311
env = { 'GEM_HOME' => gem_home, 'GEM_PATH' => gem_home }
2310-
sh env, 'ruby', "#{gem_home}/bin/rubocop", *args
2312+
sh env, ruby, "#{gem_home}/bin/rubocop", *args
23112313
else
2312-
unless sh('rubocop', "_#{RUBOCOP_VERSION}_", *args, continue_on_failure: true)
2313-
sh 'gem', 'install', 'rubocop', '-v', RUBOCOP_VERSION
2314-
sh 'rubocop', "_#{RUBOCOP_VERSION}_", *args
2314+
env = { 'PATH' => "#{File.dirname(ruby)}:#{ENV['PATH']}" }
2315+
if Gem::Specification.find_all_by_name('rubocop', "#{RUBOCOP_VERSION}").empty?
2316+
sh env, 'gem', 'install', 'rubocop', '-v', RUBOCOP_VERSION
23152317
end
2318+
sh env, 'rubocop', "_#{RUBOCOP_VERSION}_", *args
23162319
end
23172320
end
23182321

0 commit comments

Comments
 (0)