Class: StackProf::Remote::Client
- Inherits:
-
Object
- Object
- StackProf::Remote::Client
- Defined in:
- lib/stackprof/remote/client.rb
Overview
Client wraps the script that uses net/http to make the start/stop requests to a host running the StackProf::Remote::Middleware
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Instance Method Summary collapse
- #enter_console ⇒ Object
- #fetch_results ⇒ Object
-
#initialize(host, wait) ⇒ Client
constructor
A new instance of Client.
- #result_path ⇒ Object
- #run ⇒ Object
- #save_results ⇒ Object
- #start ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(host, wait) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 |
# File 'lib/stackprof/remote/client.rb', line 12 def initialize(host, wait) @host = host @wait = (wait || 30).to_i check_host end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
10 11 12 |
# File 'lib/stackprof/remote/client.rb', line 10 def host @host end |
Instance Method Details
#enter_console ⇒ Object
60 61 62 |
# File 'lib/stackprof/remote/client.rb', line 60 def enter_console StackProf::CLI.start(result_path) end |
#fetch_results ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/stackprof/remote/client.rb', line 41 def fetch_results @results = Net::HTTP.get(host, "/__stackprof__/stop") puts "[#{host}] Results: #{@results.bytesize / 1024}kb" if !@results raise "Could not retreive results" end end |
#result_path ⇒ Object
49 50 51 52 53 |
# File 'lib/stackprof/remote/client.rb', line 49 def result_path result_dir = File.('~/.sp') FileUtils.mkdir_p(result_dir) @result_path ||= File.(File.join(result_dir, "sp-#{@host}-#{Time.now.to_i}.dump")) end |
#run ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/stackprof/remote/client.rb', line 18 def run start wait fetch_results save_results enter_console end |
#save_results ⇒ Object
55 56 57 58 |
# File 'lib/stackprof/remote/client.rb', line 55 def save_results File.open(result_path, 'wb') {|f| f << @results } puts "Saved results to #{result_path}" end |
#start ⇒ Object
26 27 28 29 30 31 32 33 34 |
# 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 ⇒ Object
36 37 38 39 |
# File 'lib/stackprof/remote/client.rb', line 36 def wait puts "Waiting for #{@wait} seconds" sleep @wait end |