speed_gun 1.0.0.rc1 → 2.0.0.pre.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +9 -18
  3. data/.rspec +1 -1
  4. data/.rubocop.yml +61 -1
  5. data/.travis.yml +3 -4
  6. data/LICENSE.txt +17 -18
  7. data/README.md +19 -137
  8. data/Rakefile +9 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/example/rails/.gitignore +18 -0
  12. data/example/rails/Gemfile +20 -0
  13. data/example/rails/Gemfile.lock +184 -0
  14. data/example/rails/README.rdoc +28 -0
  15. data/example/rails/Rakefile +6 -0
  16. data/example/rails/app/assets/images/.keep +0 -0
  17. data/example/rails/app/assets/javascripts/application.js +15 -0
  18. data/example/rails/app/assets/javascripts/posts.coffee +3 -0
  19. data/example/rails/app/assets/stylesheets/application.css +15 -0
  20. data/example/rails/app/assets/stylesheets/posts.scss +3 -0
  21. data/example/rails/app/assets/stylesheets/scaffolds.scss +73 -0
  22. data/example/rails/app/controllers/application_controller.rb +5 -0
  23. data/example/rails/app/controllers/concerns/.keep +0 -0
  24. data/example/rails/app/controllers/posts_controller.rb +74 -0
  25. data/example/rails/app/helpers/application_helper.rb +2 -0
  26. data/example/rails/app/helpers/posts_helper.rb +2 -0
  27. data/example/rails/app/mailers/.keep +0 -0
  28. data/example/rails/app/models/.keep +0 -0
  29. data/example/rails/app/models/concerns/.keep +0 -0
  30. data/example/rails/app/models/post.rb +2 -0
  31. data/example/rails/app/views/layouts/application.html.erb +14 -0
  32. data/example/rails/app/views/posts/_form.html.erb +25 -0
  33. data/example/rails/app/views/posts/edit.html.erb +6 -0
  34. data/example/rails/app/views/posts/index.html.erb +29 -0
  35. data/example/rails/app/views/posts/index.json.jbuilder +4 -0
  36. data/example/rails/app/views/posts/new.html.erb +5 -0
  37. data/example/rails/app/views/posts/show.html.erb +14 -0
  38. data/example/rails/app/views/posts/show.json.jbuilder +1 -0
  39. data/example/rails/bin/bundle +3 -0
  40. data/example/rails/bin/rails +9 -0
  41. data/example/rails/bin/rake +9 -0
  42. data/example/rails/bin/setup +29 -0
  43. data/example/rails/bin/spring +15 -0
  44. data/example/rails/config/application.rb +26 -0
  45. data/example/rails/config/boot.rb +3 -0
  46. data/example/rails/config/database.yml +25 -0
  47. data/example/rails/config/environment.rb +5 -0
  48. data/example/rails/config/environments/development.rb +41 -0
  49. data/example/rails/config/environments/production.rb +79 -0
  50. data/example/rails/config/environments/test.rb +42 -0
  51. data/example/rails/config/initializers/assets.rb +11 -0
  52. data/example/rails/config/initializers/backtrace_silencers.rb +7 -0
  53. data/example/rails/config/initializers/cookies_serializer.rb +3 -0
  54. data/example/rails/config/initializers/filter_parameter_logging.rb +4 -0
  55. data/example/rails/config/initializers/inflections.rb +16 -0
  56. data/example/rails/config/initializers/mime_types.rb +4 -0
  57. data/example/rails/config/initializers/session_store.rb +3 -0
  58. data/example/rails/config/initializers/wrap_parameters.rb +14 -0
  59. data/example/rails/config/locales/en.yml +23 -0
  60. data/example/rails/config/routes.rb +57 -0
  61. data/example/rails/config/secrets.yml +22 -0
  62. data/example/rails/config.ru +4 -0
  63. data/example/rails/db/migrate/20160619175824_create_posts.rb +10 -0
  64. data/example/rails/db/schema.rb +23 -0
  65. data/example/rails/db/seeds.rb +7 -0
  66. data/example/rails/lib/assets/.keep +0 -0
  67. data/example/rails/lib/tasks/.keep +0 -0
  68. data/example/rails/log/.keep +0 -0
  69. data/example/rails/public/404.html +67 -0
  70. data/example/rails/public/422.html +67 -0
  71. data/example/rails/public/500.html +66 -0
  72. data/example/rails/public/favicon.ico +0 -0
  73. data/example/rails/public/robots.txt +5 -0
  74. data/example/rails/test/controllers/.keep +0 -0
  75. data/example/rails/test/controllers/posts_controller_test.rb +49 -0
  76. data/example/rails/test/fixtures/.keep +0 -0
  77. data/example/rails/test/fixtures/posts.yml +9 -0
  78. data/example/rails/test/helpers/.keep +0 -0
  79. data/example/rails/test/integration/.keep +0 -0
  80. data/example/rails/test/mailers/.keep +0 -0
  81. data/example/rails/test/models/.keep +0 -0
  82. data/example/rails/test/models/post_test.rb +7 -0
  83. data/example/rails/test/test_helper.rb +10 -0
  84. data/example/rails/vendor/assets/javascripts/.keep +0 -0
  85. data/example/rails/vendor/assets/stylesheets/.keep +0 -0
  86. data/lib/rack/speed_gun.rb +100 -0
  87. data/lib/speed_gun/app/public/report.js +58 -0
  88. data/lib/speed_gun/app/views/events.slim +11 -0
  89. data/lib/speed_gun/app/views/payload.slim +20 -0
  90. data/lib/speed_gun/app/views/report.scss +322 -0
  91. data/lib/speed_gun/app/views/report.slim +57 -0
  92. data/lib/speed_gun/app.rb +53 -0
  93. data/lib/speed_gun/config.rb +25 -32
  94. data/lib/speed_gun/event.rb +29 -39
  95. data/lib/speed_gun/profiler/action_controller_profiler.rb +3 -8
  96. data/lib/speed_gun/profiler/action_mailer_profiler.rb +7 -0
  97. data/lib/speed_gun/profiler/action_view_profiler.rb +3 -8
  98. data/lib/speed_gun/profiler/active_job_profiler.rb +6 -0
  99. data/lib/speed_gun/profiler/active_record_profiler.rb +3 -8
  100. data/lib/speed_gun/profiler/active_support_notifications_profiler.rb +9 -6
  101. data/lib/speed_gun/profiler/active_support_profiler.rb +8 -0
  102. data/lib/speed_gun/profiler/line_profiler.rb +32 -0
  103. data/lib/speed_gun/profiler/rack_profiler.rb +2 -4
  104. data/lib/speed_gun/profiler.rb +15 -9
  105. data/lib/speed_gun/railtie.rb +21 -5
  106. data/lib/speed_gun/report.rb +65 -0
  107. data/lib/speed_gun/source.rb +90 -0
  108. data/lib/speed_gun/store/file_store.rb +35 -0
  109. data/lib/speed_gun/store/memory_store.rb +7 -14
  110. data/lib/speed_gun/store.rb +10 -3
  111. data/lib/speed_gun/version.rb +9 -1
  112. data/lib/speed_gun.rb +21 -26
  113. data/speed_gun.gemspec +21 -16
  114. metadata +168 -58
  115. data/.coveralls.yml +0 -1
  116. data/lib/speed_gun/app/views/meter.html.slim +0 -4
  117. data/lib/speed_gun/middleware.rb +0 -91
  118. data/lib/speed_gun/profile.rb +0 -102
  119. data/lib/speed_gun/store/elastic_search_store.rb +0 -64
  120. data/lib/speed_gun/store/fluent_logger_store.rb +0 -29
  121. data/lib/speed_gun/store/memcache_store.rb +0 -40
  122. data/lib/speed_gun/store/multiple_store.rb +0 -23
  123. data/lib/speed_gun/store/redis_store.rb +0 -41
  124. data/lib/speed_gun/template.rb +0 -15
  125. data/spec/lib/speed_gun/config_spec.rb +0 -37
  126. data/spec/lib/speed_gun/event_spec.rb +0 -70
  127. data/spec/lib/speed_gun/middleware_spec.rb +0 -65
  128. data/spec/lib/speed_gun/profile_spec.rb +0 -41
  129. data/spec/lib/speed_gun_spec.rb +0 -52
  130. data/spec/spec_helper.rb +0 -9
  131. data/spec/support/simplecov.rb +0 -12
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,23 @@
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"
@@ -0,0 +1,57 @@
1
+ Rails.application.routes.draw do
2
+ resources :posts
3
+ # The priority is based upon order of creation: first created -> highest priority.
4
+ # See how all your routes lay out with "rake routes".
5
+
6
+ # You can have the root of your site routed with "root"
7
+ # root 'welcome#index'
8
+
9
+ # Example of regular route:
10
+ # get 'products/:id' => 'catalog#view'
11
+
12
+ # Example of named route that can be invoked with purchase_url(id: product.id)
13
+ # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
14
+
15
+ # Example resource route (maps HTTP verbs to controller actions automatically):
16
+ # resources :products
17
+
18
+ # Example resource route with options:
19
+ # resources :products do
20
+ # member do
21
+ # get 'short'
22
+ # post 'toggle'
23
+ # end
24
+ #
25
+ # collection do
26
+ # get 'sold'
27
+ # end
28
+ # end
29
+
30
+ # Example resource route with sub-resources:
31
+ # resources :products do
32
+ # resources :comments, :sales
33
+ # resource :seller
34
+ # end
35
+
36
+ # Example resource route with more complex sub-resources:
37
+ # resources :products do
38
+ # resources :comments
39
+ # resources :sales do
40
+ # get 'recent', on: :collection
41
+ # end
42
+ # end
43
+
44
+ # Example resource route with concerns:
45
+ # concern :toggleable do
46
+ # post 'toggle'
47
+ # end
48
+ # resources :posts, concerns: :toggleable
49
+ # resources :photos, concerns: :toggleable
50
+
51
+ # Example resource route within a namespace:
52
+ # namespace :admin do
53
+ # # Directs /admin/products/* to Admin::ProductsController
54
+ # # (app/controllers/admin/products_controller.rb)
55
+ # resources :products
56
+ # end
57
+ end
@@ -0,0 +1,22 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rake secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ development:
14
+ secret_key_base: 9a753418d95e93c55cd74b260c169bbd76947e63a51675b33fba1fadf7cbe82c210537dc33084654783d67c2f7449d8c8815cab08ee5eec3e3e62b51f38267ca
15
+
16
+ test:
17
+ secret_key_base: 07d5a9caf2cf08053502dd49c131158a9bcd32d8a03fb37ca5b5cef0b77152006bdc2ec257450a246b27decb9ab393b78f5a402023e1f31375e2637178d8f2fe
18
+
19
+ # Do not keep production secrets in the repository,
20
+ # instead read values from the environment.
21
+ production:
22
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@@ -0,0 +1,4 @@
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
@@ -0,0 +1,10 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :posts do |t|
4
+ t.string :title
5
+ t.text :body
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended that you check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(version: 20160619175824) do
15
+
16
+ create_table "posts", force: :cascade do |t|
17
+ t.string "title"
18
+ t.text "body"
19
+ t.datetime "created_at", null: false
20
+ t.datetime "updated_at", null: false
21
+ end
22
+
23
+ end
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7
+ # Mayor.create(name: 'Emanuel', city: cities.first)
File without changes
File without changes
File without changes
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-agent: *
5
+ # Disallow: /
File without changes
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+
3
+ class PostsControllerTest < ActionController::TestCase
4
+ setup do
5
+ @post = posts(:one)
6
+ end
7
+
8
+ test "should get index" do
9
+ get :index
10
+ assert_response :success
11
+ assert_not_nil assigns(:posts)
12
+ end
13
+
14
+ test "should get new" do
15
+ get :new
16
+ assert_response :success
17
+ end
18
+
19
+ test "should create post" do
20
+ assert_difference('Post.count') do
21
+ post :create, post: { body: @post.body, title: @post.title }
22
+ end
23
+
24
+ assert_redirected_to post_path(assigns(:post))
25
+ end
26
+
27
+ test "should show post" do
28
+ get :show, id: @post
29
+ assert_response :success
30
+ end
31
+
32
+ test "should get edit" do
33
+ get :edit, id: @post
34
+ assert_response :success
35
+ end
36
+
37
+ test "should update post" do
38
+ patch :update, id: @post, post: { body: @post.body, title: @post.title }
39
+ assert_redirected_to post_path(assigns(:post))
40
+ end
41
+
42
+ test "should destroy post" do
43
+ assert_difference('Post.count', -1) do
44
+ delete :destroy, id: @post
45
+ end
46
+
47
+ assert_redirected_to posts_path
48
+ end
49
+ end
File without changes
@@ -0,0 +1,9 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ title: MyString
5
+ body: MyText
6
+
7
+ two:
8
+ title: MyString
9
+ body: MyText
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class PostTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,10 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
7
+ fixtures :all
8
+
9
+ # Add more helper methods to be used by all tests here...
10
+ end
File without changes
File without changes
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+ require 'rack'
3
+ require 'speed_gun'
4
+ require 'speed_gun/app'
5
+ require 'speed_gun/profiler/rack_profiler'
6
+ require 'speed_gun/profiler/line_profiler'
7
+
8
+ class Rack::SpeedGun
9
+ def initialize(app)
10
+ @app = app
11
+
12
+ end
13
+
14
+ def call(env)
15
+ return @app.call(env) if SpeedGun.config.disabled? || skip?(env['PATH_INFO'])
16
+
17
+ return call_speed_gun_app(env) if under_speed_gun?(env)
18
+
19
+ SpeedGun.current_report = SpeedGun::Report.new
20
+
21
+ SpeedGun::Profiler::RackProfiler.profile('rack', rack: rack_info(env), request: request_info(env)) do |event|
22
+ res = SpeedGun::Profiler::LineProfiler.profile { @app.call(env) }
23
+ res[1]['X-Speed-Gun-Report'] = SpeedGun.current_report.id
24
+ event.payload[:response] = {
25
+ status: res[0],
26
+ headers: res[1]
27
+ }
28
+ res
29
+ end
30
+ ensure
31
+ if SpeedGun.current_report
32
+ SpeedGun.config.logger.debug("Speed Gun ID: #{SpeedGun.current_report.id}")
33
+ SpeedGun.config.logger.debug(
34
+ "Check out here: #{base_url(env)}/reports/#{SpeedGun.current_report.id}"
35
+ ) if SpeedGun.config.webapp
36
+ Thread.start(SpeedGun.current_report) do |report|
37
+ SpeedGun.config.store.store(report)
38
+ end
39
+ end
40
+ SpeedGun.current_report = nil
41
+ end
42
+
43
+ private
44
+
45
+ def under_speed_gun?(env)
46
+ SpeedGun.config.webapp && env['PATH_INFO'].match(/\A#{Regexp.escape(SpeedGun.config.prefix)}/)
47
+ end
48
+
49
+ def call_speed_gun_app(env)
50
+ env['PATH_INFO'].sub!(/\A#{Regexp.escape(SpeedGun.config.prefix)}/, '')
51
+
52
+ SpeedGun::App.call(env)
53
+ end
54
+
55
+ def skip?(path_info)
56
+ SpeedGun.config.skip_paths.any? do |path|
57
+ case path
58
+ when String
59
+ path_info.start_with?(path)
60
+ when Regexp
61
+ path_info =~ path
62
+ else
63
+ false
64
+ end
65
+ end
66
+ end
67
+
68
+ def rack_info(env)
69
+ {
70
+ version: env['rack.version'],
71
+ url_scheme: env['rack.url_scheme']
72
+ }
73
+ end
74
+
75
+ def request_info(env)
76
+ {
77
+ method: env['REQUEST_METHOD'],
78
+ path: env['PATH_INFO'],
79
+ headers: request_headers(env),
80
+ query: Rack::Utils.parse_query(env['QUERY_STRING'])
81
+ }
82
+ end
83
+
84
+ def request_headers(env)
85
+ headers = {}
86
+ env.each_pair do |key, val|
87
+ if key.start_with?('HTTP_')
88
+ headers[key[5..-1].split('_').map(&:capitalize).join('-')] = val
89
+ end
90
+ end
91
+ headers
92
+ end
93
+
94
+ def base_url(env)
95
+ scheme = env['rack.url_scheme']
96
+ host = env['HTTP_HOST'] || "#{env['SERVER_NAME'] || env['SERVER_ADDR']}:#{env['SERVER_PORT']}"
97
+
98
+ "#{scheme}://#{host}#{SpeedGun.config.prefix}"
99
+ end
100
+ end
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ jQuery(function($) {
4
+ var reportPage = {
5
+ selectTab: function(id) {
6
+ $('#sources.active, #events.active').removeClass('active');
7
+ $(id).addClass('active');
8
+ },
9
+
10
+ selectLine: function(id) {
11
+ $('#source-code .source').hide();
12
+
13
+ var source = $(id).parents('.source');
14
+ source.show();
15
+
16
+ $('.line-info.focus, .line-code.focus').removeClass('focus');
17
+ var fid = id.slice(6);
18
+ console.log(fid);
19
+ $('#line-' + fid + ', #line-code-' + fid).addClass('focus');
20
+
21
+ reportPage.selectTab('#sources');
22
+ },
23
+
24
+ selectFile: function(id) {
25
+ $('#source-code').scrollTop(0);
26
+ $('#source-code .source').hide()
27
+ $(id).show();
28
+ }
29
+ };
30
+
31
+ $('#report .tabs a').on('click', function(e) {
32
+ e.preventDefault();
33
+
34
+ var href = $(this).attr('href');
35
+ reportPage.selectTab(href);
36
+ });
37
+
38
+ $('#source-list a').on('click', function(e) {
39
+ e.preventDefault();
40
+
41
+ var href = $(this).attr('href');
42
+ reportPage.selectFile(href);
43
+ });
44
+
45
+ $('#events .backtraces a, #sources .source .line-no a').on('click', function(e) {
46
+ e.preventDefault();
47
+
48
+ var href = $(this).attr('href');
49
+ reportPage.selectLine(href);
50
+ });
51
+
52
+ $('#events .event .event-name a').on('click', function(e) {
53
+ e.preventDefault();
54
+
55
+ var id = $(this).attr('href');
56
+ $(id).find('> .event-info .event-payload').slideToggle();
57
+ });
58
+ });
@@ -0,0 +1,11 @@
1
+ - events.each do |event|
2
+ .event(id="event-#{event.id}")
3
+ .event-info
4
+ h3.event-name
5
+ a(href="#event-#{event.id}")
6
+ = event.name
7
+ span.duration-ms= "%06.1fms" % (event.duration * 1000.0)
8
+ .event-payload
9
+ == partial('payload', locals: { name: event.name, payload: event.payload })
10
+ .event-children
11
+ == partial('events', locals: { events: event.children })
@@ -0,0 +1,20 @@
1
+ table.payload
2
+ - payload.each_pair do |key, val|
3
+ tr
4
+ td.payload-key= key
5
+ - case val
6
+ - when Hash
7
+ td.payload-value.table== partial('payload', locals: { name: key, payload: val })
8
+ - when Array
9
+ - if key == 'backtrace'
10
+ td.payload-value
11
+ ul.backtraces
12
+ - val.each do |bt|
13
+ li.backtrace
14
+ a(href="#line-#{line_id(bt[0], bt[1])}")= bt.join(':')
15
+ - else
16
+ td= val.join(', ')
17
+ - when String, Integer
18
+ td= val
19
+ - else
20
+ td= val.inspect