9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/qprof.rb', line 9
def call(title = '')
FileUtils.mkdir_p('/tmp/qprof')
run = "#{Time.now.to_i}-#{SecureRandom.hex(4)}"
dump_path = "/tmp/qprof/#{run}.dump"
graph_path = "/tmp/qprof/#{run}.html"
StackProf.run(mode: :cpu, interval: 2, raw: true, out: dump_path) do
@value = yield
end
flame_io = StringIO.new
StackProf::Report.from_file(dump_path).print_d3_flamegraph(flame_io)
File.write(graph_path, flame_io.string)
Launchy.open(graph_path)
@value
end
|