class StackProf::Remote::Client
Client
wraps the script that uses net/http to make the start/stop requests to a host running the StackProf::Remote::Middleware
Attributes
host[R]
Public Class Methods
new(host, wait)
click to toggle source
# File lib/stackprof/remote/client.rb, line 12 def initialize(host, wait) @host = host @wait = (wait || 30).to_i check_host end
Public Instance Methods
enter_console()
click to toggle source
# File lib/stackprof/remote/client.rb, line 67 def enter_console StackProf::CLI.start(result_path) end
fetch_results()
click to toggle source
# File lib/stackprof/remote/client.rb, line 41 def fetch_results response = Net::HTTP.get_response(host, "/__stackprof__/stop") if response.code == '200' @results = response.body if !@results raise "Could not retreive results" end puts "[#{host}] Results: #{@results.bytesize / 1024}kb" else puts "[#{host}] Returned a #{response.code} response" puts response.body raise "Bad Response" end end
result_path()
click to toggle source
# File lib/stackprof/remote/client.rb, line 56 def result_path result_dir = File.expand_path('~/.sp') FileUtils.mkdir_p(result_dir) @result_path ||= File.expand_path(File.join(result_dir, "sp-#{@host}-#{Time.now.to_i}.dump")) end
run()
click to toggle source
# File lib/stackprof/remote/client.rb, line 18 def run start wait fetch_results save_results enter_console end
save_results()
click to toggle source
# File lib/stackprof/remote/client.rb, line 62 def save_results File.open(result_path, 'wb') {|f| f << @results } puts "Saved results to #{result_path}" end
start()
click to toggle source
# File lib/stackprof/remote/client.rb, line 26 def start puts "=== StackProf on #{host} ===" puts "Starting" result = Net::HTTP.get(host, "/__stackprof__/start") puts "[#{host}] #{result}" if result !~ /Started/ raise "Did not start successfully" end end
wait()
click to toggle source
# File lib/stackprof/remote/client.rb, line 36 def wait puts "Waiting for #{@wait} seconds" sleep @wait end
Private Instance Methods
check_host()
click to toggle source
# File lib/stackprof/remote/client.rb, line 72 def check_host if !host || !URI.parse(host) raise "Please supply a valid host to connect to (#{host})" end end