First, profile. Second, profile.
SpeedGun is a better web app profiler on Rails and Rack apps.
Add this line to your application's Gemfile:
gem 'speed_gun'
And then execute:
$ bundle
Or install it yourself as:
$ gem install speed_gun
You don't require settings in development.
In production. You should set enable_if
and authorize_proc
configs.
require 'speed_gun'
class MyApplication < Sinatra::Base
use SpeedGun::Middleware
end
SpeedGun has built-in profilers.
SpeedGun::Profiler::ActionController
SpeedGun::Profiler::ActionView
SpeedGun::Profiler::ActiveRecord
SpeedGun::Profiler::Rack
these profilers don't need configuration.
If you want take profile manually. You can use SpeedGun.profile
method.
SpeedGun.profile("MyProfile#method") do
my_profile.method()
end
SpeedGun is supporting profiling on javascript. You can use speedGun.profile
or speedGun.profileMethod
.
speedGun.profile("any title", function() { ... codes ...});
var object = { func: function() { ... codes ... } };
speedGun.profileMethod(object, "func", "any title");
And SpeedGun collect browser informations.
- User Agent
- Perfomance API(if implemented)
You can create your custom profilers. a custom profiler require title
method.
Some examples:
class SimpleCustomProfiler < SpeedGun::Profiler::Base
def title
'simple'
end
end
SpeedGun.profile(:simple_custom_profiler) { ... }
class BeforeFilerProfiler < SpeedGun::Profiler::Base
# `hook_method` is a helper of method profiling.
hook_method ApplicationControler, :some_filter
end
class ApplicationControler
def some_filer
...
end
end
class ForceGCProfiler < SpeedGun::Profiler::Base
# You can define profiler type name.
def self.type
:force_gc_profiler
end
# `#before_profile` is called on before profiling.
def before_profile
@before_gc_disable = GC.enable
GC.start
end
# `#after_profile` is called on after profiling.
def after_profile
GC.disable if @before_gc_disable
end
end
SpeedGun.profile(:force_gc_profiler) { ... }
SpeedGun store request informations(profiling, environments and browser infos). You can select store engines.
SpeedGun::Store::Memory
(default store engine on rack)max_entries
option: Set number of max profile entries(default: 100)
SpeedGun::Store::File
(default store engine on rails)path
option: Set stored path(default:/tmp/speed_gun
orRails.root/tmp/speed_gun
)expires
option: Set expires in seconds(default: 1 day)
SpeedGun::Store::Memcache
(beforerequire 'speed_gun/store/memcache'
)client
option: Set memcache client instance(default:Dalli::Clinet.new
)prefix
option: Set prefix of your profile key(default:'speed-gun-'
)expires
option: Set expires in seconds(default: 1 day)
SpeedGun::Store::Redis
(beforerequire 'speed_gun/store/redis'
)client
option: Set redis client instance(default:Redis.new
)prefix
option: Set prefix of your profile key(default:'speed-gun-'
)expires
option: Set expires in seconds(default: 1 day)
SpeedGun's store engines requires []
and []=
methods.
Please pull-requests http://github.com/rosylilly/speed_gun