Skip to content

Commit

Permalink
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions spec/std/gc_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "spec"

describe "GC" do
it "stats compiled" do
GC.stats.collections.should be >= 0
end
end
19 changes: 17 additions & 2 deletions src/gc/boehm.cr
Original file line number Diff line number Diff line change
@@ -122,9 +122,24 @@ module GC

record Stats,
collections : LibC::ULong,
bytes_found : LibC::Long
bytes_found : LibC::Long,
heap_size : LibC::ULong,
free_bytes : LibC::ULong,
unmapped_bytes : LibC::ULong,
bytes_since_gc : LibC::ULong,
total_bytes : LibC::ULong

def self.stats
Stats.new LibGC.gc_no - 1, LibGC.bytes_found
LibGC.get_heap_usage_safe(out heap_size, out free_bytes, out unmapped_bytes, out bytes_since_gc, out total_bytes)
collections = LibGC.gc_no - 1
bytes_found = LibGC.bytes_found

Stats.new collections: collections,
bytes_found: bytes_found,
heap_size: heap_size,
free_bytes: free_bytes,
unmapped_bytes: unmapped_bytes,
bytes_since_gc: bytes_since_gc,
total_bytes: total_bytes
end
end

0 comments on commit 0c93b1b

Please sign in to comment.