summaryrefslogtreecommitdiff
path: root/lib/gitlab/metrics/sampler.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2015-12-17 17:17:18 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2015-12-17 17:25:48 +0100
commitf181f05e8abd7b1066c11578193f6d7170764bf5 (patch)
treea1b2e5af8db3cfcff7b724b214887e2e6d7952bf /lib/gitlab/metrics/sampler.rb
parentbcee44ad33d8a84822a8df068d47812594c445a3 (diff)
downloadgitlab-ce-f181f05e8abd7b1066c11578193f6d7170764bf5.tar.gz
Track object counts using the "allocations" Gem
This allows us to track the counts of actual classes instead of "T_XXX" nodes. This is only enabled on CRuby as it uses CRuby specific APIs.
Diffstat (limited to 'lib/gitlab/metrics/sampler.rb')
-rw-r--r--lib/gitlab/metrics/sampler.rb25
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/gitlab/metrics/sampler.rb b/lib/gitlab/metrics/sampler.rb
index 03afa6324dd..828ee1f8c62 100644
--- a/lib/gitlab/metrics/sampler.rb
+++ b/lib/gitlab/metrics/sampler.rb
@@ -13,6 +13,12 @@ module Gitlab
@last_minor_gc = Delta.new(GC.stat[:minor_gc_count])
@last_major_gc = Delta.new(GC.stat[:major_gc_count])
+
+ if Gitlab::Metrics.mri?
+ require 'allocations'
+
+ Allocations.start
+ end
end
def start
@@ -52,9 +58,22 @@ module Gitlab
new('file_descriptors', value: System.file_descriptor_count)
end
- def sample_objects
- ObjectSpace.count_objects.each do |type, count|
- @metrics << Metric.new('object_counts', { count: count }, type: type)
+ if Metrics.mri?
+ def sample_objects
+ sample = Allocations.to_hash
+ counts = sample.each_with_object({}) do |(klass, count), hash|
+ hash[klass.name] = count
+ end
+
+ # Symbols aren't allocated so we'll need to add those manually.
+ counts['Symbol'] = Symbol.all_symbols.length
+
+ counts.each do |name, count|
+ @metrics << Metric.new('object_counts', { count: count }, type: name)
+ end
+ end
+ else
+ def sample_objects
end
end