module Vernier::Autorun
def self.at_exit
def self.at_exit stop if running? end
def self.running?
def self.running? !!@collector end
def self.start
def self.start interval = options.fetch(:interval, 500).to_i allocation_sample_rate = options.fetch(:allocation_sample_rate, 0).to_i hooks = options.fetch(:hooks, "").split(",") STDERR.puts("starting profiler with interval #{interval}") @collector = Vernier::Collector.new(:wall, interval:, allocation_sample_rate:, hooks:) @collector.start end
def self.stop
def self.stop result = @collector.stop @collector = nil output_path = options[:output] output_path ||= Tempfile.create(["profile", ".vernier.json.gz"]).path result.write(out: output_path) STDERR.puts(result.inspect) STDERR.puts("written to #{output_path}") end
def self.toggle
def self.toggle running? ? stop : start end