File: rubocop-profile

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (39 lines) | stat: -rwxr-xr-x 1,087 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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