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.
- checksums.yaml +4 -4
- data/example/rails/app/controllers/posts_controller.rb +2 -0
- data/lib/rack/speed_gun.rb +4 -4
- data/lib/speed_gun.rb +17 -0
- data/lib/speed_gun/app.rb +6 -3
- data/lib/speed_gun/app/public/feather.css +572 -0
- data/lib/speed_gun/app/public/fonts/feather-webfont.eot +0 -0
- data/lib/speed_gun/app/public/fonts/feather-webfont.svg +158 -0
- data/lib/speed_gun/app/public/fonts/feather-webfont.ttf +0 -0
- data/lib/speed_gun/app/public/fonts/feather-webfont.woff +0 -0
- data/lib/speed_gun/app/public/report.js +21 -12
- data/lib/speed_gun/app/views/_hint.scss +648 -0
- data/lib/speed_gun/app/views/events.slim +14 -11
- data/lib/speed_gun/app/views/payload.slim +7 -1
- data/lib/speed_gun/app/views/report.scss +246 -228
- data/lib/speed_gun/app/views/report.slim +11 -39
- data/lib/speed_gun/app/views/sources.slim +35 -0
- data/lib/speed_gun/event.rb +1 -1
- data/lib/speed_gun/hook.rb +52 -0
- data/lib/speed_gun/hook/net/http.rb +32 -0
- data/lib/speed_gun/profiler.rb +2 -0
- data/lib/speed_gun/profiler/active_support_notifications_profiler.rb +3 -6
- data/lib/speed_gun/profiler/http_profiler.rb +4 -0
- data/lib/speed_gun/railtie.rb +4 -0
- data/lib/speed_gun/report.rb +4 -0
- data/lib/speed_gun/version.rb +1 -7
- metadata +14 -4
@@ -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.
|
14
|
-
span.duration-ms= "%
|
14
|
+
= @report.name || @report.name
|
15
|
+
span.duration-ms= "%04.1fms" % (@report.duration * 1000.0)
|
15
16
|
.tabs
|
16
|
-
a.tab
|
17
|
-
|
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
|
-
|
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
|
+
|
data/lib/speed_gun/event.rb
CHANGED
@@ -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
|
data/lib/speed_gun/profiler.rb
CHANGED
@@ -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.
|
23
|
+
SpeedGun.record(event)
|
23
24
|
end
|
24
25
|
|
25
26
|
def self.backtrace
|
26
|
-
|
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
|
data/lib/speed_gun/railtie.rb
CHANGED
data/lib/speed_gun/report.rb
CHANGED
@@ -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
|
}
|
data/lib/speed_gun/version.rb
CHANGED
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
|
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-
|
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:
|
342
|
+
version: '0'
|
333
343
|
requirements: []
|
334
344
|
rubyforge_project:
|
335
345
|
rubygems_version: 2.5.1
|