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|
profile = Pf2.stop
profile = JSON.parse(profile, symbolize_names: true, max_nesting: false)
res.header['Content-Type'] = 'application/json'
res.header['Access-Control-Allow-Origin'] = '*'
res.body = JSON.generate(Pf2::Reporter::FirefoxProfiler.new((profile)).emit)
Pf2.start
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