Skip to content

Commit

Permalink
Implement GC.{measure_total_time, total_time} and update GC.stat to u…
Browse files Browse the repository at this point in the history
…pdate provided hash
  • Loading branch information
bjfish authored and eregon committed Nov 29, 2021
1 parent d797c39 commit 5185a7a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
19 changes: 19 additions & 0 deletions core/gc/measure_total_time_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require_relative '../../spec_helper'

ruby_version_is "3.1" do
describe "GC.measure_total_time" do
before :each do
@default = GC.measure_total_time
end

after :each do
GC.measure_total_time = @default
end

it "can set and get a boolean value" do
original = GC.measure_total_time
GC.measure_total_time = !original
GC.measure_total_time.should == !original
end
end
end
8 changes: 8 additions & 0 deletions core/gc/stat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,12 @@
GC.stat(:total_allocated_objects).should be_kind_of(Integer)
GC.stat[:total_allocated_objects].should be_kind_of(Integer)
end

it "raises an error if argument is not nil, a symbol, or a hash" do
-> { GC.stat(7) }.should raise_error(TypeError, "non-hash or symbol given")
end

it "raises an error if an unknown key is given" do
-> { GC.stat(:foo) }.should raise_error(ArgumentError, "unknown key: foo")
end
end
15 changes: 15 additions & 0 deletions core/gc/total_time_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require_relative '../../spec_helper'

ruby_version_is "3.1" do
describe "GC.total_time" do
it "returns an Integer" do
GC.total_time.should be_kind_of(Integer)
end

it "increases as collections are run" do
time_before = GC.total_time
GC.start
GC.total_time.should > time_before
end
end
end

3 comments on commit 5185a7a

@MSP-Greg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bjfish @eregon

JFYI, core/gc/total_time_spec.rb:12 is intermittently failing on Windows mingw or ucrt in Ruby master, and also ruby-loco builds. When it fails, the two values are equal. I don't know if this is a problem, if Windows has a resolution / rounding issue with nanoseconds, etc... Note that RUBY_PLATFORM.include? 'mingw' is true for both. Also, mswin builds haven't failed (?)

@eregon
Copy link
Member

@eregon eregon commented on 5185a7a Nov 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a log or output?
Maybe GC.total_time doesn't work on Windows.
In any case I think best to report this to CRuby.

@MSP-Greg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.