├── test ├── tmp │ └── .keep ├── dummy │ ├── log │ │ └── .keep │ ├── app │ │ ├── mailers │ │ │ └── .keep │ │ ├── models │ │ │ ├── .keep │ │ │ └── concerns │ │ │ │ └── .keep │ │ ├── assets │ │ │ ├── images │ │ │ │ └── .keep │ │ │ ├── javascripts │ │ │ │ └── application.js │ │ │ └── stylesheets │ │ │ │ └── application.css │ │ ├── controllers │ │ │ ├── concerns │ │ │ │ └── .keep │ │ │ └── application_controller.rb │ │ ├── helpers │ │ │ └── application_helper.rb │ │ └── views │ │ │ └── layouts │ │ │ └── application.html.erb │ ├── lib │ │ └── assets │ │ │ └── .keep │ ├── public │ │ ├── favicon.ico │ │ ├── 500.html │ │ ├── 422.html │ │ └── 404.html │ ├── bin │ │ ├── rake │ │ ├── bundle │ │ └── rails │ ├── config │ │ ├── routes.rb │ │ ├── initializers │ │ │ ├── cookies_serializer.rb │ │ │ ├── session_store.rb │ │ │ ├── mime_types.rb │ │ │ ├── filter_parameter_logging.rb │ │ │ ├── assets.rb │ │ │ ├── backtrace_silencers.rb │ │ │ ├── wrap_parameters.rb │ │ │ └── inflections.rb │ │ ├── environment.rb │ │ ├── boot.rb │ │ ├── database.yml │ │ ├── locales │ │ │ └── en.yml │ │ ├── application.rb │ │ ├── secrets.yml │ │ └── environments │ │ │ ├── development.rb │ │ │ ├── test.rb │ │ │ └── production.rb │ ├── config.ru │ ├── Rakefile │ └── README.rdoc ├── mocks │ └── fake_app.rb ├── integration │ └── navigation_test.rb ├── controllers │ └── rails_ruby_prof │ │ └── home_controller_test.rb ├── test_helper.rb └── lib │ └── ruby-prof │ └── rails │ ├── printer_setup_test.rb │ ├── profile_test.rb │ ├── profiles_test.rb │ ├── profiles_mock_module.rb │ ├── runner_button_test.rb │ ├── printer_test.rb │ ├── printers_test.rb │ ├── config_test.rb │ ├── config_validation_test.rb │ └── runner_test.rb ├── lib ├── ruby-prof │ └── rails │ │ ├── version.rb │ │ ├── engine.rb │ │ ├── profiles.rb │ │ ├── config.rb │ │ ├── printer_setup.rb │ │ ├── filename_module.rb │ │ ├── profile.rb │ │ ├── printer.rb │ │ ├── printers.rb │ │ ├── config_validation.rb │ │ ├── runner_button.rb │ │ └── runner.rb ├── ruby-prof-rails.rb └── rack │ └── ruby-prof-rails.rb ├── doc ├── ruby_prof_rails_start.png ├── ruby_prof_rails_stop.png └── ruby_prof_rails_profiles.png ├── app ├── helpers │ └── ruby_prof_rails │ │ ├── application_helper.rb │ │ └── home_helper.rb ├── views │ ├── ruby_prof_rails │ │ ├── home │ │ │ ├── help │ │ │ │ ├── _exclude_formats.html.erb │ │ │ │ ├── _eliminate_methods.html.erb │ │ │ │ ├── _printers.html.erb │ │ │ │ └── _measurement.html.erb │ │ │ ├── _bootstrap_modal.html.erb │ │ │ ├── _profiles.html.erb │ │ │ └── index.html.erb │ │ └── runner │ │ │ └── _button.html │ └── layouts │ │ └── ruby_prof_rails │ │ └── application.html.erb ├── assets │ ├── javascripts │ │ └── ruby_prof_rails │ │ │ ├── application.js │ │ │ ├── home.js │ │ │ ├── jquery_ujs.js │ │ │ └── jquery.min.js │ └── stylesheets │ │ └── ruby_prof_rails │ │ ├── application.css │ │ └── home.css └── controllers │ └── ruby_prof_rails │ ├── printer_controller.rb │ ├── application_controller.rb │ ├── profile_controller.rb │ └── home_controller.rb ├── .gitignore ├── config └── routes.rb ├── bin └── rails ├── Gemfile ├── Rakefile ├── MIT-LICENSE ├── ruby_prof_rails.gemspec └── README.md /test/tmp/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/log/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/app/mailers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/app/models/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/lib/assets/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/app/assets/images/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/app/models/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /lib/ruby-prof/rails/version.rb: -------------------------------------------------------------------------------- 1 | module RubyProf 2 | module Rails 3 | VERSION = '1.0.0' 4 | end 5 | end -------------------------------------------------------------------------------- /doc/ruby_prof_rails_start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tleish/ruby-prof-rails/HEAD/doc/ruby_prof_rails_start.png -------------------------------------------------------------------------------- /doc/ruby_prof_rails_stop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tleish/ruby-prof-rails/HEAD/doc/ruby_prof_rails_stop.png -------------------------------------------------------------------------------- /app/helpers/ruby_prof_rails/application_helper.rb: -------------------------------------------------------------------------------- 1 | module RubyProfRails 2 | module ApplicationHelper 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /doc/ruby_prof_rails_profiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tleish/ruby-prof-rails/HEAD/doc/ruby_prof_rails_profiles.png -------------------------------------------------------------------------------- /lib/ruby-prof-rails.rb: -------------------------------------------------------------------------------- 1 | require 'ruby-prof/rails/engine' 2 | 3 | module RubyProf 4 | module Rails 5 | 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /test/dummy/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative '../config/boot' 3 | require 'rake' 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /test/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | mount RubyProf::Rails::Engine => "/ruby_prof_rails" 3 | end 4 | -------------------------------------------------------------------------------- /test/mocks/fake_app.rb: -------------------------------------------------------------------------------- 1 | require 'sinatra' 2 | 3 | class FakeApp < Sinatra::Base 4 | get "/" do 5 | "foo" 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /test/dummy/bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /test/dummy/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../../config/application', __FILE__) 3 | require_relative '../config/boot' 4 | require 'rails/commands' 5 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.action_dispatch.cookies_serializer = :json -------------------------------------------------------------------------------- /test/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Rails.application 5 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.session_store :cookie_store, key: '_dummy_session' 4 | -------------------------------------------------------------------------------- /test/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | -------------------------------------------------------------------------------- /test/integration/navigation_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class NavigationTest < ActionDispatch::IntegrationTest 4 | fixtures :all 5 | 6 | # test "the truth" do 7 | # assert true 8 | # end 9 | end 10 | 11 | -------------------------------------------------------------------------------- /app/helpers/ruby_prof_rails/home_helper.rb: -------------------------------------------------------------------------------- 1 | module RubyProfRails 2 | module HomeHelper 3 | 4 | def my_profiles 5 | @profiles.select { |profile| profile.session_id == request.session_options[:id] } 6 | end 7 | 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .bundle/ 2 | log/*.log 3 | pkg/ 4 | coverage/ 5 | test/dummy/db/*.sqlite3 6 | test/dummy/db/*.sqlite3-journal 7 | test/dummy/log/*.log 8 | test/dummy/tmp/ 9 | test/dummy/.sass-cache 10 | custom_plan.rb 11 | zeus.json 12 | Gemfile.lock 13 | .idea 14 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | # Prevent CSRF attacks by raising an exception. 3 | # For APIs, you may want to use :null_session instead. 4 | protect_from_forgery with: :exception 5 | end 6 | -------------------------------------------------------------------------------- /test/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | # Set up gems listed in the Gemfile. 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) 3 | 4 | require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) 5 | $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) 6 | -------------------------------------------------------------------------------- /test/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | RubyProf::Rails::Engine.routes.draw do 2 | 3 | namespace :ruby_prof_rails do 4 | post '' => 'home#update' 5 | root to: 'home#index' 6 | resources :home , path: '' 7 | post 'profile' => 'profile#batch', :as => :profile_batch 8 | resources :profile 9 | resources :printer 10 | 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /test/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |2 | ruby-prof-rails supports excluding specific request file formats from the routes. 3 |
4 |5 | For example, you likely want to skip images (png, jpg, gif), unless you 6 | are producing these images via rails code. 7 |
8 |9 | exclude_formats is a list of file formats (line separated text). 10 |
11 |<%= @default_exclude_formats %>
12 |13 | Any routes with the file formats specified will be ignored and skipped over. 14 |
15 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters) 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /test/dummy/README.rdoc: -------------------------------------------------------------------------------- 1 | == README 2 | 3 | This README would normally document whatever steps are necessary to get the 4 | application up and running. 5 | 6 | Things you may want to cover: 7 | 8 | * Ruby version 9 | 10 | * System dependencies 11 | 12 | * Configuration 13 | 14 | * Database creation 15 | 16 | * Database initialization 17 | 18 | * How to run the test suite 19 | 20 | * Services (job queues, cache servers, search engines, etc.) 21 | 22 | * Deployment instructions 23 | 24 | * ... 25 | 26 | 27 | Please feel free to use a different markup language if you do not plan to run 28 | rake doc:app. 29 | -------------------------------------------------------------------------------- /test/dummy/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | # 7 | default: &default 8 | adapter: sqlite3 9 | pool: 5 10 | timeout: 5000 11 | 12 | development: 13 | <<: *default 14 | database: db/development.sqlite3 15 | 16 | # Warning: The database defined as "test" will be erased and 17 | # re-generated from your development database when you run "rake". 18 | # Do not set this db to the same as development or production. 19 | test: 20 | <<: *default 21 | database: db/test.sqlite3 22 | 23 | production: 24 | <<: *default 25 | database: db/production.sqlite3 26 | -------------------------------------------------------------------------------- /test/dummy/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. 9 | // 10 | // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require_tree . 14 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | # Declare your gem's dependencies in rails_ruby_prof.gemspec. 4 | # Bundler will treat runtime dependencies like base dependencies, and 5 | # development dependencies will be added by default to the :development group. 6 | gemspec 7 | 8 | # Declare any dependencies that are still in development here instead of in 9 | # your gemspec. These might include edge Rails or gems from your path or 10 | # Git. Remember to move these dependencies to your gemspec before releasing 11 | # your gem to rubygems.org. 12 | 13 | # To use debugger 14 | # gem 'debugger' 15 | 16 | group :test do 17 | gem 'sqlite3' 18 | gem 'minitest-rails-capybara' 19 | gem 'minitest-reporters' 20 | gem 'simplecov' 21 | end 22 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | require 'minitest/spec' 2 | require 'minitest/autorun' 3 | require 'rack/test' 4 | require 'mocha' 5 | require 'mocha/setup' 6 | require './lib/ruby-prof/rails/config' 7 | 8 | # Configure Rails Environment 9 | ENV['RAILS_ENV'] = 'test' 10 | 11 | require File.expand_path('../../test/dummy/config/environment.rb', __FILE__) 12 | # ActiveRecord::Migrator.migrations_paths = [File.expand_path('../../test/dummy/db/migrate', __FILE__)] 13 | # ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__) 14 | require 'rails/test_help' 15 | require 'minitest/rails' 16 | require 'minitest/rails/capybara' 17 | 18 | Rails.backtrace_cleaner.remove_silencers! 19 | 20 | RubyProf::Rails::Config.path = 'test/tmp' -------------------------------------------------------------------------------- /app/assets/javascripts/ruby_prof_rails/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. 9 | // 10 | // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require ./jquery.min 14 | //= require ./jquery_ujs 15 | //= require ./home -------------------------------------------------------------------------------- /test/dummy/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /test/dummy/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /app/assets/stylesheets/ruby_prof_rails/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any styles 10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new 11 | * file per style scope. 12 | * 13 | *= require ./home 14 | *= require_self 15 | */ -------------------------------------------------------------------------------- /test/dummy/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any styles 10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new 11 | * file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /lib/ruby-prof/rails/profiles.rb: -------------------------------------------------------------------------------- 1 | require_relative 'config' 2 | require_relative 'profile' 3 | require_relative 'filename_module' 4 | 5 | module RubyProf 6 | module Rails 7 | # RubyProf Rails Profile Utility 8 | class Profiles 9 | 10 | include RubyProf::Rails::FilenameModule 11 | 12 | class << self 13 | def list 14 | Dir[File.join(RubyProf::Rails::Config.path, "#{PREFIX}*.yml")].reverse.map do |file| 15 | RubyProf::Rails::Profile.new(file) 16 | end 17 | end 18 | 19 | def find(id) 20 | profiles = self.list 21 | profile = profiles.detect { |profile| profile.id == id } 22 | return profile if profile && profile.exists? 23 | end 24 | end 25 | 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | begin 2 | require 'bundler/setup' 3 | rescue LoadError 4 | puts 'You must `gem install bundler` and `bundle install` to run rake tasks' 5 | end 6 | 7 | require 'rdoc/task' 8 | 9 | RDoc::Task.new(:rdoc) do |rdoc| 10 | rdoc.rdoc_dir = 'rdoc' 11 | rdoc.title = 'RailsRubyProf' 12 | rdoc.options << '--line-numbers' 13 | rdoc.rdoc_files.include('README.rdoc') 14 | rdoc.rdoc_files.include('lib/**/*.rb') 15 | end 16 | 17 | APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__) 18 | load 'rails/tasks/engine.rake' 19 | 20 | 21 | 22 | Bundler::GemHelper.install_tasks 23 | 24 | require 'rake/testtask' 25 | 26 | Rake::TestTask.new(:test) do |t| 27 | t.libs << 'lib' 28 | t.libs << 'test' 29 | t.pattern = 'test/**/*_test.rb' 30 | t.verbose = false 31 | end 32 | 33 | 34 | task default: :test 35 | -------------------------------------------------------------------------------- /app/views/ruby_prof_rails/runner/_button.html: -------------------------------------------------------------------------------- 1 | 29 | 30 | 31 | Ruby-Prof Rails: Profiling... 32 | -------------------------------------------------------------------------------- /app/controllers/ruby_prof_rails/printer_controller.rb: -------------------------------------------------------------------------------- 1 | module RubyProfRails 2 | class PrinterController < RubyProfRails::ApplicationController 3 | 4 | RUBY_PROF_GEM_DIR = Gem::Specification.find_by_name('ruby-prof').gem_dir 5 | 6 | def show 7 | printer = printers[params[:id].to_sym] || 'no-printer' 8 | printer_path = File.join(RUBY_PROF_GEM_DIR, 'examples', printer) 9 | 10 | if printer && File.exist?(printer_path) 11 | send_file printer_path 12 | else 13 | render text: 'Printer example was not found.' # write some content to the body 14 | end 15 | end 16 | 17 | private 18 | 19 | def printers 20 | RubyProf::Rails::Printers.hash.merge( 21 | FlatPrinterWithLineNumbers: 'flat.txt', 22 | CallTreePrinter: 'multi.grind.dat' 23 | ) 24 | end 25 | 26 | end 27 | end -------------------------------------------------------------------------------- /app/views/ruby_prof_rails/home/help/_eliminate_methods.html.erb: -------------------------------------------------------------------------------- 1 |2 | ruby-prof supports eliminating specific methods from profiling 3 | results. This is useful for reducing connectivity in the call graph, making 4 | it easier to identify the source of performance problems when using a graph 5 | printer. 6 |
7 |8 | For example, consider Integer#times: it's hardly ever useful to know 9 | how much time is spent in the method itself. We're much more interested 10 | in how much the passed in block contributes to the time spent in the method 11 | which contains the Integer#times call. 12 |
13 |14 | eliminate_methods is a list of regular expressions (line separated text). 15 |
16 |
17 | Integer#times
18 | String#.*
19 |
21 | After eliminating methods the resulting profile will appear exactly as if 22 | those methods had been inlined at their call sites. 23 |
24 | -------------------------------------------------------------------------------- /lib/ruby-prof/rails/config.rb: -------------------------------------------------------------------------------- 1 | module RubyProf 2 | module Rails 3 | # server configuration for RubyProfRails application 4 | class Config 5 | 6 | DEFAULT_EXCLUDE_FORMATS = %w{css js json map jpg jpeg png gif}.join(', ') 7 | 8 | class << self 9 | attr_accessor :username, :password, :path, :exclude_formats, :session_auth_lambda, :debug 10 | 11 | def path 12 | @path ||= File.join(::Rails.root, 'tmp', 'ruby-prof-rails') 13 | Pathname(@path) 14 | end 15 | 16 | def exclude_formats 17 | @exclude_formats || DEFAULT_EXCLUDE_FORMATS 18 | end 19 | 20 | def extract_options_from(env) 21 | Hash(env['rack.session'][:ruby_prof_rails]) 22 | end 23 | 24 | def http_basic_authenticate 25 | { 26 | name: username, 27 | password: password 28 | } 29 | end 30 | 31 | end 32 | 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /test/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require 'rails/all' 4 | 5 | Bundler.require(*Rails.groups) 6 | require 'ruby-prof-rails' 7 | 8 | module Dummy 9 | class Application < Rails::Application 10 | # Settings in config/environments/* take precedence over those specified here. 11 | # Application configuration should go into files in config/initializers 12 | # -- all .rb files in that directory are automatically loaded. 13 | 14 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 15 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 16 | # config.time_zone = 'Central Time (US & Canada)' 17 | 18 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 19 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 20 | # config.i18n.default_locale = :de 21 | end 22 | end 23 | 24 | -------------------------------------------------------------------------------- /lib/ruby-prof/rails/printer_setup.rb: -------------------------------------------------------------------------------- 1 | require_relative 'profiles' 2 | require_relative 'printers' 3 | require_relative 'filename_module' 4 | 5 | module RubyProf 6 | module Rails 7 | # RubyProf Rails PrinterSetup class 8 | class PrinterSetup 9 | attr_accessor :key, :printer_class, :filename 10 | 11 | include RubyProf::Rails::FilenameModule 12 | 13 | def initialize(options = {}) 14 | @type = options.fetch(:type) 15 | @request = options.fetch(:request) 16 | setup_printer 17 | end 18 | 19 | private 20 | 21 | def setup_printer 22 | @key = find_printer.type 23 | @printer_class = find_printer.printer_class 24 | @filename = hash_to_filename 25 | end 26 | 27 | def find_printer 28 | @printer_config ||= RubyProf::Rails::Printers.find_by(@type) || printer_default 29 | end 30 | 31 | def printer_default 32 | RubyProf::Rails::Printers.default 33 | end 34 | 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /test/lib/ruby-prof/rails/printer_setup_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | require './lib/ruby-prof/rails/printer_setup' 3 | 4 | describe RubyProf::Rails::PrinterSetup do 5 | 6 | describe 'setup' do 7 | it 'return a printer setup object' do 8 | RubyProf::Rails::Printers.hash.each do |printer, filename| 9 | @setup = RubyProf::Rails::PrinterSetup.new( request: mock_request(mock_env(printer)), type: printer ) 10 | @setup.key.must_equal printer 11 | @setup.printer_class.must_equal "RubyProf::#{printer}".constantize 12 | @setup.filename.must_match /.*#{filename}$/ 13 | end 14 | end 15 | 16 | end 17 | 18 | private 19 | 20 | def mock_request(env) 21 | Rack::Request.new(env) 22 | end 23 | 24 | def mock_env(printer) 25 | { 26 | 'rack.session' => { 27 | ruby_prof_rails: { 28 | printers: printer 29 | } 30 | }, 31 | 'rack.session.options' => { 32 | id: SecureRandom.hex 33 | } 34 | } 35 | end 36 | 37 | end 38 | -------------------------------------------------------------------------------- /app/controllers/ruby_prof_rails/application_controller.rb: -------------------------------------------------------------------------------- 1 | require 'ruby-prof/rails/config_validation' 2 | 3 | module RubyProfRails 4 | class ApplicationController < ActionController::Base 5 | before_action :init_vars, :properly_configured?, :session_authenticate 6 | http_basic_authenticate_with RubyProf::Rails::Config.http_basic_authenticate 7 | 8 | private 9 | 10 | def init_vars 11 | @config = RubyProf::Rails::Config 12 | @config_validation = RubyProf::Rails::ConfigValidation.new(config: @config, app_config: ::Rails.application.config) 13 | @routes = ruby_prof_rails_engine 14 | end 15 | 16 | def properly_configured? 17 | return if @enable_config ||= @config_validation.properly_configured? 18 | flash[:alert] = ('To profile a Rails application it is vital to run it using production like settings 7 | (cache classes, cache view lookups, etc.). Otherwise, Rail's dependency loading code will overwhelm any time spent 8 | in the application itself (our tests show that Rails dependency loading causes a roughly 6x slowdown).
9 |To enable Rails Ruby Prof configuration you must initially set config.cache_classes = true.
} 10 | 11 | HAS_AUTHENTICATION_ALERT = %q{For security this page is disabled until RubyProf::Rails::Config.username 12 | and RubyProf::Rails::Config.password has been configured (see documentation). } 13 | 14 | def initialize(args) 15 | @config = args.fetch(:config) 16 | @cache_classes = args.fetch(:app_config).cache_classes 17 | end 18 | 19 | def properly_configured? 20 | @config.debug || (@cache_classes && has_authentication?) 21 | end 22 | 23 | def session_auth_lambda?(session) 24 | session_auth_lambda = @config.session_auth_lambda 25 | session_auth_lambda ? session_auth_lambda.call(session) : true 26 | end 27 | 28 | def alerts 29 | alerts = [] 30 | alerts << CACHE_CLASS_ENABLED_ALERT unless @cache_classes 31 | alerts << HAS_AUTHENTICATION_ALERT unless has_authentication? 32 | alerts 33 | end 34 | 35 | private 36 | 37 | def has_authentication? 38 | @config.username.present? || @config.password.present? 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /test/lib/ruby-prof/rails/runner_button_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | require './test/mocks/fake_app' 3 | require './lib/ruby-prof/rails/runner_button' 4 | require 'mocha' 5 | 6 | 7 | describe RubyProf::Rails::Profiles do 8 | 9 | describe 'draw' do 10 | it 'it returns exact response if header is not html' do 11 | response_orig = [mock_status, mock_header('application/json'), mock_html] 12 | response = RubyProf::Rails::RunnerButton.new( app: mock_app, response: response_orig ).draw 13 | response.must_equal response_orig 14 | end 15 | 16 | it 'it modified body if header is not html' do 17 | ::Rails.application.stubs(:routes).returns(mock_routes) 18 | response_orig = [mock_status, mock_header, mock_html] 19 | response = RubyProf::Rails::RunnerButton.new( app: mock_app, response: response_orig ).draw 20 | (response == response_orig).must_equal false 21 | response.last.body.first.include?('ruby-prof-rails-button').must_equal true 22 | end 23 | 24 | end 25 | 26 | private 27 | 28 | def mock_html 29 | '
' 30 | end 31 | 32 | def mock_app 33 | app = FakeApp.new 34 | # app.stubs(:routes).returns(mock_routes) 35 | # app 36 | end 37 | 38 | def mock_routes 39 | stub(named_routes: {'ruby_prof_rails_engine' => stub( 40 | app: stub(routes: stub(named_routes: stub( 41 | routes: {ruby_prof_rails_home_index: stub( 42 | path: stub(spec: '/ruby_prof_rails(.:format)'))})))) }) 43 | end 44 | 45 | def mock_status 46 | 200 47 | end 48 | 49 | def mock_header(content_type = 'text/html') 50 | {'Content-Type' => content_type} 51 | end 52 | 53 | def mock_body 54 | '' 55 | end 56 | 57 | end 58 | -------------------------------------------------------------------------------- /app/controllers/ruby_prof_rails/profile_controller.rb: -------------------------------------------------------------------------------- 1 | module RubyProfRails 2 | class ProfileController < RubyProfRails::ApplicationController 3 | 4 | include ActionView::Helpers::TextHelper 5 | 6 | def show 7 | profile = RubyProf::Rails::Profiles.find(params[:id]) 8 | if profile 9 | time = profile.time.strftime('%Y-%m-%d_%I-%M-%S-%Z') 10 | send_file profile.filename, filename: "#{profile.hash[:prefix]}_#{time}.#{profile.hash[:format]}" 11 | else 12 | render text: 'Profiler file was not found and may have been deleted.' # write some content to the body 13 | end 14 | end 15 | 16 | def destroy 17 | delete_profiles 18 | redirect_to redirect_with_anchor_path 19 | end 20 | 21 | def batch 22 | delete_profiles if params[:batch_method] = 'delete' 23 | redirect_to redirect_with_anchor_path 24 | end 25 | 26 | private 27 | 28 | def delete_profiles 29 | delete_profiles = Array(params[:id]).map { |id| delete_profile(id) } 30 | profiles = pluralize(delete_profiles.length, 'profile') 31 | if delete_profiles.empty? 32 | flash[:alert] = "No profiles selected" 33 | elsif delete_profiles.all? 34 | flash[:notice] = "#{profiles} deleted" 35 | else 36 | flash[:alert] = "#{profiles} not found" 37 | end 38 | end 39 | 40 | def delete_profile(id) 41 | profile = RubyProf::Rails::Profiles.find(id) 42 | return false unless profile 43 | File.unlink profile.manifest 44 | File.unlink profile.filename 45 | true 46 | end 47 | 48 | def redirect_with_anchor_path 49 | anchor = params[:tab].present? ? "##{params[:tab]}" : '' 50 | @routes.ruby_prof_rails_path + anchor 51 | end 52 | 53 | end 54 | end -------------------------------------------------------------------------------- /test/dummy/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |If you are the application owner check the logs for more information.
64 |Maybe you tried to change something you didn't have access to.
63 |If you are the application owner check the logs for more information.
65 |You may have mistyped the address or the page may have moved.
63 |If you are the application owner check the logs for more information.
65 |