Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Splits method into small methods

  • Loading branch information...
commit 88d264103dd429e0c25dc874437b6fe4ad2e494c 1 parent 190ee04
@bhb authored
Showing with 34 additions and 22 deletions.
  1. +34 −22 lib/rack/perftools_profiler/profiler.rb
View
56 lib/rack/perftools_profiler/profiler.rb
@@ -98,29 +98,8 @@ def profiling?
end
def data(options = {})
- printer = (options.fetch('printer') {@printer}).to_sym
- ignore = options.fetch('ignore') { nil }
- focus = options.fetch('focus') { nil }
- nodecount = options.fetch('nodecount') { nil }
- nodefraction = options.fetch('nodefraction') { nil }
if ::File.exists?(PROFILING_DATA_FILE)
- args = ["--#{printer}"]
- args << "--ignore=#{ignore}" if ignore
- args << "--focus=#{focus}" if focus
- args << "--nodecount=#{nodecount}" if nodecount
- args << "--nodefraction=#{nodefraction}" if nodefraction
- args << PROFILING_DATA_FILE
- cmd = ["pprof.rb"] + args
- cmd = ["bundle", "exec"] + cmd if @bundler
-
- stdout, stderr, status = Dir.chdir(@gemfile_dir) { run(*cmd) }
- if status!=0
- raise ProfilingError.new("Running the command '#{cmd.join(" ")}' exited with status #{status}", stderr)
- elsif stdout.length == 0 && stderr.length > 0
- raise ProfilingError.new("Running the command '#{cmd.join(" ")}' failed to generate a file", stderr)
- else
- [printer, stdout]
- end
+ data_from_file(options)
else
[:none, nil]
end
@@ -128,6 +107,39 @@ def data(options = {})
private
+ def data_from_file(options)
+ printer = options.fetch('printer') {@printer}.to_sym
+
+ command_array = build_command(printer, options)
+ stdout, stderr, status = Dir.chdir(@gemfile_dir) { run(*command_array) }
+
+ full_command = command_array.join(" ")
+ if status!=0
+ raise ProfilingError.new("Running the command '#{full_command}' exited with status #{status}", stderr)
+ elsif stdout.length == 0 && stderr.length > 0
+ raise ProfilingError.new("Running the command '#{full_command}' failed to generate a file", stderr)
+ else
+ [printer, stdout]
+ end
+ end
+
+ def build_command(printer, options)
+ ignore = options.fetch('ignore') { nil }
+ focus = options.fetch('focus') { nil }
+ nodecount = options.fetch('nodecount') { nil }
+ nodefraction = options.fetch('nodefraction') { nil }
+
+ args = ["--#{printer}"]
+ args << "--ignore=#{ignore}" if ignore
+ args << "--focus=#{focus}" if focus
+ args << "--nodecount=#{nodecount}" if nodecount
+ args << "--nodefraction=#{nodefraction}" if nodefraction
+ args << PROFILING_DATA_FILE
+ cmd = ["pprof.rb"] + args
+ cmd = ["bundle", "exec"] + cmd if @bundler
+ cmd
+ end
+
def run(*command)
out = err = ""
pid = nil
Please sign in to comment.
Something went wrong with that request. Please try again.