Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic support for profiling with bin/rubocop-profile
- Loading branch information
Showing
5 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,3 +65,7 @@ TAGS | |
|
||
# For bundle binstubs | ||
bin/* | ||
!bin/rubocop-profile | ||
|
||
# For stackprof or others | ||
tmp/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require 'stackprof' | ||
|
||
StackProf.start | ||
start = Process.clock_gettime(Process::CLOCK_MONOTONIC) | ||
begin | ||
load "#{__dir__}/../exe/rubocop" | ||
ensure | ||
delta = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start | ||
StackProf.stop | ||
Dir.mkdir('tmp') unless File.exist?('tmp') | ||
StackProf.results('tmp/stackprof.dump') | ||
puts "Finished in #{delta.round(1)} seconds" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 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| | ||
path = args.fetch(:path, '.') | ||
cmd = "bin/rubocop-profile #{path}" | ||
system cmd | ||
end | ||
|
||
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_when { |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 |