forked from rubocop/rubocop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprof.rake
48 lines (42 loc) · 1.39 KB
/
prof.rake
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
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true
namespace :prof do
dump_path = 'tmp/stackprof.dump'
desc 'Run RuboCop on itself with profiling on'
task :run, [:path] do |_task, args|
# Must be run `rubocop` with the local process.
require 'rubocop/server'
if RuboCop::Server.running?
RuboCop::Server::ClientCommand::Stop.new.run
puts 'Stop the server for profiling.'
end
path = args.fetch(:path, '.')
cmd = "bin/rubocop-profile #{path}"
system cmd
end
desc 'Run RuboCop on itself only if dump does not exist'
task :run_if_needed, [:path] do
Rake::Task[:run].run unless File.exist?(dump_path)
end
desc 'List the slowest cops'
task slow_cops: :run_if_needed do
method = 'RuboCop::Cop::Commissioner#trigger_responding_cops'
cmd = "stackprof #{dump_path} --text --method '#{method}'"
puts cmd
output = `#{cmd}`
_header, list, _code = *output
.lines
.grep_v(/RuboCop::Cop::Commissioner/) # ignore internal calls
.slice_after { |line| line.match?(/callees.*:|code:/) }
puts list.first(40)
end
desc 'Check a particular method by walking through the callstack'
task :walk, [:method] => :run_if_needed do |_task, args|
method = args.fetch(:method) do
warn "usage: bundle exec rake 'walk[Class#method]'"
exit!
end
cmd = "stackprof #{dump_path} --walk --method '#{method}'"
puts cmd
system cmd
end
end