summaryrefslogtreecommitdiff
path: root/bin/rubocop-profile
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-10-17 18:09:13 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-10-17 18:09:13 +0000
commit5150ecc452f4cf1c899f79d35d52af978ff2d43f (patch)
treeed36b7982b574d6b4ec5b4e3f68a61a0f7e762d1 /bin/rubocop-profile
parent3884d9d7160e80a70ad327813ada6cab03cded65 (diff)
downloadgitlab-ce-5150ecc452f4cf1c899f79d35d52af978ff2d43f.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'bin/rubocop-profile')
-rwxr-xr-xbin/rubocop-profile39
1 files changed, 39 insertions, 0 deletions
diff --git a/bin/rubocop-profile b/bin/rubocop-profile
new file mode 100755
index 00000000000..d1e31edbeed
--- /dev/null
+++ b/bin/rubocop-profile
@@ -0,0 +1,39 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+# Profile bundled RuboCop version.
+#
+# See https://github.com/rubocop/rubocop/blob/master/bin/rubocop-profile
+
+if ARGV.include?('-h') || ARGV.include?('--help')
+ puts "Usage: same as main `rubocop` command but gathers profiling info"
+ puts "Additional option: `--memory` to print memory usage"
+ exit(0)
+end
+with_mem = ARGV.delete('--memory')
+ARGV.unshift '--cache', 'false' unless ARGV.include?('--cache')
+
+require 'stackprof'
+if with_mem
+ require 'memory_profiler'
+ MemoryProfiler.start
+end
+StackProf.start
+start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+begin
+ require 'rubocop'
+
+ exit RuboCop::CLI.new.run
+ensure
+ delta = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
+ puts "Finished in #{delta.round(1)} seconds"
+ StackProf.stop
+ if with_mem
+ puts "Building memory report..."
+ report = MemoryProfiler.stop
+ end
+ Dir.mkdir('tmp') unless File.exist?('tmp')
+ StackProf.results('tmp/stackprof.dump')
+ report&.pretty_print(scale_bytes: true)
+ puts "StackProf written to `tmp/stackprof.dump`."
+end