20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/pf2/serve.rb', line 20
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.['Content-Type'] = 'application/json'
res.['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
|