speed_gun 2.0.0.pre.alpha.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,56 +2,28 @@ doctype 5
2
2
  html
3
3
  head
4
4
  meta(charset="UTF-8")
5
+ link(rel="stylesheet" href="#{File.join(SpeedGun.config.prefix, '/feather.css')}")
5
6
  link(rel="stylesheet" href="#{File.join(SpeedGun.config.prefix, '/report.css')}")
6
7
  script(src="https://code.jquery.com/jquery-3.0.0.min.js")
7
8
  script(src="#{File.join(SpeedGun.config.prefix, '/report.js')}")
8
- title #{@report.id} - Speed Gun
9
+ title #{@report.name || @report.id} - Speed Gun
9
10
  body
10
11
  #container
11
12
  #report
12
13
  h1.report-id
13
- = @report.id
14
- span.duration-ms= "% 4.1fms" % (@report.duration * 1000.0)
14
+ = @report.name || @report.name
15
+ span.duration-ms= "%04.1fms" % (@report.duration * 1000.0)
15
16
  .tabs
16
- a.tab-events(href="#events") Events
17
- a.tab-sources(href="#sources") Sources
17
+ a.active.tab.events(href="#events")
18
+ span.icon-bell
19
+ | Events
20
+ a.tab.sources(href="#sources")
21
+ span.icon-file
22
+ | Sources
18
23
 
19
24
  #details
20
25
  #events.active
21
26
  == partial('events', locals: { events: @events })
22
27
 
23
28
  #sources
24
- #source-list
25
- - @report.sources.each do |source|
26
- .source-link
27
- a(href="#file-#{line_id(source.file, 0)}")
28
- span.shortpath= File.basename(source.file)
29
- span.fullpath= source.file
30
- #source-code
31
- - @report.sources.each do |source|
32
- .source(id="file-#{line_id(source.file, 0)}")
33
- h3.filename
34
- a(href="#file-#{line_id(source.file, 0)}")
35
- span.shortpath= File.basename(source.file)
36
- span.fullpath= source.file
37
- .source-code
38
- .line-infos
39
- .line-info.header
40
- .line-cpu CPU
41
- .line-wall Wall
42
- .line-allocs Allocs
43
- .line-calls Calls
44
- .line-no No.
45
- - source.lines.each do |line|
46
- .line-info(id="line-#{line_id(source.file, line.line)}")
47
- .line-cpu= "% 8.1fms" % (line.cpu / 1000.0)
48
- .line-wall= "% 8.1fms" % ((line.wall - line.cpu) / 1000.0)
49
- .line-allocs= line.allocations
50
- .line-calls= "% 4d" % line.calls
51
- .line-no
52
- a(href="#line-#{line_id(source.file, line.line)}")= "% 5d" % line.line
53
- pre.line-codes
54
- .line-code.header Code
55
- - source.lines.each do |line|
56
- .line-code(id="line-code-#{line_id(source.file, line.line)}")= line.code
57
-
29
+ == partial('sources', locals: { sources: @report.sources })
@@ -0,0 +1,35 @@
1
+ #source-list
2
+ - sources.each do |source|
3
+ .source-link
4
+ a(href="#file-#{source_line_id(source.file, 0)}")
5
+ span.shortpath= File.basename(source.file)
6
+ span.fullpath= source.file
7
+ #source-code
8
+ - sources.each do |source|
9
+ .source(id="file-#{source_line_id(source.file, 0)}")
10
+ h3.filename
11
+ a(href="#file-#{source_line_id(source.file, 0)}")
12
+ span.shortpath= File.basename(source.file)
13
+ span.fullpath= source.file
14
+ .source-code
15
+ .source-line
16
+ .line-info
17
+ .line-cpu CPU
18
+ .line-wall Wall
19
+ .line-allocs Allocs
20
+ .line-calls Calls
21
+ .line-no No.
22
+ .line-code Code
23
+ - source.lines.each do |line|
24
+ .source-line(id="line-#{source_line_id(source.file, line.line)}")
25
+ .line-info
26
+ a(href="#line-#{source_line_id(source.file, line.line)}")
27
+ .line-cpu= "% 8.1fms" % (line.cpu / 1000.0)
28
+ .line-wall= "% 8.1fms" % ((line.wall - line.cpu) / 1000.0)
29
+ .line-allocs= line.allocations
30
+ .line-calls= "% 4d" % line.calls
31
+ .line-no
32
+ = "% 5d" % line.line
33
+ .line-code(id="line-code-#{source_line_id(source.file, line.line)}")= line.code
34
+
35
+
@@ -41,7 +41,7 @@ class SpeedGun::Event
41
41
 
42
42
  def finished?
43
43
  @finished_at
44
- end
44
+ end
45
45
 
46
46
  def roughly_finished_at
47
47
  finished_at || started_at
@@ -0,0 +1,52 @@
1
+ require 'speed_gun'
2
+
3
+ class SpeedGun::Hook
4
+ def self.hooks
5
+ @hooks ||= []
6
+ end
7
+
8
+ def self.install!
9
+ hooks.each do |hook|
10
+ hook.available? && hook.install!
11
+ end
12
+ end
13
+
14
+ attr_reader :name
15
+
16
+ def initialize(name, &block)
17
+ @name = name
18
+ @installed = false
19
+ @available_checker = -> { true }
20
+ @execute = -> { true }
21
+ self.class.hooks.push(self)
22
+ instance_eval(&block)
23
+ end
24
+
25
+ def depends(&block)
26
+ @available_checker = block
27
+ end
28
+
29
+ def execute(&block)
30
+ @execute = block
31
+ end
32
+
33
+ def available?
34
+ @available_checker.is_a?(Proc) && @available_checker.call
35
+ end
36
+
37
+ def install!
38
+ return if @installed
39
+ @execute.is_a?(Proc) && @execute.call
40
+ @installed = true
41
+ end
42
+ end
43
+
44
+ module SpeedGun
45
+ def self.hook(name, &block)
46
+ SpeedGun::Hook.new(name, &block)
47
+ end
48
+ end
49
+
50
+ Dir[File.expand_path('../hook/**/*.rb', __FILE__)].each do |hook|
51
+ require hook if File.file?(hook)
52
+ end
@@ -0,0 +1,32 @@
1
+ require 'speed_gun/hook'
2
+
3
+ SpeedGun.hook('Net::HTTP') do
4
+ depends do
5
+ defined?(Net) && defined?(Net::HTTP)
6
+ end
7
+
8
+ execute do
9
+ require 'speed_gun/profiler/http_profiler'
10
+
11
+ class Net::HTTP
12
+ def request_with_speedgun(req, *args, &block)
13
+ payload = { request: { method: req.method, uri: req.uri.to_s, headers: req.to_hash } }
14
+
15
+ SpeedGun::Profiler::HTTPProfiler.profile('http.' + req.method.downcase, payload) do |event|
16
+ res = request_without_speedgun(req, *args, &block)
17
+
18
+ event.payload[:response] = {
19
+ version: res.http_version,
20
+ code: res.code,
21
+ headers: res.to_hash
22
+ }
23
+
24
+ res
25
+ end
26
+ end
27
+
28
+ alias request_without_speedgun request
29
+ alias request request_with_speedgun
30
+ end
31
+ end
32
+ end
@@ -16,6 +16,8 @@ class SpeedGun::Profiler
16
16
  def profile(name = self.class.name, payload = {})
17
17
  started_at = Time.now
18
18
 
19
+ payload[:backtrace] ||= SpeedGun.get_backtrace
20
+
19
21
  event = SpeedGun::Event.new(name, payload, started_at)
20
22
  result = yield(event)
21
23
  event.finish!
@@ -10,6 +10,7 @@ class SpeedGun::Profiler::ActiveSupportNotificatiosProfiler < SpeedGun::Profiler
10
10
  end
11
11
 
12
12
  def self.record(event, name, started, ended, _id, payload, ignore_payload)
13
+ name = name.split('.').reverse.join('.')
13
14
  payload = payload.symbolize_keys
14
15
 
15
16
  ignore_payload.each do |key|
@@ -19,14 +20,10 @@ class SpeedGun::Profiler::ActiveSupportNotificatiosProfiler < SpeedGun::Profiler
19
20
  payload[:backtrace] = backtrace
20
21
 
21
22
  event = SpeedGun::Event.new(name, payload, started, ended)
22
- SpeedGun.current_report.record(event)
23
+ SpeedGun.record(event)
23
24
  end
24
25
 
25
26
  def self.backtrace
26
- Rails.backtrace_cleaner.clean(caller[2..-1]).map do |called|
27
- filename, line, trace = *called.split(':', 3)
28
- filename = File.expand_path(filename)
29
- [filename, line.to_i, trace]
30
- end
27
+ SpeedGun.get_backtrace(caller(2))
31
28
  end
32
29
  end
@@ -0,0 +1,4 @@
1
+ require 'speed_gun/profiler'
2
+
3
+ class SpeedGun::Profiler::HTTPProfiler < SpeedGun::Profiler
4
+ end
@@ -5,6 +5,10 @@ require 'rack/speed_gun'
5
5
  require 'rails/railtie'
6
6
 
7
7
  class SpeedGun::Railtie < ::Rails::Railtie
8
+ config.to_prepare do
9
+ SpeedGun::Hook.install!
10
+ end
11
+
8
12
  initializer 'speed_gun' do |app|
9
13
  app.middleware.insert(0, Rack::SpeedGun)
10
14
 
@@ -6,6 +6,8 @@ class SpeedGun::Report
6
6
  # @return [String] Report ID
7
7
  attr_reader :id
8
8
 
9
+ attr_accessor :name
10
+
9
11
  # @return [Array<SpeedGun::Source>] Profiled source codes
10
12
  attr_reader :sources
11
13
 
@@ -32,6 +34,7 @@ class SpeedGun::Report
32
34
 
33
35
  def initialize
34
36
  @id = SecureRandom.uuid
37
+ @name = nil
35
38
  @sources = []
36
39
  @events = []
37
40
  end
@@ -58,6 +61,7 @@ class SpeedGun::Report
58
61
 
59
62
  def to_hash
60
63
  {
64
+ name: name,
61
65
  sources: sources.map { |source| [ source.id, source.to_hash ] },
62
66
  events: events.map { |event| [event.id, event.to_hash] }
63
67
  }
@@ -1,11 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'semantic'
3
2
 
4
3
  module SpeedGun
5
- VERSION = '2.0.0-alpha.1'
6
-
7
- # @return [Semantic::Version] Version
8
- def self.version
9
- @version ||= Semantic::Version.new(VERSION)
10
- end
4
+ VERSION = '2.0.0'
11
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: speed_gun
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.alpha.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sho Kusano
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-20 00:00:00.000000000 Z
11
+ date: 2016-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -287,13 +287,22 @@ files:
287
287
  - lib/rack/speed_gun.rb
288
288
  - lib/speed_gun.rb
289
289
  - lib/speed_gun/app.rb
290
+ - lib/speed_gun/app/public/feather.css
291
+ - lib/speed_gun/app/public/fonts/feather-webfont.eot
292
+ - lib/speed_gun/app/public/fonts/feather-webfont.svg
293
+ - lib/speed_gun/app/public/fonts/feather-webfont.ttf
294
+ - lib/speed_gun/app/public/fonts/feather-webfont.woff
290
295
  - lib/speed_gun/app/public/report.js
296
+ - lib/speed_gun/app/views/_hint.scss
291
297
  - lib/speed_gun/app/views/events.slim
292
298
  - lib/speed_gun/app/views/payload.slim
293
299
  - lib/speed_gun/app/views/report.scss
294
300
  - lib/speed_gun/app/views/report.slim
301
+ - lib/speed_gun/app/views/sources.slim
295
302
  - lib/speed_gun/config.rb
296
303
  - lib/speed_gun/event.rb
304
+ - lib/speed_gun/hook.rb
305
+ - lib/speed_gun/hook/net/http.rb
297
306
  - lib/speed_gun/profiler.rb
298
307
  - lib/speed_gun/profiler/action_controller_profiler.rb
299
308
  - lib/speed_gun/profiler/action_mailer_profiler.rb
@@ -302,6 +311,7 @@ files:
302
311
  - lib/speed_gun/profiler/active_record_profiler.rb
303
312
  - lib/speed_gun/profiler/active_support_notifications_profiler.rb
304
313
  - lib/speed_gun/profiler/active_support_profiler.rb
314
+ - lib/speed_gun/profiler/http_profiler.rb
305
315
  - lib/speed_gun/profiler/line_profiler.rb
306
316
  - lib/speed_gun/profiler/rack_profiler.rb
307
317
  - lib/speed_gun/railtie.rb
@@ -327,9 +337,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
327
337
  version: '0'
328
338
  required_rubygems_version: !ruby/object:Gem::Requirement
329
339
  requirements:
330
- - - ">"
340
+ - - ">="
331
341
  - !ruby/object:Gem::Version
332
- version: 1.3.1
342
+ version: '0'
333
343
  requirements: []
334
344
  rubyforge_project:
335
345
  rubygems_version: 2.5.1