Skip to content

Instantly share code, notes, and snippets.

@blaedj
Created November 21, 2023 20:44
Show Gist options
  • Save blaedj/0a2f5a045b4a86852e0e84b5fcbe3398 to your computer and use it in GitHub Desktop.
Save blaedj/0a2f5a045b4a86852e0e84b5fcbe3398 to your computer and use it in GitHub Desktop.
watch.rb for vernier - traps info signal to start/stop profiling
# put this inside vernier/lib/vernier/watch.rb
# to use with e.g. rails server:
# $ 'RUBYOPT='-I/path-containing-vernier-repo/vernier/lib -rvernier/watch' rails server
# then sending the 'info' signal (shoult be Ctrl-T on macos terminal) will start/stop profiling
require "vernier"
class Null
def self.record_interval name
yield
end
end
$collector = Null
def vernier
$collector
end
trap(:INFO) do
if $collector == Null
puts "starting collector"
$collector = Vernier::Collector.new(:wall)
$collector.start
puts "started collector"
else
puts "stopping collector"
result = $collector.stop
FIle.write("time_profile.json", Vernier::Output::Firefox.new(result).output)
$collector = Null
puts "stopped collector"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment