From 41af606db385abe429888c5aca8b2e86c8830c24 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 18 Jan 2009 05:16:39 +0000 Subject: [PATCH] Remove script/performance/profiler in favour of performance integration tests. To continue using script/performance/profiler, install the request_profiler plugin : script/plugin install git://github.com/rails/request_profiler.git --- .../lib/action_controller/request_profiler.rb | 168 ------------------ railties/CHANGELOG | 6 + railties/bin/performance/request | 3 - railties/lib/commands/performance/request.rb | 6 - .../applications/app/app_generator.rb | 2 +- 5 files changed, 7 insertions(+), 178 deletions(-) delete mode 100644 actionpack/lib/action_controller/request_profiler.rb delete mode 100755 railties/bin/performance/request delete mode 100755 railties/lib/commands/performance/request.rb diff --git a/actionpack/lib/action_controller/request_profiler.rb b/actionpack/lib/action_controller/request_profiler.rb deleted file mode 100644 index 80cd55334f..0000000000 --- a/actionpack/lib/action_controller/request_profiler.rb +++ /dev/null @@ -1,168 +0,0 @@ -require 'optparse' - -module ActionController - class RequestProfiler - # Wrap up the integration session runner. - class Sandbox - include Integration::Runner - - def self.benchmark(n, script) - new(script).benchmark(n) - end - - def initialize(script_path) - @quiet = false - define_run_method(script_path) - reset! - end - - def benchmark(n, profiling = false) - @quiet = true - print ' ' - - ms = Benchmark.ms do - n.times do |i| - run(profiling) - print_progress(i) - end - end - - puts - ms - ensure - @quiet = false - end - - def say(message) - puts " #{message}" unless @quiet - end - - private - def define_run_method(script_path) - script = File.read(script_path) - - source = <<-end_source - def run(profiling = false) - if profiling - RubyProf.resume do - #{script} - end - else - #{script} - end - - old_request_count = request_count - reset! - self.request_count = old_request_count - end - end_source - - instance_eval source, script_path, 1 - end - - def print_progress(i) - print "\n " if i % 60 == 0 - print ' ' if i % 10 == 0 - print '.' - $stdout.flush - end - end - - - attr_reader :options - - def initialize(options = {}) - @options = default_options.merge(options) - end - - - def self.run(args = nil, options = {}) - profiler = new(options) - profiler.parse_options(args) if args - profiler.run - end - - def run - sandbox = Sandbox.new(options[:script]) - - puts 'Warming up once' - - elapsed = warmup(sandbox) - puts '%.0f ms, %d requests, %d req/sec' % [elapsed, sandbox.request_count, 1000 * sandbox.request_count / elapsed] - puts "\n#{options[:benchmark] ? 'Benchmarking' : 'Profiling'} #{options[:n]}x" - - options[:benchmark] ? benchmark(sandbox) : profile(sandbox) - end - - def profile(sandbox) - load_ruby_prof - - benchmark(sandbox, true) - results = RubyProf.stop - - show_profile_results results - results - end - - def benchmark(sandbox, profiling = false) - sandbox.request_count = 0 - elapsed = sandbox.benchmark(options[:n], profiling) - count = sandbox.request_count.to_i - puts '%.0f ms, %d requests, %d req/sec' % [elapsed, count, 1000 * count / elapsed] - end - - def warmup(sandbox) - Benchmark.ms { sandbox.run(false) } - end - - def default_options - { :n => 100, :open => 'open %s &' } - end - - # Parse command-line options - def parse_options(args) - OptionParser.new do |opt| - opt.banner = "USAGE: #{$0} [options] [session script path]" - - opt.on('-n', '--times [100]', 'How many requests to process. Defaults to 100.') { |v| options[:n] = v.to_i if v } - opt.on('-b', '--benchmark', 'Benchmark instead of profiling') { |v| options[:benchmark] = v } - opt.on('-m', '--measure [mode]', 'Which ruby-prof measure mode to use: process_time, wall_time, cpu_time, allocations, or memory. Defaults to process_time.') { |v| options[:measure] = v } - opt.on('--open [CMD]', 'Command to open profile results. Defaults to "open %s &"') { |v| options[:open] = v } - opt.on('-h', '--help', 'Show this help') { puts opt; exit } - - opt.parse args - - if args.empty? - puts opt - exit - end - options[:script] = args.pop - end - end - - protected - def load_ruby_prof - begin - gem 'ruby-prof', '>= 0.6.1' - require 'ruby-prof' - if mode = options[:measure] - RubyProf.measure_mode = RubyProf.const_get(mode.upcase) - end - rescue LoadError - abort '`gem install ruby-prof` to use the profiler' - end - end - - def show_profile_results(results) - File.open "#{RAILS_ROOT}/tmp/profile-graph.html", 'w' do |file| - RubyProf::GraphHtmlPrinter.new(results).print(file) - `#{options[:open] % file.path}` if options[:open] - end - - File.open "#{RAILS_ROOT}/tmp/profile-flat.txt", 'w' do |file| - RubyProf::FlatPrinter.new(results).print(file) - `#{options[:open] % file.path}` if options[:open] - end - end - end -end diff --git a/railties/CHANGELOG b/railties/CHANGELOG index b313f082a3..b36f57f75d 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,11 @@ *2.3.0 [Edge]* +* Remove script/performance/profiler in favour of performance integration tests. [Pratik Naik] + + To continue using script/performance/profiler, install the request_profiler plugin : + + script/plugin install git://github.com/rails/request_profiler.git + * Add a rake task to apply a template to an existing application : rake rails:template LOCATION=~/template.rb [Pratik Naik] * Add "-m/--template" option to Rails generator to apply a template to the generated application. [Jeremy McAnally] diff --git a/railties/bin/performance/request b/railties/bin/performance/request deleted file mode 100755 index ae3f38c74b..0000000000 --- a/railties/bin/performance/request +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../../config/boot' -require 'commands/performance/request' diff --git a/railties/lib/commands/performance/request.rb b/railties/lib/commands/performance/request.rb deleted file mode 100755 index 1773886487..0000000000 --- a/railties/lib/commands/performance/request.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby -require 'config/environment' -require 'application' -require 'action_controller/request_profiler' - -ActionController::RequestProfiler.run(ARGV) diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb index 795a0d7653..2c31d89538 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -151,7 +151,7 @@ def create_public_files(m) def create_script_files(m) %w( about console dbconsole destroy generate runner server plugin - performance/benchmarker performance/profiler performance/request + performance/benchmarker performance/profiler ).each do |file| m.file "bin/#{file}", "script/#{file}", { :chmod => 0755, -- GitLab