diff options
author | John Cai <jcai@gitlab.com> | 2019-01-24 19:31:38 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2019-01-24 19:31:38 +0300 |
commit | adb3f04645228d31a4682d1f577a76885e01701b (patch) | |
tree | b808b7555309aac7ebd34c73def75625ac4d15dc | |
parent | 4f57abc546c54dea76a3b73127bb4853181f355f (diff) | |
parent | 7ca7bcb545ec2a1f688acd75f675bda6f2b221e3 (diff) |
Merge branch 'add-rbtrace-and-objspace-support' into 'master'
Support rbtrace and ObjectSpace via environment flags
See merge request gitlab-org/gitaly!1046
-rw-r--r-- | changelogs/unreleased/add-rbtrace-and-objspace-support.yml | 5 | ||||
-rw-r--r-- | ruby/Gemfile | 1 | ||||
-rw-r--r-- | ruby/Gemfile.lock | 10 | ||||
-rwxr-xr-x | ruby/bin/gitaly-ruby | 19 | ||||
-rw-r--r-- | ruby/lib/gitlab/config.rb | 12 |
5 files changed, 46 insertions, 1 deletions
diff --git a/changelogs/unreleased/add-rbtrace-and-objspace-support.yml b/changelogs/unreleased/add-rbtrace-and-objspace-support.yml new file mode 100644 index 000000000..facf62924 --- /dev/null +++ b/changelogs/unreleased/add-rbtrace-and-objspace-support.yml @@ -0,0 +1,5 @@ +--- +title: Support rbtrace and ObjectSpace via environment flags +merge_request: 1046 +author: +type: added diff --git a/ruby/Gemfile b/ruby/Gemfile index 706a8e5de..ac75ab493 100644 --- a/ruby/Gemfile +++ b/ruby/Gemfile @@ -14,6 +14,7 @@ gem 'gitlab-gollum-rugged_adapter', '~> 0.4.4', require: false gem 'grpc', '~> 1.15.0' gem 'sentry-raven', '~> 2.7.2', require: false gem 'faraday', '~> 0.12' +gem 'rbtrace', require: false # Detects the open source license the repository includes # This version needs to be in sync with GitLab CE/EE diff --git a/ruby/Gemfile.lock b/ruby/Gemfile.lock index c9f9215c1..6cef990c7 100644 --- a/ruby/Gemfile.lock +++ b/ruby/Gemfile.lock @@ -33,6 +33,7 @@ GEM activesupport (>= 3.0.0) faraday (0.15.3) multipart-post (>= 1.2, < 3) + ffi (1.10.0) gemojione (3.3.0) json gitaly-proto (1.7.0) @@ -83,12 +84,14 @@ GEM mime-types-data (3.2018.0812) mini_portile2 (2.4.0) minitest (5.11.3) + msgpack (1.2.6) multi_json (1.13.1) multipart-post (2.0.0) nokogiri (1.10.1) mini_portile2 (~> 2.4.0) nokogumbo (1.5.0) nokogiri + optimist (3.0.0) parallel (1.12.1) parser (2.5.3.0) ast (~> 2.4.0) @@ -101,6 +104,10 @@ GEM procto (0.0.3) public_suffix (3.0.3) rainbow (3.0.0) + rbtrace (0.4.11) + ffi (>= 1.0.6) + msgpack (>= 0.4.3) + optimist (>= 3.0.0) rdoc (4.3.0) rouge (3.3.0) rspec (3.7.0) @@ -180,6 +187,7 @@ DEPENDENCIES grpc (~> 1.15.0) licensee (~> 8.9.0) listen (~> 0.5.0) + rbtrace rdoc (~> 4.2) rspec rspec-parameterized @@ -192,4 +200,4 @@ DEPENDENCIES webmock (~> 3.4.0) BUNDLED WITH - 1.17.2 + 1.17.3 diff --git a/ruby/bin/gitaly-ruby b/ruby/bin/gitaly-ruby index 9002ad86a..6f6a69b82 100755 --- a/ruby/bin/gitaly-ruby +++ b/ruby/bin/gitaly-ruby @@ -23,6 +23,8 @@ def main FileUtils.mkdir_p(socket_dir) File.chmod(0700, socket_dir) + load_tracing + s = GRPC::RpcServer.new( poll_period: SHUTDOWN_TIMEOUT, interceptors: [ @@ -58,6 +60,23 @@ def main run_thread.join end +def load_tracing + config = Gitlab::Config::Gitaly.new + + if config.rbtrace_enabled? + GRPC.logger.info("... loading rbtrace") + require 'rbtrace' + end + + # rubocop:disable Style/GuardClause + if config.objspace_trace_enabled? + GRPC.logger.info("... loading ObjectSpace allocation tracking") + require 'objspace' + ObjectSpace.trace_object_allocations_start + end + # rubocop:enable Style/GuardClause +end + def start_parent_watcher(original_ppid, signal_thread) Thread.new do loop do diff --git a/ruby/lib/gitlab/config.rb b/ruby/lib/gitlab/config.rb index 6aa445aa8..a0e1742a6 100644 --- a/ruby/lib/gitlab/config.rb +++ b/ruby/lib/gitlab/config.rb @@ -55,6 +55,18 @@ module Gitlab def client_path @client_path ||= ENV['GITALY_RUBY_GITALY_BIN_DIR'] end + + def rbtrace_enabled? + @rbtrace_enabled ||= enabled?(ENV['GITALY_RUBY_RBTRACE_ENABLED']) + end + + def objspace_trace_enabled? + @objspace_trace_enabled ||= enabled?(ENV['GITALY_RUBY_OBJSPACE_TRACE_ENABLED']) + end + + def enabled?(value) + %w[true yes 1].include?(value&.downcase) + end end def git |