Skip to content

Commit

Permalink
Decouple GC::Profiler from Metrics a bit.
Browse files Browse the repository at this point in the history
Ultimately, the very simplistic utility of GC::Profiler isn't useful and
Rubinius::Metrics should be used directly instead. We may remove support for
GC::Profiler in the future.  For now, using it requires enabling Rubinius
Metrics.
  • Loading branch information
brixen committed Apr 1, 2016
1 parent 731e807 commit 0deebd9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
26 changes: 19 additions & 7 deletions core/gc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,27 @@ def garbage_collect
end

def self.count
data = stat
data[:"gc.young.count"] + data[:"gc.immix.count"]
if data = stat
data[:"gc.young.count"] + data[:"gc.immix.count"]
else
0
end
end

def self.time
data = stat
data[:"gc.young.ms"] +
data[:"gc.immix.stop.ms"] +
data[:"gc.large.sweep.us"] * 1_000
if data = stat
data[:"gc.young.ms"] +
data[:"gc.immix.stop.ms"] +
data[:"gc.large.sweep.us"] * 1_000
else
0
end
end

def self.stat
Rubinius::Metrics.data.to_hash
if Rubinius::Metrics.enabled?
return Rubinius::Metrics.data.to_hash
end
end

module Profiler
Expand Down Expand Up @@ -90,6 +98,10 @@ def self.report(out = $stdout)
end

def self.result
unless Rubinius::Metrics.enabled?
return "Rubinius::Metrics is disabled. GC::Profiler results are unavailable"
end

stats = GC.stat

out = <<-OUT
Expand Down
6 changes: 6 additions & 0 deletions core/metrics.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module Rubinius
module Metrics
@enabled = false

def self.enabled?
!!@enabled
end

def self.data
@data ||= Data.new
end
Expand Down

0 comments on commit 0deebd9

Please sign in to comment.