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
metadata CHANGED
@@ -1,23 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: speed_gun
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc1
4
+ version: 2.0.0.pre.alpha.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sho Kusano
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2014-02-17 00:00:00.000000000 Z
11
+ date: 2016-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: msgpack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
- type: :development
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
@@ -25,13 +25,13 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: rack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
- type: :development
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
@@ -39,41 +39,41 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: rblineprof
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 2.14.1
48
- type: :development
47
+ version: '0'
48
+ type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 2.14.1
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: simplecov
56
+ name: sass
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.8.2
62
- type: :development
61
+ version: '0'
62
+ type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 0.8.2
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: simplecov-console
70
+ name: semantic
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
- type: :development
76
+ type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
@@ -81,13 +81,13 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rack-test
84
+ name: sinatra
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
- type: :development
90
+ type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
@@ -95,13 +95,13 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: coveralls
98
+ name: sinatra-partial
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
- type: :development
104
+ type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: hashie
112
+ name: slim
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -123,13 +123,55 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: msgpack
126
+ name: bundler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.12'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.12'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rake
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '11.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '11.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '3.0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '3.0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop
127
169
  requirement: !ruby/object:Gem::Requirement
128
170
  requirements:
129
171
  - - ">="
130
172
  - !ruby/object:Gem::Version
131
173
  version: '0'
132
- type: :runtime
174
+ type: :development
133
175
  prerelease: false
134
176
  version_requirements: !ruby/object:Gem::Requirement
135
177
  requirements:
@@ -137,13 +179,13 @@ dependencies:
137
179
  - !ruby/object:Gem::Version
138
180
  version: '0'
139
181
  - !ruby/object:Gem::Dependency
140
- name: slim
182
+ name: yard
141
183
  requirement: !ruby/object:Gem::Requirement
142
184
  requirements:
143
185
  - - ">="
144
186
  - !ruby/object:Gem::Version
145
187
  version: '0'
146
- type: :runtime
188
+ type: :development
147
189
  prerelease: false
148
190
  version_requirements: !ruby/object:Gem::Requirement
149
191
  requirements:
@@ -152,12 +194,11 @@ dependencies:
152
194
  version: '0'
153
195
  description: Better web app profiler for Rails apps
154
196
  email:
155
- - rosylilly@aduca.org
197
+ - sho-kusano@zeny.io
156
198
  executables: []
157
199
  extensions: []
158
200
  extra_rdoc_files: []
159
201
  files:
160
- - ".coveralls.yml"
161
202
  - ".gitignore"
162
203
  - ".rspec"
163
204
  - ".rubocop.yml"
@@ -166,37 +207,112 @@ files:
166
207
  - LICENSE.txt
167
208
  - README.md
168
209
  - Rakefile
210
+ - bin/console
211
+ - bin/setup
212
+ - example/rails/.gitignore
213
+ - example/rails/Gemfile
214
+ - example/rails/Gemfile.lock
215
+ - example/rails/README.rdoc
216
+ - example/rails/Rakefile
217
+ - example/rails/app/assets/images/.keep
218
+ - example/rails/app/assets/javascripts/application.js
219
+ - example/rails/app/assets/javascripts/posts.coffee
220
+ - example/rails/app/assets/stylesheets/application.css
221
+ - example/rails/app/assets/stylesheets/posts.scss
222
+ - example/rails/app/assets/stylesheets/scaffolds.scss
223
+ - example/rails/app/controllers/application_controller.rb
224
+ - example/rails/app/controllers/concerns/.keep
225
+ - example/rails/app/controllers/posts_controller.rb
226
+ - example/rails/app/helpers/application_helper.rb
227
+ - example/rails/app/helpers/posts_helper.rb
228
+ - example/rails/app/mailers/.keep
229
+ - example/rails/app/models/.keep
230
+ - example/rails/app/models/concerns/.keep
231
+ - example/rails/app/models/post.rb
232
+ - example/rails/app/views/layouts/application.html.erb
233
+ - example/rails/app/views/posts/_form.html.erb
234
+ - example/rails/app/views/posts/edit.html.erb
235
+ - example/rails/app/views/posts/index.html.erb
236
+ - example/rails/app/views/posts/index.json.jbuilder
237
+ - example/rails/app/views/posts/new.html.erb
238
+ - example/rails/app/views/posts/show.html.erb
239
+ - example/rails/app/views/posts/show.json.jbuilder
240
+ - example/rails/bin/bundle
241
+ - example/rails/bin/rails
242
+ - example/rails/bin/rake
243
+ - example/rails/bin/setup
244
+ - example/rails/bin/spring
245
+ - example/rails/config.ru
246
+ - example/rails/config/application.rb
247
+ - example/rails/config/boot.rb
248
+ - example/rails/config/database.yml
249
+ - example/rails/config/environment.rb
250
+ - example/rails/config/environments/development.rb
251
+ - example/rails/config/environments/production.rb
252
+ - example/rails/config/environments/test.rb
253
+ - example/rails/config/initializers/assets.rb
254
+ - example/rails/config/initializers/backtrace_silencers.rb
255
+ - example/rails/config/initializers/cookies_serializer.rb
256
+ - example/rails/config/initializers/filter_parameter_logging.rb
257
+ - example/rails/config/initializers/inflections.rb
258
+ - example/rails/config/initializers/mime_types.rb
259
+ - example/rails/config/initializers/session_store.rb
260
+ - example/rails/config/initializers/wrap_parameters.rb
261
+ - example/rails/config/locales/en.yml
262
+ - example/rails/config/routes.rb
263
+ - example/rails/config/secrets.yml
264
+ - example/rails/db/migrate/20160619175824_create_posts.rb
265
+ - example/rails/db/schema.rb
266
+ - example/rails/db/seeds.rb
267
+ - example/rails/lib/assets/.keep
268
+ - example/rails/lib/tasks/.keep
269
+ - example/rails/log/.keep
270
+ - example/rails/public/404.html
271
+ - example/rails/public/422.html
272
+ - example/rails/public/500.html
273
+ - example/rails/public/favicon.ico
274
+ - example/rails/public/robots.txt
275
+ - example/rails/test/controllers/.keep
276
+ - example/rails/test/controllers/posts_controller_test.rb
277
+ - example/rails/test/fixtures/.keep
278
+ - example/rails/test/fixtures/posts.yml
279
+ - example/rails/test/helpers/.keep
280
+ - example/rails/test/integration/.keep
281
+ - example/rails/test/mailers/.keep
282
+ - example/rails/test/models/.keep
283
+ - example/rails/test/models/post_test.rb
284
+ - example/rails/test/test_helper.rb
285
+ - example/rails/vendor/assets/javascripts/.keep
286
+ - example/rails/vendor/assets/stylesheets/.keep
287
+ - lib/rack/speed_gun.rb
169
288
  - lib/speed_gun.rb
170
- - lib/speed_gun/app/views/meter.html.slim
289
+ - lib/speed_gun/app.rb
290
+ - lib/speed_gun/app/public/report.js
291
+ - lib/speed_gun/app/views/events.slim
292
+ - lib/speed_gun/app/views/payload.slim
293
+ - lib/speed_gun/app/views/report.scss
294
+ - lib/speed_gun/app/views/report.slim
171
295
  - lib/speed_gun/config.rb
172
296
  - lib/speed_gun/event.rb
173
- - lib/speed_gun/middleware.rb
174
- - lib/speed_gun/profile.rb
175
297
  - lib/speed_gun/profiler.rb
176
298
  - lib/speed_gun/profiler/action_controller_profiler.rb
299
+ - lib/speed_gun/profiler/action_mailer_profiler.rb
177
300
  - lib/speed_gun/profiler/action_view_profiler.rb
301
+ - lib/speed_gun/profiler/active_job_profiler.rb
178
302
  - lib/speed_gun/profiler/active_record_profiler.rb
179
303
  - lib/speed_gun/profiler/active_support_notifications_profiler.rb
304
+ - lib/speed_gun/profiler/active_support_profiler.rb
305
+ - lib/speed_gun/profiler/line_profiler.rb
180
306
  - lib/speed_gun/profiler/rack_profiler.rb
181
307
  - lib/speed_gun/railtie.rb
308
+ - lib/speed_gun/report.rb
309
+ - lib/speed_gun/source.rb
182
310
  - lib/speed_gun/store.rb
183
- - lib/speed_gun/store/elastic_search_store.rb
184
- - lib/speed_gun/store/fluent_logger_store.rb
185
- - lib/speed_gun/store/memcache_store.rb
311
+ - lib/speed_gun/store/file_store.rb
186
312
  - lib/speed_gun/store/memory_store.rb
187
- - lib/speed_gun/store/multiple_store.rb
188
- - lib/speed_gun/store/redis_store.rb
189
- - lib/speed_gun/template.rb
190
313
  - lib/speed_gun/version.rb
191
- - spec/lib/speed_gun/config_spec.rb
192
- - spec/lib/speed_gun/event_spec.rb
193
- - spec/lib/speed_gun/middleware_spec.rb
194
- - spec/lib/speed_gun/profile_spec.rb
195
- - spec/lib/speed_gun_spec.rb
196
- - spec/spec_helper.rb
197
- - spec/support/simplecov.rb
198
314
  - speed_gun.gemspec
199
- homepage: https://github.com/rosylilly/speed_gun
315
+ homepage: https://github.com/zeny-io/speed_gun
200
316
  licenses:
201
317
  - MIT
202
318
  metadata: {}
@@ -216,15 +332,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
332
  version: 1.3.1
217
333
  requirements: []
218
334
  rubyforge_project:
219
- rubygems_version: 2.2.0
335
+ rubygems_version: 2.5.1
220
336
  signing_key:
221
337
  specification_version: 4
222
338
  summary: Better web app profiler for Rails apps
223
- test_files:
224
- - spec/lib/speed_gun/config_spec.rb
225
- - spec/lib/speed_gun/event_spec.rb
226
- - spec/lib/speed_gun/middleware_spec.rb
227
- - spec/lib/speed_gun/profile_spec.rb
228
- - spec/lib/speed_gun_spec.rb
229
- - spec/spec_helper.rb
230
- - spec/support/simplecov.rb
339
+ test_files: []
340
+ has_rdoc:
data/.coveralls.yml DELETED
@@ -1 +0,0 @@
1
- service_name: travis-ci
@@ -1,4 +0,0 @@
1
- div.speed-gun(style="position: fixed; bottom: -1px; right: -1px; border: 1px solid #999; border-radius: 3px 0 0 0; background-color: white; font-size: 9px;")
2
- a(href="#" style="display: block; padding: 5px 10px")
3
- = "%0.2f" % (duration * 1000)
4
- | ms
@@ -1,91 +0,0 @@
1
- require 'speed_gun'
2
- require 'speed_gun/template'
3
- require 'speed_gun/profiler/rack_profiler'
4
-
5
- class SpeedGun::Middleware
6
- BODY_END_REGEXP = /<\/(?:body|html)>/i
7
-
8
- # @param app [#call] Rack application
9
- # @return [SpeedGun::Middleware] a instance of SpeedGun::Middleware
10
- def initialize(app)
11
- @app = app
12
- end
13
-
14
- # Handle rack request
15
- #
16
- # @return [Rack::Response]
17
- def call(env)
18
- if with_speed_gun?(env)
19
- call_with_speed_gun(env)
20
- else
21
- call_without_speed_gun(env)
22
- end
23
- end
24
-
25
- private
26
-
27
- def with_speed_gun?(env)
28
- SpeedGun.enabled? && !skip?(env['PATH_INFO'])
29
- end
30
-
31
- def skip?(path)
32
- SpeedGun.config.skip_paths.any? { |regexp| regexp.match(path) }
33
- end
34
-
35
- def call_without_speed_gun(env)
36
- @app.call(env)
37
- end
38
-
39
- def call_with_speed_gun(env)
40
- SpeedGun.current_profile = SpeedGun::Profile.new
41
- SpeedGun.current_profile.request_method = env['REQUEST_METHOD'].to_s.upcase
42
- SpeedGun.current_profile.path = env['PATH_INFO'].to_s
43
- SpeedGun.current_profile.query = env['QUERY_STRING'].to_s
44
-
45
- response = SpeedGun::Profiler::RackProfier.profile do
46
- call_without_speed_gun(env)
47
- end
48
-
49
- SpeedGun.current_profile.status = response[0]
50
-
51
- if SpeedGun.current_profile.active?
52
- inject_header(response[1])
53
- if SpeedGun.current_profile.config.auto_inject?
54
- response = inject_body(*response)
55
- end
56
- end
57
-
58
- response
59
- ensure
60
- if SpeedGun.current_profile.active?
61
- SpeedGun.config.store.save(SpeedGun.current_profile)
62
- end
63
- SpeedGun.discard_profile!
64
- end
65
-
66
- def inject_header(headers)
67
- headers['X-SpeedGun-Profile-Id'] = SpeedGun.current_profile.id
68
- end
69
-
70
- def inject_body(status, headers, body)
71
- unless headers['Content-Type'] =~ /text\/html/
72
- return [status, headers, body]
73
- end
74
-
75
- response = Rack::Response.new([], status, headers)
76
-
77
- body = [body] if body.kind_of?(String)
78
- body.each { |fragment| response.write(inject_fragment(fragment)) }
79
- body.close if body.respond_to?(:close)
80
-
81
- response.finish
82
- end
83
-
84
- def inject_fragment(body)
85
- return body unless body.match(BODY_END_REGEXP)
86
-
87
- body.sub(BODY_END_REGEXP) do |matched|
88
- SpeedGun::Template.render + matched
89
- end
90
- end
91
- end
@@ -1,102 +0,0 @@
1
- require 'securerandom'
2
- require 'speed_gun'
3
- require 'speed_gun/event'
4
-
5
- class SpeedGun::Profile
6
- def self.from_hash(id, hash)
7
- profile = new
8
-
9
- hash['events'].map! do |event_id|
10
- SpeedGun.config.store.load(SpeedGun::Event, event_id)
11
- end
12
-
13
- hash['id'] = id
14
- hash.delete('duration')
15
- hash.each_pair do |key, val|
16
- profile.instance_variable_set(:"@#{key}", val)
17
- end
18
-
19
- profile
20
- end
21
-
22
- # @return [String] profile ID
23
- attr_reader :id
24
-
25
- # @return [Array<SpeedGun::Event>] recorded events
26
- attr_reader :events
27
-
28
- # @return [SpeedGun::Config] the config of the profile
29
- attr_reader :config
30
-
31
- # @return [Integer] status code of the response
32
- attr_accessor :status
33
-
34
- # @return [String] method of the request
35
- attr_accessor :request_method
36
-
37
- # @return [String] path of the request
38
- attr_accessor :path
39
-
40
- # @return [String] query of the request
41
- attr_accessor :query
42
-
43
- # @return [SpeedGun::Profile] instance of SpeedGun::Profile
44
- def initialize(config = SpeedGun.config.dup)
45
- @id = SecureRandom.uuid
46
- @events = []
47
- @config = config
48
- @active = true
49
- end
50
-
51
- # Record an event
52
- #
53
- # @param event [SpeedGun::Event] record event
54
- # @return [Array<SpeedGun::Event>] recorded events
55
- def record!(event)
56
- config.logger.debug(
57
- "[SpeedGun] Record Event: #{event.name}: #{'%0.2f' % (event.duration * 1000)}ms"
58
- ) if config.logger
59
- config.store.save(event) if active?
60
- @events.push(event)
61
- end
62
-
63
- def active?
64
- @active
65
- end
66
-
67
- def deactive?
68
- !active?
69
- end
70
-
71
- def activate!
72
- @active = true
73
- end
74
-
75
- def deactivate!
76
- @active = false
77
- end
78
-
79
- def earliest_started_at
80
- @events.sort_by(&:started_at).first.started_at
81
- end
82
-
83
- def latest_finished_at
84
- @events.sort_by { |event| event.finished_at || 0 }.last.finished_at
85
- end
86
-
87
- def duration
88
- finished_at = latest_finished_at
89
- finished_at ? finished_at - earliest_started_at : 0
90
- end
91
-
92
- def to_hash
93
- {
94
- 'events' => events.map(&:id),
95
- 'status' => status,
96
- 'request_method' => request_method,
97
- 'path' => path,
98
- 'query' => query,
99
- 'duration' => duration
100
- }
101
- end
102
- end
@@ -1,64 +0,0 @@
1
- require 'speed_gun/store'
2
-
3
- class SpeedGun::Store::ElasticSearchStore < SpeedGun::Store
4
- DEFAULT_INDEX = 'speed_gun'
5
-
6
- def initialize(options = {})
7
- @index = options[:index] || DEFAULT_INDEX
8
- @async = options.fetch(:async, true)
9
- @client = options[:client] || default_clinet(options)
10
- end
11
-
12
- def save(object)
13
- @async ? save_with_async(object) : save_without_async(object)
14
- end
15
-
16
- def load(klass, id)
17
- hit = @client.search(
18
- index: @index,
19
- body: {
20
- query: {
21
- match: {
22
- "_id" => id,
23
- "_type" => underscore(klass.name)
24
- }
25
- }
26
- }
27
- )['hits']['hits'].first['_source']
28
-
29
- klass.from_hash(id, hit)
30
- end
31
-
32
- private
33
-
34
- def save_with_async(object)
35
- Thread.new(object) { |object| save_without_async(object) }
36
- end
37
-
38
- def save_without_async(object)
39
- @client.index(
40
- index: @index,
41
- type: underscore(object.class.name),
42
- id: object.id,
43
- body: object.to_hash.merge(
44
- '@timestamp' => Time.now
45
- )
46
- )
47
- end
48
-
49
- def index(klass)
50
- [@prefix, underscore(klass.name)].join('-')
51
- end
52
-
53
- def underscore(name)
54
- name = name
55
- name.sub!(/^[A-Z]/) { |c| c.downcase }
56
- name.gsub!(/[A-Z]/) { |c| "_#{c.downcase}" }
57
- name.gsub!('::', '')
58
- end
59
-
60
- def default_clinet(options)
61
- require 'elasticsearch' unless defined?(Elasticsearch)
62
- Elasticsearch::Client.new(options)
63
- end
64
- end
@@ -1,29 +0,0 @@
1
- require 'speed_gun/store'
2
-
3
- class SpeedGun::Store::FluentLoggerStore < SpeedGun::Store
4
- DEFAULT_PREFIX = 'speed_gun'
5
-
6
- def initialize(options = {})
7
- @prefix = options[:prefix] || DEFAULT_PREFIX
8
- @logger = options[:logger] || default_logger(options)
9
- end
10
-
11
- def save(object)
12
- @logger.post(tag(object), object.to_hash.merge(id: object.id))
13
- end
14
-
15
- def load(klass, id)
16
- nil
17
- end
18
-
19
- private
20
-
21
- def tag(object)
22
- object.class.name.sub(/.*::/, '').downcase
23
- end
24
-
25
- def default_logger(options)
26
- require 'fluent-logger' unless defined?(Fluent::Logger)
27
- Fluent::Logger::FluentLogger.new(@prefix, options)
28
- end
29
- end