GithubHelp home page GithubHelp logo

miniprofiler / rack-mini-profiler Goto Github PK

View Code? Open in Web Editor NEW
3.7K 57.0 398.0 1.97 MB

Profiler for your development and production Ruby rack apps.

License: MIT License

Ruby 65.30% CSS 4.08% JavaScript 27.70% HTML 0.20% SCSS 2.73%

rack-mini-profiler's Introduction

rack-mini-profiler

Middleware that displays speed badge for every HTML page, along with (optional) flamegraphs and memory profiling. Designed to work both in production and in development.

Screenshot 2023-04-05 at 3 13 52 PM

Features

  • Database profiling - Currently supports Mysql2, Postgres, Oracle (oracle_enhanced ~> 1.5.0) and Mongoid3 (with fallback support to ActiveRecord)
  • Call-stack profiling - Flame graphs showing time spent by gem
  • Memory profiling - Per-request memory usage, GC stats, and global allocation metrics

Learn more

rack-mini-profiler needs your help

We have decided to restructure our repository so there is a central UI repo and the various language implementations have their own.

WE NEED HELP.

If you feel like taking on any of this start an issue and update us on your progress.

Installation

Install/add to Gemfile in Ruby 2.6+

gem 'rack-mini-profiler'

NOTE: Be sure to require rack_mini_profiler below the pg and mysql gems in your Gemfile. rack_mini_profiler will identify these gems if they are loaded to insert instrumentation. If included too early no SQL will show up.

You can also include optional libraries to enable additional features.

# For memory profiling
gem 'memory_profiler'

# For call-stack profiling flamegraphs
gem 'stackprof'

Rails

All you have to do is to include the Gem and you're good to go in development. See notes below for use in production.

Upgrading to version 2.0.0

Prior to version 2.0.0, Mini Profiler patched various Rails methods to get the information it needed such as template rendering time. Starting from version 2.0.0, Mini Profiler doesn't patch any Rails methods by default and relies on ActiveSupport::Notifications to get the information it needs from Rails. If you want Mini Profiler to keep using its patches in version 2.0.0 and later, change the gem line in your Gemfile to the following:

If you want to manually require Mini Profiler:

gem 'rack-mini-profiler', require: ['enable_rails_patches']

If you don't want to manually require Mini Profiler:

gem 'rack-mini-profiler', require: ['enable_rails_patches', 'rack-mini-profiler']

Net::HTTP stack level too deep errors

If you start seeing SystemStackError: stack level too deep errors from Net::HTTP after installing Mini Profiler, this means there is another patch for Net::HTTP#request that conflicts with Mini Profiler's patch in your application. To fix this, change rack-mini-profiler gem line in your Gemfile to the following:

gem 'rack-mini-profiler', require: ['prepend_net_http_patch', 'rack-mini-profiler']

If you currently have require: false, remove the 'rack-mini-profiler' string from the require array above so the gem line becomes like this:

gem 'rack-mini-profiler', require: ['prepend_net_http_patch']

This conflict happens when a ruby method is patched twice, once using module prepend, and once using method aliasing. See this ruby issue for details. The fix is to apply all patches the same way. Mini Profiler by default will apply its patch using method aliasing, but you can change that to module prepend by adding require: ['prepend_net_http_patch'] to the gem line as shown above.

peek-mysql2 stack level too deep errors

If you use peek-mysql2 with Rails >= 5, you'll need to use this gem spec in your Gemfile:

gem 'rack-mini-profiler', require: ['prepend_mysql2_patch', 'rack-mini-profiler']

This should not be necessary with Rails < 5 because peek-mysql2 hooks into mysql2 gem in different ways depending on your Rails version.

Rails and manual initialization

In case you need to make sure rack_mini_profiler is initialized after all other gems, or you want to execute some code before rack_mini_profiler required:

gem 'rack-mini-profiler', require: false

Note the require: false part - if omitted, it will cause the Railtie for the mini-profiler to be loaded outright, and an attempt to re-initialize it manually will raise an exception.

Then run the generator which will set up rack-mini-profiler in development:

bundle exec rails g rack_mini_profiler:install

Rack Builder

require 'rack-mini-profiler'

home = lambda { |env|
  [200, {'Content-Type' => 'text/html'}, ["<html><body>hello!</body></html>"]]
}

builder = Rack::Builder.new do
  use Rack::MiniProfiler
  map('/') { run home }
end

run builder

Sinatra

require 'rack-mini-profiler'
class MyApp < Sinatra::Base
  use Rack::MiniProfiler
end

Hanami

For working with hanami, you need to use rack integration. Also, you need to add Hanami::View::Rendering::Partial#render method for profile:

# config.ru
require 'rack-mini-profiler'
Rack::MiniProfiler.profile_method(Hanami::View::Rendering::Partial, :render) { "Render partial #{@options[:partial]}" }

use Rack::MiniProfiler

Patching ActiveRecord

A typical web application spends a lot of time querying the database. rack_mini_profiler will detect the ORM that is available and apply patches to properly collect query statistics.

To make this work, declare the orm's gem before declaring rack-mini-profiler in the Gemfile:

gem 'pg'
gem 'mongoid'
gem 'rack-mini-profiler'

If you wish to override this behavior, the environment variable RACK_MINI_PROFILER_PATCH is available.

export RACK_MINI_PROFILER_PATCH="pg,mongoid"
# or
export RACK_MINI_PROFILER_PATCH="false"
# initializers/rack_profiler.rb: SqlPatches.patch %w(mongo)

Patching Net::HTTP

Other than databases, rack-mini-profiler applies a patch to Net::HTTP. You may want to disable this patch:

export RACK_MINI_PROFILER_PATCH_NET_HTTP="false"

Flamegraphs

To generate flamegraphs, add the stackprof gem to your Gemfile.

Then, to view the flamegraph as a direct HTML response from your request, just visit any page in your app with ?pp=flamegraph appended to the URL, or add the header X-Rack-Mini-Profiler to the request with the value flamegraph.

Conversely, if you want your regular response instead (which is specially useful for JSON and/or XHR requests), just append the ?pp=async-flamegraph parameter to your request/fetch URL; the request will then return as normal, and the flamegraph data will be stored for later async viewing, both for this request and for all subsequent requests made by this page (based on the REFERER header). For viewing these async flamegraphs, use the 'flamegraph' link that will appear inside the MiniProfiler UI for these requests or path returned in the X-MiniProfiler-Flamegraph-Path header.

Note: Mini Profiler will not record SQL timings for a request if it asks for a flamegraph. The rationale behind this is to keep Mini Profiler's methods that are responsible for generating the timings data out of the flamegraph.

Memory Profiling

Memory allocations can be measured (using the memory_profiler gem) which will show allocations broken down by gem, file location, and class and will also highlight String allocations.

Add ?pp=profile-memory to the URL of any request while Rack::MiniProfiler is enabled to generate the report.

Additional query parameters can be used to filter the results.

  • memory_profiler_allow_files - filename pattern to include (default is all files)
  • memory_profiler_ignore_files - filename pattern to exclude (default is no exclusions)
  • memory_profiler_top - number of results per section (defaults to 50)

The allow/ignore patterns will be treated as regular expressions.

Example: ?pp=profile-memory&memory_profiler_allow_files=active_record|app

There are two additional pp options that can be used to analyze memory which do not require the memory_profiler gem

  • Use ?pp=profile-gc to report on Garbage Collection statistics
  • Use ?pp=analyze-memory to report on ObjectSpace statistics

Snapshots Sampling

In a complex web application, it's possible for a request to trigger rare conditions that result in poor performance. Mini Profiler ships with a feature to help detect those rare conditions and fix them. It works by enabling invisible profiling on one request every N requests, and saving the performance metrics that are collected during the request (a.k.a snapshot of the request) so that they can be viewed later. To turn this feature on, set the snapshot_every_n_requests config to a value larger than 0. The larger the value is, the less frequently requests are profiled.

Mini Profiler will exclude requests that are made to skipped paths (see skip_paths config below) from being sampled. Additionally, if profiling is enabled for a request that later finishes with a non-2xx status code, Mini Profiler will discard the snapshot and not save it (this behavior may change in the future).

After enabling snapshots sampling, you can see the snapshots that have been collected at /mini-profiler-resources/snapshots (or if you changed the base_url_path config, substitute mini-profiler-resources with your value of the config). You'll see on that page a table where each row represents a group of snapshots with the duration of the worst snapshot in that group. The worst snapshot in a group is defined as the snapshot whose request took longer than all of the snapshots in the same group. Snapshots grouped by HTTP method and path of the request, and if your application is a Rails app, Mini Profiler will try to convert the path to controller#action and group by that instead of request path. Clicking on a group will display the snapshots of that group sorted from worst to best. From there, you can click on a snapshot's ID to see the snapshot with all the performance metrics that were collected.

Access to the snapshots page is restricted to only those who can see the speed badge on their own requests, see the section below this one about access control.

Mini Profiler will keep a maximum of 50 snapshot groups and a maximum of 15 snapshots per group making the default maximum number of snapshots in the system 750. The default group and per group limits can be changed via the max_snapshot_groups and max_snapshots_per_group configuration options, see the configurations table below.

Snapshots Transporter

Mini Profiler can be configured so that it sends snapshots over HTTP using the snapshots transporter. The main use-case of the transporter is to allow the aggregation of snapshots from multiple applications/sources in a single place. To enable the snapshots transporter, you need to provide a destination URL to the snapshots_transport_destination_url config, and a secure key to the snapshots_transport_auth_key config (will be used for authorization). Both of these configs are required for the transporter to be enabled.

The transporter uses a buffer to temporarily hold snapshots in memory with a limit of 100 snapshots. Every 30 seconds, if the buffer is not empty, the transporter will make a POST request with the buffer content to the destination URL. Requests made by the transporter will have a Mini-Profiler-Transport-Auth header with the value of the snapshots_transport_auth_key config. The destination should only accept requests that include this header AND the header's value matches the key you set to the snapshots_transport_auth_key config.

If the specified destination responds with a non-200 status code, the transporter will increase the interval between requests by 2^n seconds where n is the number of failed requests since the last successful request. The base interval between requests is 30 seconds. So if a request fails, the next request will be 30 + 2^1 = 32 seconds later. If the next request fails too, the next one will be 30 + 2^2 = 34 seconds later and so on until a request succeeds at which point the interval will return to 30 seconds. The interval will not go beyond 1 hour.

Requests made by the transporter can be optionally gzip-compressed by setting the snapshots_transport_gzip_requests config to true. The body of the requests (after decompression, if you opt for compression) is a JSON string with a single top-level key called snapshots and it has an array of snapshots. The structure of a snapshot is too complex to be explained here, but it has the same structure that Mini Profiler client expects. So if your use-case is to simply be able to view snapshots from multiple sources in one place, you should simply store the snapshots as-is, and then serve them to Mini Profiler client to consume. If the destination application also has Mini Profiler, you can simply use the API of the storage backends to store the incoming snapshots and Mini Profiler will treat them the same as local snapshots (e.g. they'll be grouped and displayed in the same manner described in the previous section).

Mini Profiler offers an API to add extra fields (a.k.a custom fields) to snapshots. For example, you may want to add whether the request was made by a logged-in or anonymous user, the version of your application or any other things that are specific to your application. To add custom fields to a snapshot, call the Rack::MiniProfiler.add_snapshot_custom_field(<key>, <value>) method anywhere during the lifetime of a request, and the snapshot of that request will include the fields you added. If you have a Rails app, you can call that method in an after_action callback. Custom fields are cleared between requests.

Access control in non-development environments

rack-mini-profiler is designed with production profiling in mind. To enable that run Rack::MiniProfiler.authorize_request once you know a request is allowed to profile.

  # inside your ApplicationController

  before_action do
    if current_user && current_user.is_admin?
      Rack::MiniProfiler.authorize_request
    end
  end

If your production application is running on more than one server (or more than one dyno) you will need to configure rack mini profiler's storage to use Redis or Memcache. See storage for information on changing the storage backend.

Note:

Out-of-the-box we will initialize the authorization_mode to :allow_authorized in production. However, in some cases we may not be able to do it:

  • If you are running in development or test we will not enable the explicit authorization mode
  • If you use require: false on rack_mini_profiler we are unlikely to be able to run the railtie
  • If you are running outside of rails we will not run the railtie

In those cases use:

Rack::MiniProfiler.config.authorization_mode = :allow_authorized

When deciding to fully profile a page mini profiler consults with the authorization_mode

By default in production we attempt to set the authorization mode to :allow_authorized meaning that end user will only be able to see requests where somewhere Rack::MiniProfiler.authorize_request is invoked.

In development we run in the :allow_all authorization mode meaning every request is profiled and displayed to the end user.

Configuration

Various aspects of rack-mini-profiler's behavior can be configured when your app boots. For example in a Rails app, this should be done in an initializer: config/initializers/mini_profiler.rb

Caching behavior

To fix some nasty bugs with rack-mini-profiler showing the wrong data, the middleware will remove headers relating to caching (Date & Etag on responses, If-Modified-Since & If-None-Match on requests). This probably won't ever break your application, but it can cause some unexpected behavior. For example, in a Rails app, calls to stale? will always return true.

To disable this behavior, use the following config setting:

# Do not let rack-mini-profiler disable caching
Rack::MiniProfiler.config.disable_caching = false # defaults to true

Storage

rack-mini-profiler stores its results so they can be shared later and aren't lost at the end of the request.

There are 4 storage options: MemoryStore, RedisStore, MemcacheStore, and FileStore.

FileStore is the default in Rails environments and will write files to tmp/miniprofiler/*. MemoryStore is the default otherwise.

# set MemoryStore
Rack::MiniProfiler.config.storage = Rack::MiniProfiler::MemoryStore

# set RedisStore
if Rails.env.production?
  Rack::MiniProfiler.config.storage_options = { url: ENV["REDIS_SERVER_URL"] }
  Rack::MiniProfiler.config.storage = Rack::MiniProfiler::RedisStore
end

MemoryStore stores results in a processes heap - something that does not work well in a multi process environment. FileStore stores results in the file system - something that may not work well in a multi machine environment. RedisStore/MemcacheStore work in multi process and multi machine environments (RedisStore only saves results for up to 24 hours so it won't continue to fill up Redis). You will need to add gem redis/gem dalli respectively to your Gemfile to use these stores.

Additionally you may implement an AbstractStore for your own provider.

User result segregation

MiniProfiler will attempt to keep all user results isolated, out-of-the-box the user provider uses the ip address:

Rack::MiniProfiler.config.user_provider = Proc.new{|env| Rack::Request.new(env).ip}

You can override (something that is very important in a multi-machine production setup):

Rack::MiniProfiler.config.user_provider = Proc.new{ |env| CurrentUser.get(env) }

The string this function returns should be unique for each user on the system (for anonymous you may need to fall back to ip address)

Profiling specific methods

You can increase the granularity of profiling by measuring the performance of specific methods. Add methods of interest to an initializer.

Rails.application.config.to_prepare do
  ::Rack::MiniProfiler.profile_singleton_method(User, :non_admins) { |a| "executing all_non_admins" }
  ::Rack::MiniProfiler.profile_method(User, :favorite_post) { |a| "executing favorite_post" }
end

Profiling arbitrary block of code

It is also possible to profile any arbitrary block of code by passing a block to Rack::MiniProfiler.step(name, opts=nil).

Rack::MiniProfiler.step('Adding two elements') do
  result = 1 + 2
end

Using in SPA applications

Single page applications built using Ember, Angular or other frameworks need some special care, as routes often change without a full page load.

On route transition always call:

if (window.MiniProfiler !== undefined) {
  window.MiniProfiler.pageTransition();
}

This method will remove profiling information that was related to previous page and clear aggregate statistics.

MiniProfiler's speed badge on pages that are not generated via Rails

You need to inject the following in your SPA to load MiniProfiler's speed badge (extra details surrounding this script and credit for the script tag to @ivanyv):

 <script type="text/javascript" id="mini-profiler"
        src="/mini-profiler-resources/includes.js?v=12b4b45a3c42e6e15503d7a03810ff33"
        data-css-url="/mini-profiler-resources/includes.css?v=12b4b45a3c42e6e15503d7a03810ff33"
        data-version="12b4b45a3c42e6e15503d7a03810ff33"
        data-path="/mini-profiler-resources/"
        data-horizontal-position="left"
        data-vertical-position="top"
        data-ids=""
        data-trivial="false"
        data-children="false"
        data-max-traces="20"
        data-controls="false"
        data-total-sql-count="false"
        data-authorized="true"
        data-toggle-shortcut="alt+p"
        data-start-hidden="false"
        data-collapse-results="true"
        data-html-container="body"
        data-hidden-custom-fields></script>

See an example of how to do this in a React useEffect.

Note: The GUID (data-version and the ?v= parameter on the src and data-css-url) will change with each release of rack_mini_profiler. The MiniProfiler's speed badge will continue to work, although you will have to change the GUID to expire the script to fetch the most recent version.

Using MiniProfiler's built in route for apps without HTML responses

MiniProfiler also ships with a /rack-mini-profiler/requests route that displays the speed badge on a blank HTML page. This can be useful when profiling an application that does not render HTML.

Register MiniProfiler's assets in the Rails assets pipeline

MiniProfiler can be configured so it registers its assets in the assets pipeline. To do that, you'll need to provide a lambda (or proc) to the assets_url config (see the below section). The callback will receive 3 arguments which are: name represents asset name (currently it's either rack-mini-profiling.js or rack-mini-profiling.css), assets_version is a 32 characters long hash of MiniProfiler's assets, and env which is the env object of the request. MiniProfiler expects the assets_url callback to return a URL from which the asset can be loaded (the return value will be used as a href/src attribute in the DOM). If the assets_url callback is not set (the default) or it returns a non-truthy value, MiniProfiler will fallback to loading assets from its own middleware (/mini-profiler-resources/*). The following callback should work for most applications:

Rack::MiniProfiler.config.assets_url = ->(name, version, env) {
  ActionController::Base.helpers.asset_path(name)
}

Configuration Options

You can set configuration options using the configuration accessor on Rack::MiniProfiler. For example:

Rack::MiniProfiler.config.position = 'bottom-right'
Rack::MiniProfiler.config.start_hidden = true

The available configuration options are:

Option Default Description
pre_authorize_cb Rails: dev only
Rack: always on
A lambda callback that returns true to make mini_profiler visible on a given request.
position 'top-left' Display mini_profiler on 'top-right', 'top-left', 'bottom-right' or 'bottom-left'.
skip_paths [] An array of paths that skip profiling. Both String and Regexp are acceptable in the array.
skip_schema_queries Rails dev: true
Othwerwise: false
true to skip schema queries.
auto_inject true true to inject the miniprofiler script in the page.
backtrace_ignores [] Regexes of lines to be removed from backtraces.
backtrace_includes Rails: [/^\/?(app|config|lib|test)/]
Rack: []
Regexes of lines to keep in backtraces.
backtrace_remove rails: Rails.root
Rack: nil
A string or regex to remove part of each line in the backtrace.
toggle_shortcut Alt+P Keyboard shortcut to toggle the mini_profiler's visibility. See jquery.hotkeys.
start_hidden false false to make mini_profiler visible on page load.
backtrace_threshold_ms 0 Minimum SQL query elapsed time before a backtrace is recorded.
flamegraph_sample_rate 0.5 How often to capture stack traces for flamegraphs in milliseconds.
flamegraph_mode :wall The StackProf mode to pass to StackProf.run.
flamegraph_ignore_gc false Whether to ignore garbage collection frames in flamegraphs.
base_url_path '/mini-profiler-resources/' Path for assets; added as a prefix when naming assets and sought when responding to requests.
cookie_path '/' Set-Cookie header path for profile cookie
collapse_results true If multiple timing results exist in a single page, collapse them till clicked.
max_traces_to_show 20 Maximum number of mini profiler timing blocks to show on one page
html_container body The HTML container (as a jQuery selector) to inject the mini_profiler UI into
show_total_sql_count false Displays the total number of SQL executions.
enable_advanced_debugging_tools false Enables sensitive debugging tools that can be used via the UI. In production we recommend keeping this disabled as memory and environment debugging tools can expose contents of memory that may contain passwords. Defaults to true in development.
assets_url nil See the "Register MiniProfiler's assets in the Rails assets pipeline" section above.
snapshot_every_n_requests -1 Determines how frequently snapshots are taken. See the "Snapshots Sampling" above for more details.
max_snapshot_groups 50 Determines how many snapshot groups Mini Profiler is allowed to keep.
max_snapshots_per_group 15 Determines how many snapshots per group Mini Profiler is allowed to keep.
snapshot_hidden_custom_fields [] Each snapshot custom field will have a dedicated column in the UI by default. Use this config to exclude certain custom fields from having their own columns.
snapshots_transport_destination_url nil Set this config to a valid URL to enable snapshots transporter which will POST snapshots to the given URL. The transporter requires snapshots_transport_auth_key config to be set as well.
snapshots_transport_auth_key nil POST requests made by the snapshots transporter to the destination URL will have a Mini-Profiler-Transport-Auth header with the value of this config. Make sure you use a secure and random key for this config.
snapshots_redact_sql_queries true When this is true, SQL queries will be redacted from sampling snapshots, but the backtrace and duration of each SQL query will be saved with the snapshot to keep debugging performance issues possible.
snapshots_transport_gzip_requests false Make the snapshots transporter gzip the requests it makes to snapshots_transport_destination_url.
content_security_policy_nonce Rails: Current nonce
Rack: nil
Set the content security policy nonce to use when inserting MiniProfiler's script block. Can be set to a static string, or a Proc which receives env and response_headers as arguments and returns the nonce.
enable_hotwire_turbo_drive_support false Enable support for Hotwire TurboDrive page transitions.
profile_parameter 'pp' The query parameter used to interact with this gem.

Using MiniProfiler with Rack::Deflate middleware

If you are using Rack::Deflate with Rails and rack-mini-profiler in its default configuration, Rack::MiniProfiler will be injected (as always) at position 0 in the middleware stack, which means it will run after Rack::Deflate on response processing. To prevent attempting to inject HTML in already compressed response body MiniProfiler will suppress compression by setting identity encoding in Accept-Encoding request header.

Using MiniProfiler with Heroku Redis

If you are using Heroku Redis, you may need to add the following to your config/initializers/mini_profiler.rb, in order to get Mini Profiler to work:

if Rails.env.production?
  Rack::MiniProfiler.config.storage_options = {
    url: ENV["REDIS_URL"],
    ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }
  }
  Rack::MiniProfiler.config.storage = Rack::MiniProfiler::RedisStore
end

The above code snippet is Heroku's officially suggested workaround.

Special query strings

If you include the query string pp=help at the end of your request you will see the various options available. You can use these options to extend or contract the amount of diagnostics rack-mini-profiler gathers.

Development

If you want to contribute to this project, that's great, thank you! You can run the following rake task:

$ BUNDLE_GEMFILE=website/Gemfile bundle install
$ bundle exec rake client_dev

This will start a local Sinatra server at http://localhost:9292 where you'll be able to preview your changes. Refreshing the page should be enough to see any changes you make to files in the lib/html directory.

Make sure to prepend bundle exec before any Rake tasks you run.

Running the Specs

You need Memcached and Redis services running for the specs.

$ bundle exec rake build
$ bundle exec rake spec

Licence

The MIT License (MIT)

Copyright (c) 2013 Sam Saffron

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

rack-mini-profiler's People

Contributors

atotic avatar barmstrong avatar ceritium avatar davidtaylorhq avatar dgynn avatar dyfrgi avatar eileencodes avatar eviltrout avatar felixbuenemann avatar gmcgibbon avatar gregmolnar avatar ianks avatar infertux avatar jamesarosen avatar jethroo avatar jjb avatar kbrock avatar keshavbiswa avatar kevinjalbert avatar nateberkopec avatar nextmat avatar nspring avatar olleolleolle avatar osamasayegh avatar rrooding avatar rtomayko avatar samsaffron avatar schneems avatar semaperepelitsa avatar technicalpickles avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rack-mini-profiler's Issues

Release version for EF 6 on Nuget?

Is it possible you can release the EntityFramework6 project on Nuget?
(I assume this makes it possible to use EF6 with the MiniProfiler).

Rails 3.0 Support

When I update my Rails 3.0.20 app to profiler v0.9.0, I get the following error:

/Users/gamov/.rvm/gems/ruby-1.9.3-p484@ector/gems/railties-3.0.20/lib/rails/railtie/configuration.rb:77:in `method_missing': undefined method `assets' for #<Rails::Application::Configuration:0x007f8e693f0350> (NoMethodError)
Exiting
    from /Users/gamov/.rvm/gems/ruby-1.9.3-p484@ector/gems/rack-mini-profiler-0.9.0/lib/mini_profiler_rails/railtie.rb:17:in `initialize!'
    from /Users/gamov/.rvm/gems/ruby-1.9.3-p484@ector/gems/rack-mini-profiler-0.9.0/lib/mini_profiler_rails/railtie.rb:52:in `block in <class:Railtie>'

looks like 0.9.0 is expecting the asset pipeline but I don't think there is a Rails 3.1 + requirement for v0.9.0, Am I correct?

0.1.31 doesn't have this problem.

I got postgress error - No function matches the given name and argument types....

When using select in sql I got an error

@new_charities = Charity.select(:id, :name, :slug).published.where('created_at >= :since_date', since_date: since_date)

when I remove the select there is no error

@new_charities = Charity.published.where('created_at >= :since_date', since_date: since_date)

here is a stack trace

https://gist.github.com/gudata/da2c5ce57ffd776179c6

I have tried with master and the latest released gem.

Profiler enabled in Rails test environment

#35 introduces a regression so that the profiler is enabled in Rails test environment.

Rack::MiniProfiler::Config initializes a default pre_authorize_cb

@pre_authorize_cb = lambda {|env| true}

So pre_authorize_cb is defined when the code in Rack::MiniProfilerRails is executed. With the ||= operator added in #35, pre_authorize_cb will not be redefined

c.pre_authorize_cb ||= lambda { |env|
  !Rails.env.test?
}

So the profiler is now enabled in test environment by default, which is not the desired behavior.

Hotkeys for showing/hiding profiler not working

When using profiler with jQuery 1.11.1, keyboard shortcut for showing / hiding profiler is not working. Instead, profiler is toggled on every key press.

This is probably due to load order of jquery.hotkeys plugin - it is loaded AFTER the 'keydown' event binding for shortcuts is set.

mini-profiler removes cache-control header

The cache-control headers without mini-profiler:

HTTP/1.1 200 OK
Date: Fri, 07 Mar 2014 12:48:37 GMT
Content-Type: image/jpeg
Status: 200 OK
Content-Length: 340038
Content-Disposition: filename="14tdysnuvo.jpg"
Cache-Control: public, max-age=31536000
ETag: "39f18a9d2ab41214aa62c3fe28efcd7d44e92ea9"
X-Request-Id: dce5d9cd-cfbb-4362-a42f-a7b62ded6574
X-Runtime: 0.100084

and with mini-profiler enabled:

HTTP/1.1 200 OK
Date: Fri, 07 Mar 2014 12:33:58 GMT
Status: 200 OK
Content-Type: image/jpeg
Content-Length: 340038
Content-Disposition: filename="14tdysnuvo.jpg"
Cache-Control: must-revalidate, private, max-age=0
X-Request-Id: 97c0797a-71cb-429a-800e-963bcf93f50d
X-Runtime: 0.104847
Set-Cookie: __profilin=p%3Dt; path=/
Set-Cookie: __profilin=p%3Dt; path=/
Set-Cookie: __profilin=p%3Dt; path=/
X-MiniProfiler-Ids: ["mryxzb2q56i903vzo703","g7x7vc8680669mha5h0q","bpe4damr7lhmz98m76s9","rxi35n4b1ucuszoil3g5","96f75o5579wx53nhjwqv","5obvbow2o2cdbplrfhud","rnr6i46hnelap0abdtx9","wsrkubaekehj9gk1ndxo","dc2l6imvfwvzl7ta66pw","2wuoraq2z97ox8rfkdsa"]

can ayone explain the reason why mini-profiler removes the e-tag and cache-control headers and how to disable this behavior?
I have an test-environment and want both, the miniprofiler and a working cache in front of the app.

broken interactions with bullet, appsignal gems, possibly puma

I'm having problems with this gem in combination with bullet gem. If I comment out Bullet.enable then profiler starts showing up.
I am loading rack-mini-profiler manually in a Rails initializer (with require: false in Gemfile).

I noticed it seems to hang on mutex lock in the middleware, because if I press ctrl-c while profiler is "stuck" loading the results, I get the backtrace shown at the end of this post.

Also a similar thing seems to be happening with appsignal gem.

I am using puma so this may be related to #70

^CExiting
2014-10-16 15:30:35 +0200: Rack app error: #<ThreadError: Attempt to unlock a mutex which is not locked>2014-10-16 15:30:35 +0200: Rack app error: #<ThreadError: Attempt to unlock a mutex which is not locked>
/path/gems/rack-1.5.2/lib/rack/lock.rb:22:in `unlock'
/path/gems/rack-1.5.2/lib/rack/lock.rb:22:in `ensure in call'
/path/gems/rack-1.5.2/lib/rack/lock.rb:23:in `call'
/path/gems/actionpack-4.1.6/lib/action_dispatch/middleware/static.rb:64:in `call'
/path/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
/Users/me/.rvm/gems/r
2014-10-16 15:30:35 +0200: Rack app error: #<ThreadError: Attempt to unlock a mutex which is not locked>
/path/gems/rack-1.5.2/lib/rack/lock.rb:22:in `unlock'
/path/gems/rack-1.5.2/lib/rack/lock.rb:22:in `ensure in call'
/path/gems/rack-1.5.2/lib/rack/lock.rb:23:in `call'
/path/gems/actionpack-4.1.6/lib/action_dispatch/middleware/static.rb:64:in `call'
/path/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
/path/gems/rack-mini-profiler-0.9.2/lib/mini_profiler/profiler.rb:193:in `call'
/path/gems/railties-4.1.6/lib/rails/engine.rb:514:in `call'
/path/gems/railties-4.1.6/lib/rails/application.rb:144:in `call'
/path/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
/path/gems/puma-2.9.1/lib/puma/server.rb:490:in `handle_request'
/Users/me/.rvm/gems/r/path/gems/rack-1.5.2/lib/rack/lock.rb:22:in `unlock'
/path/gems/rack-1.5.2/lib/rack/lock.rb:22:in `ensure in call'
/path/gems/rack-1.5.2/lib/rack/lock.rb:23:in `call'
/path/gems/actionpack-4.1.6/lib/action_dispatch/middleware/static.rb:64:in `call'
/path/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
/path/gems/rack-mini-profiler-0.9.2/lib/mini_profiler/profiler.rb:193:in `call'
/path/gems/railties-4.1.6/lib/rails/engine.rb:514:in `call'
/path/gems/railties-4.1.6/lib/rails/application.rb:144:in `call'
/path/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
/path/gems/puma-2.9.1/lib/puma/server.rb:490:in `handle_request'
/Users/me/.rvm/gems/r2014-10-16 15:30:35 +0200: Rack app error: #<ThreadError: Attempt to unlock a mutex which is not locked>
/path/gems/rack-1.5.2/lib/rack/lock.rb:22:in `unlock'
/path/gems/rack-1.5.2/lib/rack/lock.rb:22:in `ensure in call'
/path/gems/rack-1.5.2/lib/rack/lock.rb:23:in `call'
/path/gems/actionpack-4.1.6/lib/action_dispatch/middleware/static.rb:64:in `call'
/path/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
/path/gems/rack-mini-profiler-0.9.2/lib/mini_profiler/profiler.rb:193:in `call'
/path/gems/railties-4.1.6/lib/rails/engine.rb:514:in `call'
/path/gems/railties-4.1.6/lib/rails/application.rb:144:in `call'
/path/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
/path/gems/puma-2.9.1/lib/puma/server.rb:490:in `handle_request'
/Users/me/.rvm/gems/r2014-10-16 15:30:35 +0200: Rack app error: #<ThreadError: Attempt to unlock a mutex which is not locked>
/path/gems/rack-1.5.2/lib/rack/lock.rb:22:in `unlock'
/path/gems/rack-1.5.2/lib/rack/lock.rb:22:in `ensure in call'
/path/gems/rack-1.5.2/lib/rack/lock.rb:23:in `call'
/path/gems/actionpack-4.1.6/lib/action_dispatch/middleware/static.rb:64:in `call'
/path/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
/path/gems/rack-mini-profiler-0.9.2/lib/mini_profiler/profiler.rb:193:in `call'
/path/gems/railties-4.1.6/lib/rails/engine.rb:514:in `call'
/path/gems/railties-4.1.6/lib/rails/application.rb:144:in `call'
/path/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
/path/gems/puma-2.9.1/lib/puma/server.rb:490:in `handle_request'
/path/gems/rack-mini-profiler-0.9.2/lib/mini_profiler/profiler.rb:193:in `call'
/path/gems/railties-4.1.6/lib/rails/engine.rb:514:in `call'
/path/gems/railties-4.1.6/lib/rails/application.rb:144:in `call'
/path/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
/path/gems/puma-2.9.1/lib/puma/server.rb:490:in `handle_request'
/path/gems/puma-2.9.1/lib/puma/server.rb:361:in `process_client'
/path/gems/puma-2.9.1/lib/puma/server.rb:254:in `block in run'
/path/gems/puma-2.9.1/lib/puma/thread_pool.rb:92:in `call'
/path/gems/puma-2.9.1/lib/puma/thread_pool.rb:92:in `block in spawn_thread'
uby-2.1.2@project/gems/puma-2.9.1/lib/puma/server.rb:361:in `process_client'
/path/gems/puma-2.9.1/lib/puma/server.rb:254:in `block in run'
/path/gems/puma-2.9.1/lib/puma/thread_pool.rb:92:in `call'
/path/gems/puma-2.9.1/lib/puma/thread_pool.rb:92:in `block in spawn_thread'uby-2.1.project/gems/puma-2.9.1/lib/puma/server.rb:361:in `process_client'
/path/gems/puma-2.9.1/lib/puma/server.rb:254:in `block in run'
/path/gems/puma-2.9.1/lib/puma/thread_pool.rb:92:in `call'
/path/gems/puma-2.9.1/lib/puma/thread_pool.rb:92:in `block in spawn_thread'

uby-2.1.2@project/gems/puma-2.9.1/lib/puma/server.rb:361:in `process_client'
/path/gems/puma-2.9.1/lib/puma/server.rb:254:in `block in run'
/path/gems/puma-2.9.1/lib/puma/thread_pool.rb:92:in `call'
/path/gems/puma-2.9.1/lib/puma/thread_pool.rb:92:in `block in spawn_thread'
uby-2.1.2@project/gems/puma-2.9.1/lib/puma/server.rb:361:in `process_client'
/path/gems/puma-2.9.1/lib/puma/server.rb:254:in `block in run'
/path/gems/puma-2.9.1/lib/puma/thread_pool.rb:92:in `call'
/path/gems/puma-2.9.1/lib/puma/thread_pool.rb:92:in `block in spawn_thread'

Give an option to precompile includes.css

Hi,

In our production environment, the following file returns a 404: /mini-profiler-resources/includes.css

The reason to this is that all our static resources (css, js, images...) are managed by a content delivery server that catches the requests based on the extension of the file and fetches the file directly on disc to optimize the delivery of those.
As includes.css isn't actually in the assets directory, it fails to fetch it.

Would it be possible to give an option to allow this file to be precompiled alongside the other CSS files when using rake assets:precompile ?

Thanks

Raise "can't modify frozen object" with irregular model in Rails 4

Tried both on 0.1.31 and 0.9.0.pre, on Rails 4.0.0.

With an irregular model, like this:

class Basetrx < ActiveRecord::Base
  establish_connection :trx
  self.table_name = 'basetrx'
  self.primary_key = :id

The normal find method

Basetrx.find(t_id)

will raise "can't modify frozen object" error, with the trace:

rack-mini-profiler (0.1.31) Ruby/lib/patches/sql_patches.rb:148:in `instance_variable_set'
rack-mini-profiler (0.1.31) Ruby/lib/patches/sql_patches.rb:148:in `send_query_prepared'
activerecord (4.0.0) lib/active_record/connection_adapters/postgresql_adapter.rb:776:in `exec_cache'

Disable mini-profiler loading

Hey there,

What I'm trying to do is to disable loading of mini-profiler without touching Gemfile.
Even with "pp=disable" mini-profiler is still being loaded (at least to be able to enable it back).
Is there a setting to disable mini-profiler loading from the start without removing it from Gemfile?

Stripping of caching headers prevents Rails stale?/ fresh_when method from working correctly

Hi,

as all caching headers (HTTP_IF_MODIFIED_SINCE and HTTP_IF_NONE_MATCH) are stripped away in

env['HTTP_IF_MODIFIED_SINCE'] = ''
the internal Rails caching mechanism stops to work as intended.

Basically the stale? (http://apidock.com/rails/ActionController/Base/stale%3F) method will always return true. The result is the kind of odd behaviour, that the server regenerates the content, but correctly sets the return code to 304.

I wanted to use the mini profiler to check the impact of http caching in my application. I think this is especially an issue if you use the mini profiler also in production environments.

Jan

p.s. this discussion might also be interesting: rtomayko/rack-cache#24

Remove rendering whitespace

When I add the rack mini profiler to my gem file it adds this

<script async="" type="text/javascript" id="mini-profiler" src="/mini-profiler-resources/includes.js?v=8ceae04dd2abbc08ffe85a258d408292" data-version="8ceae04dd2abbc08ffe85a258d408292" data-path="/mini-profiler-resources/" data-current-id="9nlli8mq1mzulvt6qvvx" data-ids="9nlli8mq1mzulvt6qvvx,9nlli8mq1mzulvt6qvvx" data-position="left" data-trivial="false" data-children="false" data-max-traces="10" data-controls="false" data-authorized="true" data-toggle-shortcut="Alt+P" data-start-hidden="false"></script>

that whitespace at the top has been rendering a blank space at the bottom of my layout since I installed it and its been driving me nuts.

mini-profiler does not works with a scope

I have an application with scope, in routes, for locales, like this :

Lescollectionneurs::Application.routes.draw do
  scope "(:locale)", locale: /en|fr/ do
    #...
  end
end

When miniprofile do a http request, it will send at this address /fr/mini-profiler-resources but it does not works because it does not like the scope. Is there a solution?

Thanks!

Minimize option

I'm not sure If I just did not have found out how to do it or if it is not possible currently: Is there a way to minimize the miniprofiler so that the box is not visible anymore but can be maximazied at some pint. It often would be helpful when checkhing some CSS stuff and so on,

thanks!

counter broken in recent versions?

I can't seem to get counters to work. Rack::MiniProfiler.counter("foo") {โ€ฆ} does not raise an error, but I see no results in the profiler output.

MiniProfiler not Working on Rails 2.3.18

Hey there, I would like to that for this opensource project. I've tried miniprofiler on Rails 4 , it worked fine.

But i tried the same on Rails 2.3.18 including your patch on environment.rb, but.... it did'nt work. Need help on this, It would be great if i get this working on Rails 2.3.18. Thanks.

Rails unresponsive when profiling an asset

My main (S)CSS file started taking up 30s to compile in development on every change, so I thought I'd try the gem.

When I called the firegraph on my application.css, the application goes completely moot. It does not finish the request, just leaves the request hanging. Only a SIGKILL will end the zombie.

Note it does not happen when (a) Sass hasn't changed, or (b) no firegraph is asked for.

Suggestions?

ERROR SystemStackError: stack level too deep in active_support_encoder.rb:17

When I add,

gem 'rack-mini-profiler', require: false

in my Gemfile and

if Rails.env == 'development'
  require 'rack-mini-profiler'

  # initialization is skipped so trigger it
  Rack::MiniProfilerRails.initialize!(Rails.application)
end

in my initializer, I get the following trace at the end of my Rails log for all requests and I do not see the Mini Profiler. App works fine though.

[2014-12-01 20:28:23] ERROR SystemStackError: stack level too deep
    /Users/leninraj/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/set.rb:81
[2014-12-01 20:28:23] ERROR SystemStackError: stack level too deep
    /Users/leninraj/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/set.rb:81
[2014-12-01 20:28:23] ERROR SystemStackError: stack level too deep
    /Users/leninraj/.rvm/gems/ruby-2.1.2/bundler/gems/activesupport-json_encoder-072ab26faeaa/lib/active_support/json/encoding/active_support_encoder.rb:17

When I remove the gem and the initializer, I do not see this error in the trace. This is the code around active_support_encoder.rb:17

def initialize(options = nil)
  @options = options || {}
  @seen = Set.new
end

Here is my Gemfile:

source 'https://rubygems.org'

ruby '2.1.2'

gem 'rails', '4.1.4'
gem 'pg'
gem 'haml'
gem 'haml-rails', '~> 0.5.3'
gem 'paperclip', '4.2.0'
gem 'font-awesome-rails'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jquery-turbolinks'
gem 'jquery-ui-rails'
gem 'jbuilder', '~> 1.2'
gem 'devise'
gem 'simple_form'
gem 'merit', '~> 2.0'
gem 'icalendar'
gem 'kaminari'
gem 'rails-api'
gem 'piwik_analytics', '~> 1.0'
gem 'redis', '~> 3.0'
gem 'whenever'
gem 'omniauth'
gem 'slim-rails'
gem 'meta-tags'
gem 'tinymce-rails'
gem 'select2-rails'
gem 'js-routes'
gem 'pundit'
gem 'parsley-rails'
gem 'parsley_simple_form'
gem 'httpclient'
gem 'psych', '2.0.5'
gem 'twitter'
gem 'backbone-on-rails'
gem 'require_all'
gem 'activeadmin', github: 'activeadmin'
gem 'active_model_serializers', '~> 0.9.0'
gem 'activesupport-json_encoder', github: 'chancancode/activesupport-json_encoder'
gem 'sitemap_generator'
gem 'sass'
gem 'compass-rails' # should be in general group, not in assets
gem 'httparty'
gem 'capistrano'
gem 'capistrano-safe-deploy-to'
gem 'capistrano-unicorn-nginx'
# gem 'rack-mini-profiler', require: false
gem 'oj'
gem 'oj_mimic_json'

group :doc do
  gem 'sdoc', require: false
end

group :development do
  gem 'bullet'
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'rspec-rails'
  gem 'meta_request'
end

group :test do
  gem 'database_cleaner'
  gem 'capybara', '~> 2.2.0'
  gem 'selenium-webdriver'
  gem 'cucumber-rails', require: false
  gem 'capybara-select2'
  gem 'pickle'
  gem 'timecop'
  gem 'capypage', :path => 'vendor/gems/capypage-0.2.6'
end

group :development, :test do
  gem 'factory_girl_rails', '~> 4.0'
  gem 'pry'
end

group :assets do
  gem 'coffee-rails', '~> 4.0.0'
  gem 'uglifier', '>= 1.3.0'
end

What could be the issue? How do I get mini profiler to work?

Invalid column name 'CreatedOn'

Why do I keep getting this error msg:

An exception of type 'System.Data.SqlClient.SqlException' occurred in MiniProfiler.dll but was not handled in user code
Additional information: Invalid column name 'CreatedOn'.

I'm using Entity Framework version 6 and miniprofiler.ef6 3.0.10-beta5.

View rendering in flamegraphs?

Great project - keep up the good work ๐Ÿ‘

I tried out the flamegraph option on my Rails project, but apparently it did not show any view related informations? Just the controller stuff as well as Rails stuff.

Anybody else experiencing this?

Or maybe I'm misunderstanding what to look for stack trace wise :-)

railtie raises a frozen Array error on Rails 4.0.1

I tried the master branch using ruby 2.0.0p247 and Rails 4.0.1 and I get this error when I try to boot rails s:

=> Booting Puma
=> Rails 4.0.1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/middleware/stack.rb:90:in `insert': can't modify frozen Array (RuntimeError)
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/middleware/stack.rb:90:in `insert'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/rack-mini-profiler-829ab6e2dd3c/lib/mini_profiler_rails/railtie.rb:61:in `block in <class:Railtie>'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/lazy_load_hooks.rb:36:in `call'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/lazy_load_hooks.rb:44:in `each'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.1/lib/rails/application/finisher.rb:62:in `block in <module:Finisher>'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:30:in `instance_exec'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:30:in `run'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:54:in `run_initializers'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.1/lib/rails/application.rb:215:in `initialize!'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /vagrant/rails401/config/environment.rb:5:in `<top (required)>'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in `require'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in `block in require'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:214:in `load_dependency'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in `require'
    from /vagrant/rails401/config.ru:3:in `block in <main>'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
    from /vagrant/rails401/config.ru:in `new'
    from /vagrant/rails401/config.ru:in `<main>'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.1/lib/rails/commands/server.rb:48:in `app'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.1/lib/rails/commands/server.rb:75:in `start'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.1/lib/rails/commands.rb:76:in `block in <top (required)>'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.1/lib/rails/commands.rb:71:in `tap'
    from /root/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.1/lib/rails/commands.rb:71:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

If I revert the railtie to this version, it works:
https://github.com/MiniProfiler/rack-mini-profiler/blob/3a90c93d98f916d232a0516a4adbf11f4d15e7b0/lib/mini_profiler_rails/railtie.rb

Memory leak on JRuby

(This is being copied over from SamSaffron/MiniProfiler#101 so it doesn't get lost.)

JRuby application servers that can do hot redeploys will shut down the old JRuby runtime without exiting the process. In a few places, rack-mini-profiler creates threads that won't shut down until the process dies. Each of these threads will cause a stopped JRuby runtime to sit around in memory much longer than necessary (they appear to be weakrefs and as such, should eventually be GC'd).

Rack::MiniProfiler::FileStore
Rack::MiniProfiler::MemoryStore

are definitely problematic.

Rack::MiniProfiler may be problematic. This one create a thread that can be exited under certain circumstances. I'd have to trace through to see when that happens.

The simple fix is to flag the thread in an at_exit handler. I did this for another project:

https://github.com/wr0ngway/lumber/blob/a35520abace41a87b455b15398be630e7ef5b2da/lib/lumber/level_util.rb#L83

If you're open to a similar solution I can pull together a pull request.

even with whitelist there is a DoS attack vector

It's trivial for somebody to craft a cookie so that client_settings.has_cookie? will return true. While this won't allow them to view the profiling information without MiniProfiler.request_authorized? also being true, it'll still cause rack-mini-profiler to gather the profiling information, which could be utilized to increase the severity of a DoS attack, especially with gc profiling.

One quick fix would be to only allow pp=enable to take effect if MiniProfiler.request_authorized? , so I could push a pull request for that, but it doesn't solve the issue for people who don't use config.enabled = false.

undefined config options

  1. enabled:
Rack::MiniProfiler.config.enabled = false
undefined method `enabled=' for #<Rack::MiniProfiler::Config:0x007fcb67c63a10> (NoMethodError)
  1. flamegraph_sample_rate
Rack::MiniProfiler.config.flamegraph_sample_rate = 1
undefined method `flamegraph_sample_rate=' for #<Rack::MiniProfiler::Config:0x007fe50826b9f8> (NoMethodError)

I'm on version rack-mini-profiler (0.1.28)

middleware can't come before rack::deflater

I use Rack::Deflater by inserting in in application.rb like so:

config.middleware.insert_after ActionDispatch::Static, Rack::Deflater

then, after i do that, rack-mini-profiler inserts itself at position 0. so the first 2 middleware are:

use Rack::MiniProfiler
use Rack::Deflater

this can't work because rack-mini-profiler will try to inject html into a body that has already been compressed with gzip.

this is done here: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/lib/mini_profiler_rails/railtie.rb#L42

a solution would be to simply make this configurable.

this issue was discussed in #27, although i don't quite understand which orderings were and were not working for @eileencodes -- i think she is describing the same thing i am, however I don't understand how the problem was solved in the end, since as far as i can tell it's impossible rack-mini-profiler to come before deflater.

i'm also surprised that not more people are complaining about this, since rack::deflater is quite popular. so, maybe i'm misunderstanding my own problem?

Does not work on pages handled by a mounted engine

For pages handled by a mounted engine, the inserted script element looks like this

<script async="" type="text/javascript" id="mini-profiler" src="/foo-engine/mini-profiler-resources/includes.js?v=..." ...></script>

Note the source attribute, it is prefixed by "/foo-engine" (the mythical example engine). Unfortunately, rmp does not provide its script at that locating. The script is supposed to be at /mini-profiler-resources/includes.js.

As far as I can tell, the reason for the wrong path is that Rails sets env['SCRIPT_NAME'] to point at the engine's mount point. That parameter in turn is used by rmp to set up its script path.

A very hackish woraround I'm currently using is this change in Rack::MiniProfiler#call

  #return serve_html(env) if path.start_with? @config.base_url_path
  return serve_html(env) if path.include? @config.base_url_path

rack mini profiler not compatible to ruby 1.8.x

I try install rack-mini-profiler in ruby 1.8 version but it's not compatible.

I think it can be useful to add this information in gemspec and in the readme. Maybe the rails 2.3 information can be delete to because rails 2.3 not compatible to ruby 1.9

Mini Profiler doesn't show after renaming Asset Pipeline prefix

In my Rails 4 app I have renamed the path that Asset Pipeline uses to be /resources instead of the default /assets.

I used the following config setting in my config/application.rb file:

# Rename where the asset pipeline serves up assets
config.assets.prefix = "/resources"

Whenever I visit /assets I get my scaffolded Index view, WITH the MiniProfiler displayed. But if I visit /assets/12 I get my Show view but no MiniProfiler displayed.

All other controller Show views display the MiniProfiler correctly. Could this be a bug where MiniProfiler trips up when the Asset Pipeline prefix has been changed from the default?

MiniProfiler with cached pages, encoding issue

!! Unexpected error while processing request: incompatible character encodings: ASCII-8BIT and UTF-8

When using full page caching. After the page is written to disk with mini-profiler information, on the first attempt to read it back this error occurs. It does not happen if mini-profiler is disabled.

JSON numbers exported as string

Hi,

Due to some rounding problems on Ruby calculations using floats, we had to monkey patch the Float class to automatically convert 'itself' to a BigDecimal.

I tried using rack-mini-profiler, but kept getting a JavaScript error when formatting the duration.
The problem is that when the duration is a BigDecimal (as is our case), when converting to JSON it is exported as string, and not as number, and as such, the line 905 of includes.js raises an error because String doesn't have the toFixed function.

A fix to this, which appears to be innocuous, is simply changing:

formatDuration: function (duration) {
    return (duration || 0).toFixed(1);
}

to

formatDuration: function (duration) {
    return Number(duration || 0).toFixed(1);
}

To ensure that the duration is always numeric before calling toFixed.
Do you think it's possible to include this fix?

"can't modify frozen object" when switching from Passenger 3 to Passenger 4 (all other dependencies unchanged)

Environment:
Debian 6
Ruby 1.9.3p194
Rails 3.2.13
Phusion Passenger 3, 4
MySQL 5.1
rack-mini-profiler 0.9.0

We just upgraded from Passenger 3 Community Edition to Passenger 4 Enterprise Edition. With no other changes we found our app would error out immediately with a "can't modify frozen object" error in rack-mini-profiler/lib/patches/sql_patches.rb, line 50.

Changing the line from:

result.instance_variable_set("@miniprofiler_sql_id", ::Rack::MiniProfiler.record_sql(args[0], elapsed_time))

to:

result.instance_variable_set("@miniprofiler_sql_id", ::Rack::MiniProfiler.record_sql(args[0], elapsed_time)) unless result.nil?

...completely fixed the problem. I'll submit a pull request.

rack-mini-profiler error with share link

When I click in share link every time I get an error

http://localhost:3000/mini-profiler-resources/results?id=nbrc0vjdn5ewjtyjbgs7

In other rails projects only crash the first get of share page. The next has no error.

[2013-11-08 11:22:23] ERROR NoMethodError: undefined method `page_struct' for nil:NilClass
    /home/davidm/.rvm/gems/ruby-1.9.3-p448@mundocoleccion/gems/rack-mini-profiler-0.1.31/Ruby/lib/mini_profiler/profiler.rb:479:in `ids_comma_separated'
    /home/davidm/.rvm/gems/ruby-1.9.3-p448@mundocoleccion/gems/rack-mini-profiler-0.1.31/Ruby/lib/mini_profiler/profiler.rb:490:in `get_profile_script'
    /home/davidm/.rvm/gems/ruby-1.9.3-p448@mundocoleccion/gems/rack-mini-profiler-0.1.31/Ruby/lib/mini_profiler/profiler.rb:130:in `serve_results'
    /home/davidm/.rvm/gems/ruby-1.9.3-p448@mundocoleccion/gems/rack-mini-profiler-0.1.31/Ruby/lib/mini_profiler/profiler.rb:141:in `serve_html'
    /home/davidm/.rvm/gems/ruby-1.9.3-p448@mundocoleccion/gems/rack-mini-profiler-0.1.31/Ruby/lib/mini_profiler/profiler.rb:197:in `call'
    /home/davidm/.rvm/gems/ruby-1.9.3-p448@mundocoleccion/gems/railties-3.2.11/lib/rails/engine.rb:479:in `call'
    /home/davidm/.rvm/gems/ruby-1.9.3-p448@mundocoleccion/gems/railties-3.2.11/lib/rails/application.rb:223:in `call'
    /home/davidm/.rvm/gems/ruby-1.9.3-p448@mundocoleccion/gems/rack-1.4.5/lib/rack/content_length.rb:14:in `call'
    /home/davidm/.rvm/gems/ruby-1.9.3-p448@mundocoleccion/gems/railties-3.2.11/lib/rails/rack/log_tailer.rb:17:in `call'
    /home/davidm/.rvm/gems/ruby-1.9.3-p448@mundocoleccion/gems/rack-1.4.5/lib/rack/handler/webrick.rb:59:in `service'
    /home/davidm/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
    /home/davidm/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
    /home/davidm/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

Breaks apps which use require.js to load jquery

rack-mini-profiler presumably loads jquery directly for its own use, but if the rest of the app uses require.js to load jquery as an AMD module, the module does not get defined properly. I guess that jquery detects that it is already loaded.

Not sure what a workaround would be, other than cutting out the jquery dependency from rack-mini-profiler, but perhaps it would at least be worthwhile cautioning require.js users.

Unreachable Memcached backend causes app to crash

MiniProfiler causes Rails app to become unresponsive with the message "deadlock; recursive locking" when the storage backend becomes unavailable.

To reproduce:

  • Set up rails app to use miniprofiler with MemcacheStore
  • Start up memcached
  • Start up rails app
  • Visit rails app
  • Stop memcached
  • Visit rails app

This is only a problem for the administrators of the site, to whom the profiler is authorized.

The rails app is still running, and you can work around this by using pp=skip etc.

But the profiler should not cause the app to become unresponse - even if the backend disapears.

Not showing in Rails 4

When I include the gem in my rails app the profiler is not shown. However, the javascript is included and the div is created for the widget, but the final content is empty.

I tried adding Rack::MiniProfiler.authorize_request in a before_filter in my application controller: no dice.

I tried creating an initializer and add require: false in the gem file as described in the README: no profiler.

I am using puma, rails 4.0.1, and ruby ruby 2.0.0p247

Any tips?

FireFox V25.0.1: too much recursion.

On initial load of all pages in our ruby application 4 async calls get sent out to the mini-profiler url, and then I get 4 'too much recursion' errors. And in the meanwhile (3 minutes) my browser hangs, and crashes regularly. If you need more information to replicate the bug, please let me know.

Env:
FF 25.0.1
OSX: 10.7.5
-MacBook Pro 17"

POST to /mini-profiler-resources/results returns 404

Hi,

I am running rack-mini-profiler on Rails 4.0.3 and I'm having issues. All but one POST to /mini-profiler-resources/results returns a 404. I included a screenshot below. Would anyone have an idea what might be causing this?

mini-profiler

maxTracesToShow is not documented

This has caused me a good amount of confusion and grief.

Its value is not documented and also not configurable.

IMO:

  1. it should be configurable
  2. the default value should be mentioned in the readme
  3. the default value should be much higher or unlimited

what is the value in limiting to 10? especially since it isn't sorted by decreasing time.

Stack when I want the detail on sql requests

When I click on "1 sql" to have the details of the request, I get this stack:

/Users/pierrecaserta/.rvm/gems/ruby-1.9.3-p551/gems/rack-mini-profiler-0.9.2/lib/mini_profiler/request_timer_struct.rb:75:in new' /Users/pierrecaserta/.rvm/gems/ruby-1.9.3-p551/gems/rack-mini-profiler-0.9.2/lib/mini_profiler/request_timer_struct.rb:75:inadd_sql'
/Users/pierrecaserta/.rvm/gems/ruby-1.9.3-p551/gems/rack-mini-profiler-0.9.2/lib/mini_profiler/profiling_methods.rb:8:in record_sql' /Users/pierrecaserta/.rvm/gems/ruby-1.9.3-p551/gems/rack-mini-profiler-0.9.2/lib/patches/sql_patches.rb:50:inquery'
/Users/pierrecaserta/.rvm/gems/ruby-1.9.3-p551/gems/activerecord-3.2.21/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in block in execute' /Users/pierrecaserta/.rvm/gems/ruby-1.9.3-p551/gems/activerecord-3.2.21/lib/active_record/connection_adapters/abstract_adapter.rb:280:inblock in log'
/Users/pierrecaserta/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-3.2.21/lib/active_support/notifications/instrumenter.rb:20:in instrument' /Users/pierrecaserta/.rvm/gems/ruby-1.9.3-p551/gems/activerecord-3.2.21/lib/active_record/connection_adapters/abstract_adapter.rb:275:inlog'

Gems order in Gemfile

I have next Gemfile

gem 'rails'
gem 'pg', group: 'postgres'
gem 'mysql', group: 'mysql'
gem 'rack-mini-profiler', group: 'development'

SQL info is always empty. I read a note about gem order.
Looks like bundler load postgres group after development

I cant move pg gem out of group.
Is there any possible hack/solution how I can make sql profiling works?

Thanks!

rack-mini-profiler causing app to freeze after one request

Just built a new Fedora 19 system.

Rails 4.0.1rc2, Ruby 2.0p247

The very first request to my app (in development mode) works fine, all others fail, the rails process is deadlocked in a Futex. If I disable the rack-mini-profiler gem this doesn't happen.

Edit: Just tried with Rails 4.0.0, same behavior.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.