def self.start
if File.basename($PROGRAM_NAME) == 'bundle' && ARGV.first == 'exec'
return
end
server = WEBrick::HTTPServer.new(CONFIG)
server.mount_proc('/profile') do |req, res|
config = Pf2.class_variable_get(:@@session).configuration
profile = Pf2.stop
res.header['Content-Type'] = 'application/json'
res.header['Access-Control-Allow-Origin'] = '*'
res.body = Pf2::Reporter::FirefoxProfilerSer2.new(profile).emit
Pf2.start(**config)
end
Pf2.start
Thread.new do
hostport = "#{server.config[:Host]}:#{server.config[:Port]}"
STDERR.puts "[Pf2] Listening on #{hostport}."
STDERR.puts "[Pf2] Open https://profiler.firefox.com/from-url/#{URI.encode_www_form_component("http://#{hostport}/profile")} for visualization."
STDERR.puts ""
server.start
end
end