Excessive getcwd() calls when Rubocop is run
When running bundle exec rubocop
locally with GitLab, I noticed an usually high number of getcwd()
calls:
$ strace bundle exec rubocop
<snip>
7301 11:53:18.481876 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000019>
7301 11:53:18.482047 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000011>
7301 11:53:18.482279 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000021>
7301 11:53:18.482356 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000011>
7301 11:53:18.482426 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000012>
7301 11:53:18.482480 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000010>
7301 11:53:18.482567 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000011>
7301 11:53:18.482618 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000011>
7301 11:53:18.482768 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000039>
7301 11:53:18.482888 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000017>
7301 11:53:18.482956 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000011>
7301 11:53:18.483070 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000011>
7301 11:53:18.483159 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000024>
7301 11:53:18.483247 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000019>
7301 11:53:18.483304 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000015>
7301 11:53:18.483378 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000019>
7301 11:53:18.484708 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000142>
7301 11:53:18.484972 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000016>
7301 11:53:18.485107 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000018>
7301 11:53:18.485202 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000014>
7301 11:53:18.485261 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000014>
7301 11:53:18.485318 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000016>
7301 11:53:18.485395 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000017>
7301 11:53:18.485447 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000014>
7301 11:53:18.485522 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000016>
7301 11:53:18.485581 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000015>
7301 11:53:18.485634 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000014>
<snip>
7301 11:53:19.600873 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000015>
7301 11:53:19.600925 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000016>
7301 11:53:19.600981 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000016>
7301 11:53:19.601062 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000016>
7301 11:53:19.601124 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000017>
7301 11:53:19.601179 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000016>
7301 11:53:19.601230 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000014>
7301 11:53:19.601340 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000020>
7301 11:53:19.601965 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000036>
7301 11:53:19.602062 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000015>
7301 11:53:19.602153 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000016>
7301 11:53:19.602207 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000015>
7301 11:53:19.602269 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000015>
7301 11:53:19.602318 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000015>
7301 11:53:19.602382 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000016>
7301 11:53:19.602432 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000016>
7301 11:53:19.602501 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000016>
7301 11:53:19.602556 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000016>
7301 11:53:19.602612 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000016>
7301 11:53:19.602714 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000016>
7301 11:53:19.602765 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000016>
7301 11:53:19.602819 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000015>
7301 11:53:19.602867 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000015>
7301 11:53:19.602921 getcwd("/home/stanhu/gdk-ee/gitlab", 4096) = 27 <0.000016>
7301 11:53:19.604159 stat("/home/stanhu/gdk-ee/gitlab/lib/gitlab/git/repository.rb", {st_mode=S_IFREG|0664, st_size=34442, ...}) = 0 <0.
000046>
I think this is partly why it seems Rubocop takes a long time to run. I added this clause to Rubocop:
module MyDir
def pwd
puts "pwd is here #{caller.join("\n")}"
super
end
end
Dir.singleton_class.prepend(MyDir)
And found that the problem was happening here: https://gitlab.com/gitlab-org/gitlab-ce/blob/9f8123d935679582ac4f1487e1dcb559863372cb/rubocop/spec_helpers.rb#L11
/home/stanhu/gdk-ee/gitlab/rubocop/spec_helpers.rb:11:in `in_spec?'
/home/stanhu/gdk-ee/gitlab/rubocop/cop/sidekiq_options_queue.rb:16:in `on_send'
/home/stanhu/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.68.1/lib/rubocop/cop/commissioner.rb:59:in `block (2 levels) in trigger_responding_cops'
/home/stanhu/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.68.1/lib/rubocop/cop/commissioner.rb:130:in `with_cop_error_handling'
/home/stanhu/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.68.1/lib/rubocop/cop/commissioner.rb:58:in `block in trigger_responding_cops'
/home/stanhu/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.68.1/lib/rubocop/cop/commissioner.rb:57:in `each'
/home/stanhu/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.68.1/lib/rubocop/cop/commissioner.rb:57:in `trigger_responding_cops'
/home/stanhu/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.68.1/lib/rubocop/cop/commissioner.rb:34:in `block (2 levels) in <class:Commissioner>'
And here:
/home/stanhu/gdk-ee/gitlab/rubocop/qa_helpers.rb:8:in `in_qa_file?'
/home/stanhu/gdk-ee/gitlab/rubocop/cop/qa/element_with_pattern.rb:22:in `on_send'
/home/stanhu/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.68.1/lib/rubocop/cop/commissioner.rb:59:in `block (2 levels) in trigger_responding_cops'
/home/stanhu/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.68.1/lib/rubocop/cop/commissioner.rb:130:in `with_cop_error_handling'
/home/stanhu/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.68.1/lib/rubocop/cop/commissioner.rb:58:in `block in trigger_responding_cops'
/home/stanhu/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.68.1/lib/rubocop/cop/commissioner.rb:57:in `each'
/home/stanhu/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.68.1/lib/rubocop/cop/commissioner.rb:57:in `trigger_responding_cops'
/home/stanhu/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gem
Expected behavior
Few getcwd()
calls.
Actual behavior
In a span of 10 seconds, I count 53,260 getcwd()
system calls.
Steps to reproduce the problem
git clone https://gitlab.com/gitlab-org/gitlab-ce.git
git checkout -b sh-upgrade-rubocop-0.68.0 origin/sh-upgrade-rubocop-0.68.0
bundle install
bundle exec rubocop
RuboCop version
I'm testing 0.68.1 at the moment:
$ bundle exec rubocop -V
0.68.1 (using Parser 2.5.3.0, running on ruby 2.5.3 x86_64-linux)
Edited by Stan Hu