Created
June 23, 2009 18:30
-
-
Save benders/134738 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ENV["RAILS_ENV"] = "profiling" | |
require File.expand_path(File.dirname(__FILE__) + "/../../config/environment") | |
require File.expand_path(File.dirname(__FILE__) + "/../../vendor/rails/actionmailer/lib/actionmailer") | |
require 'test_help' | |
require 'ruby-prof' | |
require 'app/controllers/products_controller' | |
class ProductsController | |
alias :orig_method :offer | |
def offer | |
if params[:profile] then | |
params[:profile] = false | |
result = RubyProf.profile do | |
orig_method | |
end | |
measure_names = { RubyProf::MEMORY => 'memory', RubyProf::PROCESS_TIME => 'time' } | |
printer = RubyProf::CallTreePrinter.new(result) | |
printer.print(File.open("callgrind.offer_#{measure_names[RubyProf::measure_mode]}.out", 'w')) | |
# printer = RubyProf::GraphHtmlPrinter.new(result) | |
# printer.print(File.open("callgrind.offer_#{measure_names[RubyProf::measure_mode]}.html", 'w')) | |
else | |
orig_method | |
end | |
end | |
end | |
class OfferProfilingTest < ActionController::IntegrationTest | |
def setup | |
GC.disable | |
end | |
def teardown | |
GC.enable | |
end | |
def test_index | |
get 'products/offer?phonenumber=12345678901' | |
profile :get, 'products/offer?phonenumber= 12345678901&profile=true' | |
end | |
def profile(method, url) | |
RubyProf.measure_mode = RubyProf::PROCESS_TIME | |
send(method, url) | |
RubyProf.measure_mode = RubyProf::MEMORY | |
send(method, url) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Settings specified here will take precedence over those in config/environment.rb | |
# The production environment is meant for finished, "live" apps. | |
# Code is not reloaded between requests | |
config.cache_classes = true | |
# Use a different logger for distributed setups | |
# config.logger = SyslogLogger.new | |
# Full error reports are disabled and caching is turned on | |
config.action_controller.consider_all_requests_local = false | |
config.action_controller.perform_caching = true | |
config.action_view.cache_template_loading = true | |
# Use a different cache store in production | |
# config.cache_store = :mem_cache_store | |
# Enable serving of images, stylesheets, and javascripts from an asset server | |
# config.action_controller.asset_host = "http://assets.example.com" | |
# Disable delivery errors, bad email addresses will be ignored | |
# config.action_mailer.raise_delivery_errors = false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment