Sha256: 1be8a7f385da366e1c930cbc3ed4b57ca4f19042b6a641dcc8c542290e313312
Contents?: true
Size: 705 Bytes
Versions: 1
Compression:
Stored size: 705 Bytes
Contents
require 'fileutils' module StackProf class Middleware def initialize(app) @app = app at_exit{ Middleware.save if Middleware.enabled? } end def call(env) StackProf.start(mode: :cpu, interval: 1000) if self.class.enabled? @app.call(env) ensure StackProf.stop if self.class.enabled? end class << self attr_accessor :enabled alias enabled? enabled def save if results = StackProf.results FileUtils.mkdir_p('tmp') File.open("tmp/stackprof-#{results[:mode]}-#{Process.pid}-#{Time.now.to_i}.dump", 'w') do |f| f.write Marshal.dump(results) end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
stackprof-0.2.0 | lib/stackprof/middleware.rb |