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.
- checksums.yaml +4 -4
- data/.gitignore +9 -18
- data/.rspec +1 -1
- data/.rubocop.yml +61 -1
- data/.travis.yml +3 -4
- data/LICENSE.txt +17 -18
- data/README.md +19 -137
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/example/rails/.gitignore +18 -0
- data/example/rails/Gemfile +20 -0
- data/example/rails/Gemfile.lock +184 -0
- data/example/rails/README.rdoc +28 -0
- data/example/rails/Rakefile +6 -0
- data/example/rails/app/assets/images/.keep +0 -0
- data/example/rails/app/assets/javascripts/application.js +15 -0
- data/example/rails/app/assets/javascripts/posts.coffee +3 -0
- data/example/rails/app/assets/stylesheets/application.css +15 -0
- data/example/rails/app/assets/stylesheets/posts.scss +3 -0
- data/example/rails/app/assets/stylesheets/scaffolds.scss +73 -0
- data/example/rails/app/controllers/application_controller.rb +5 -0
- data/example/rails/app/controllers/concerns/.keep +0 -0
- data/example/rails/app/controllers/posts_controller.rb +74 -0
- data/example/rails/app/helpers/application_helper.rb +2 -0
- data/example/rails/app/helpers/posts_helper.rb +2 -0
- data/example/rails/app/mailers/.keep +0 -0
- data/example/rails/app/models/.keep +0 -0
- data/example/rails/app/models/concerns/.keep +0 -0
- data/example/rails/app/models/post.rb +2 -0
- data/example/rails/app/views/layouts/application.html.erb +14 -0
- data/example/rails/app/views/posts/_form.html.erb +25 -0
- data/example/rails/app/views/posts/edit.html.erb +6 -0
- data/example/rails/app/views/posts/index.html.erb +29 -0
- data/example/rails/app/views/posts/index.json.jbuilder +4 -0
- data/example/rails/app/views/posts/new.html.erb +5 -0
- data/example/rails/app/views/posts/show.html.erb +14 -0
- data/example/rails/app/views/posts/show.json.jbuilder +1 -0
- data/example/rails/bin/bundle +3 -0
- data/example/rails/bin/rails +9 -0
- data/example/rails/bin/rake +9 -0
- data/example/rails/bin/setup +29 -0
- data/example/rails/bin/spring +15 -0
- data/example/rails/config/application.rb +26 -0
- data/example/rails/config/boot.rb +3 -0
- data/example/rails/config/database.yml +25 -0
- data/example/rails/config/environment.rb +5 -0
- data/example/rails/config/environments/development.rb +41 -0
- data/example/rails/config/environments/production.rb +79 -0
- data/example/rails/config/environments/test.rb +42 -0
- data/example/rails/config/initializers/assets.rb +11 -0
- data/example/rails/config/initializers/backtrace_silencers.rb +7 -0
- data/example/rails/config/initializers/cookies_serializer.rb +3 -0
- data/example/rails/config/initializers/filter_parameter_logging.rb +4 -0
- data/example/rails/config/initializers/inflections.rb +16 -0
- data/example/rails/config/initializers/mime_types.rb +4 -0
- data/example/rails/config/initializers/session_store.rb +3 -0
- data/example/rails/config/initializers/wrap_parameters.rb +14 -0
- data/example/rails/config/locales/en.yml +23 -0
- data/example/rails/config/routes.rb +57 -0
- data/example/rails/config/secrets.yml +22 -0
- data/example/rails/config.ru +4 -0
- data/example/rails/db/migrate/20160619175824_create_posts.rb +10 -0
- data/example/rails/db/schema.rb +23 -0
- data/example/rails/db/seeds.rb +7 -0
- data/example/rails/lib/assets/.keep +0 -0
- data/example/rails/lib/tasks/.keep +0 -0
- data/example/rails/log/.keep +0 -0
- data/example/rails/public/404.html +67 -0
- data/example/rails/public/422.html +67 -0
- data/example/rails/public/500.html +66 -0
- data/example/rails/public/favicon.ico +0 -0
- data/example/rails/public/robots.txt +5 -0
- data/example/rails/test/controllers/.keep +0 -0
- data/example/rails/test/controllers/posts_controller_test.rb +49 -0
- data/example/rails/test/fixtures/.keep +0 -0
- data/example/rails/test/fixtures/posts.yml +9 -0
- data/example/rails/test/helpers/.keep +0 -0
- data/example/rails/test/integration/.keep +0 -0
- data/example/rails/test/mailers/.keep +0 -0
- data/example/rails/test/models/.keep +0 -0
- data/example/rails/test/models/post_test.rb +7 -0
- data/example/rails/test/test_helper.rb +10 -0
- data/example/rails/vendor/assets/javascripts/.keep +0 -0
- data/example/rails/vendor/assets/stylesheets/.keep +0 -0
- data/lib/rack/speed_gun.rb +100 -0
- data/lib/speed_gun/app/public/report.js +58 -0
- data/lib/speed_gun/app/views/events.slim +11 -0
- data/lib/speed_gun/app/views/payload.slim +20 -0
- data/lib/speed_gun/app/views/report.scss +322 -0
- data/lib/speed_gun/app/views/report.slim +57 -0
- data/lib/speed_gun/app.rb +53 -0
- data/lib/speed_gun/config.rb +25 -32
- data/lib/speed_gun/event.rb +29 -39
- data/lib/speed_gun/profiler/action_controller_profiler.rb +3 -8
- data/lib/speed_gun/profiler/action_mailer_profiler.rb +7 -0
- data/lib/speed_gun/profiler/action_view_profiler.rb +3 -8
- data/lib/speed_gun/profiler/active_job_profiler.rb +6 -0
- data/lib/speed_gun/profiler/active_record_profiler.rb +3 -8
- data/lib/speed_gun/profiler/active_support_notifications_profiler.rb +9 -6
- data/lib/speed_gun/profiler/active_support_profiler.rb +8 -0
- data/lib/speed_gun/profiler/line_profiler.rb +32 -0
- data/lib/speed_gun/profiler/rack_profiler.rb +2 -4
- data/lib/speed_gun/profiler.rb +15 -9
- data/lib/speed_gun/railtie.rb +21 -5
- data/lib/speed_gun/report.rb +65 -0
- data/lib/speed_gun/source.rb +90 -0
- data/lib/speed_gun/store/file_store.rb +35 -0
- data/lib/speed_gun/store/memory_store.rb +7 -14
- data/lib/speed_gun/store.rb +10 -3
- data/lib/speed_gun/version.rb +9 -1
- data/lib/speed_gun.rb +21 -26
- data/speed_gun.gemspec +21 -16
- metadata +168 -58
- data/.coveralls.yml +0 -1
- data/lib/speed_gun/app/views/meter.html.slim +0 -4
- data/lib/speed_gun/middleware.rb +0 -91
- data/lib/speed_gun/profile.rb +0 -102
- data/lib/speed_gun/store/elastic_search_store.rb +0 -64
- data/lib/speed_gun/store/fluent_logger_store.rb +0 -29
- data/lib/speed_gun/store/memcache_store.rb +0 -40
- data/lib/speed_gun/store/multiple_store.rb +0 -23
- data/lib/speed_gun/store/redis_store.rb +0 -41
- data/lib/speed_gun/template.rb +0 -15
- data/spec/lib/speed_gun/config_spec.rb +0 -37
- data/spec/lib/speed_gun/event_spec.rb +0 -70
- data/spec/lib/speed_gun/middleware_spec.rb +0 -65
- data/spec/lib/speed_gun/profile_spec.rb +0 -41
- data/spec/lib/speed_gun_spec.rb +0 -52
- data/spec/spec_helper.rb +0 -9
- data/spec/support/simplecov.rb +0 -12
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'speed_gun/store'
|
2
|
-
|
3
|
-
class SpeedGun::Store::MemcacheStroe < SpeedGun::Store
|
4
|
-
DEFAULT_PREFIX = 'speed-gun'
|
5
|
-
DEFAULT_EXPIRES_IN_SECONDS = 60 * 60 * 24
|
6
|
-
|
7
|
-
def initialize(options = {})
|
8
|
-
@prefix = options[:prefix] || DEFAULT_PREFIX
|
9
|
-
@client = options[:client] || default_client(options)
|
10
|
-
@expires = (options[:expires] || DEFAULT_EXPIRES_IN_SECONDS).to_i
|
11
|
-
end
|
12
|
-
|
13
|
-
def save(object)
|
14
|
-
@client.set(
|
15
|
-
key(object.class, object.id),
|
16
|
-
object.to_hash.to_msgpack,
|
17
|
-
@expires
|
18
|
-
)
|
19
|
-
end
|
20
|
-
|
21
|
-
def load(klass, id)
|
22
|
-
klass.from_hash(id, MessagePack.unpack(@client.get(key(klass, id))))
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def key(klass, id)
|
28
|
-
klass_name = klass.name
|
29
|
-
klass_name.gsub!(/([a-z])([A-Z])/) { |c| "#{$1.to_s}_#{$2.to_s.downcase}" }
|
30
|
-
klass_name.gsub!(/[A-Z]/) { |c| "#{c.downcase}" }
|
31
|
-
klass_name.gsub!('::', '-')
|
32
|
-
|
33
|
-
[@prefix, klass_name, id].join('-')
|
34
|
-
end
|
35
|
-
|
36
|
-
def default_client(options)
|
37
|
-
require 'dalli' unless defined?(Dalli)
|
38
|
-
Dalli.new(options)
|
39
|
-
end
|
40
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'speed_gun/store'
|
2
|
-
|
3
|
-
class SpeedGun::Store::MultipleStore < SpeedGun::Store
|
4
|
-
def initialize(stores = [])
|
5
|
-
@stores = stores
|
6
|
-
end
|
7
|
-
|
8
|
-
def save(object)
|
9
|
-
@stores.each do |store|
|
10
|
-
store.save(object)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def load(klass, id)
|
15
|
-
@stores.each do |store|
|
16
|
-
ret = store.load(klass, id)
|
17
|
-
|
18
|
-
return ret if ret
|
19
|
-
end
|
20
|
-
|
21
|
-
nil
|
22
|
-
end
|
23
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'msgpack'
|
2
|
-
require 'speed_gun/store'
|
3
|
-
|
4
|
-
class SpeedGun::Store::RedisStore < SpeedGun::Store
|
5
|
-
DEFAULT_PREFIX = 'speed-gun'
|
6
|
-
DEFAULT_EXPIRES_IN_SECONDS = 60 * 60 * 24
|
7
|
-
|
8
|
-
def initialize(options = {})
|
9
|
-
@prefix = options[:prefix] || DEFAULT_PREFIX
|
10
|
-
@client = options[:client] || default_client(options)
|
11
|
-
@expires = (options[:expires] || DEFAULT_EXPIRES_IN_SECONDS).to_i
|
12
|
-
end
|
13
|
-
|
14
|
-
def save(object)
|
15
|
-
@client.setex(
|
16
|
-
key(object.class, object.id),
|
17
|
-
@expires,
|
18
|
-
object.to_hash.to_msgpack
|
19
|
-
)
|
20
|
-
end
|
21
|
-
|
22
|
-
def load(klass, id)
|
23
|
-
klass.from_hash(id, MessagePack.unpack(@client.get(key(klass, id))))
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def key(klass, id)
|
29
|
-
klass_name = klass.name
|
30
|
-
klass_name.gsub!(/([a-z])([A-Z])/) { |c| "#{$1.to_s}_#{$2.to_s.downcase}" }
|
31
|
-
klass_name.gsub!(/[A-Z]/) { |c| "#{c.downcase}" }
|
32
|
-
klass_name.gsub!('::', '-')
|
33
|
-
|
34
|
-
[@prefix, klass_name, id].join('-')
|
35
|
-
end
|
36
|
-
|
37
|
-
def default_client(options)
|
38
|
-
require 'redis' unless defined? Redis
|
39
|
-
Redis.new(options)
|
40
|
-
end
|
41
|
-
end
|
data/lib/speed_gun/template.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'speed_gun'
|
2
|
-
require 'slim'
|
3
|
-
|
4
|
-
class SpeedGun::Template < Slim::Template
|
5
|
-
TEMPLATE_PATH =
|
6
|
-
File.join(File.dirname(__FILE__), 'app/views/meter.html.slim')
|
7
|
-
|
8
|
-
def self.render
|
9
|
-
new.render(SpeedGun.current_profile)
|
10
|
-
end
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
super(TEMPLATE_PATH, pretty: false)
|
14
|
-
end
|
15
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe SpeedGun::Config do
|
4
|
-
subject(:config) { described_class.new }
|
5
|
-
|
6
|
-
describe '#enable!' do
|
7
|
-
before do
|
8
|
-
config.disable!
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'enables the config' do
|
12
|
-
expect(config).to_not be_enabled
|
13
|
-
config.enable!
|
14
|
-
expect(config).to be_enabled
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#disable!' do
|
19
|
-
it 'disables the config' do
|
20
|
-
expect(config).to_not be_disabled
|
21
|
-
config.disable!
|
22
|
-
expect(config).to be_disabled
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe '#enabled?' do
|
27
|
-
it 'defaults to true' do
|
28
|
-
expect(config.enabled?).to be_true
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '#disabled?' do
|
33
|
-
it 'defaults to false' do
|
34
|
-
expect(config.disabled?).to be_false
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe SpeedGun::Event do
|
4
|
-
let(:event_name) { 'spec.test' }
|
5
|
-
|
6
|
-
subject(:event) { described_class.new(event_name) }
|
7
|
-
|
8
|
-
describe '#id' do
|
9
|
-
subject { event.id }
|
10
|
-
|
11
|
-
it { should be_kind_of(String) }
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '#name' do
|
15
|
-
subject { event.name }
|
16
|
-
|
17
|
-
it { should be_kind_of(String) }
|
18
|
-
it { should eq(event_name) }
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '#started_at' do
|
22
|
-
subject { event.started_at }
|
23
|
-
|
24
|
-
it { should be_kind_of(Time) }
|
25
|
-
end
|
26
|
-
|
27
|
-
describe '#finished_at' do
|
28
|
-
subject { event.finished_at }
|
29
|
-
|
30
|
-
context 'when finished event' do
|
31
|
-
before { event.finish! }
|
32
|
-
|
33
|
-
it { should be_kind_of(Time) }
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'when continues event' do
|
37
|
-
it { should be_nil }
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe '#finish!' do
|
42
|
-
it 'finishes the event' do
|
43
|
-
expect(event).to_not be_finished
|
44
|
-
event.finish!
|
45
|
-
expect(event).to be_finished
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '#duration' do
|
50
|
-
subject(:duration) { event.duration }
|
51
|
-
|
52
|
-
context 'when continues event' do
|
53
|
-
it { should eq(-1) }
|
54
|
-
end
|
55
|
-
|
56
|
-
context 'when finished event' do
|
57
|
-
before { event.finish! }
|
58
|
-
|
59
|
-
it { should be_kind_of(Float) }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe '#to_hash' do
|
64
|
-
it 'valid serialize' do
|
65
|
-
expect(
|
66
|
-
SpeedGun::Event.from_hash(event.id, event.to_hash).to_hash
|
67
|
-
).to eq(event.to_hash)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rack/test'
|
3
|
-
|
4
|
-
describe SpeedGun::Middleware do
|
5
|
-
include Rack::Test::Methods
|
6
|
-
|
7
|
-
before(:all) do
|
8
|
-
SpeedGun.config.skip_paths << '/skip'
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:app) do
|
12
|
-
builder = Rack::Builder.new do
|
13
|
-
use SpeedGun::Middleware
|
14
|
-
|
15
|
-
map '/skip' do
|
16
|
-
process = lambda do |env|
|
17
|
-
[
|
18
|
-
200,
|
19
|
-
{ 'Content-Type' => 'text/html' },
|
20
|
-
"<html><BODY><h1>Skip</h1></BODY>\n \t</html>"
|
21
|
-
]
|
22
|
-
end
|
23
|
-
|
24
|
-
run process
|
25
|
-
end
|
26
|
-
|
27
|
-
map '/html' do
|
28
|
-
process = lambda do |env|
|
29
|
-
[
|
30
|
-
200,
|
31
|
-
{ 'Content-Type' => 'text/html' },
|
32
|
-
"<html><BODY><h1>Hi</h1></BODY>\n \t</html>"
|
33
|
-
]
|
34
|
-
end
|
35
|
-
|
36
|
-
run process
|
37
|
-
end
|
38
|
-
end
|
39
|
-
builder.to_app
|
40
|
-
end
|
41
|
-
|
42
|
-
describe 'GET /skip' do
|
43
|
-
subject(:response) { get '/skip' }
|
44
|
-
|
45
|
-
it { should be_ok }
|
46
|
-
|
47
|
-
describe '#headers' do
|
48
|
-
subject { response.headers }
|
49
|
-
|
50
|
-
it { should_not be_has_key('X-SpeedGun-Profile-Id') }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe 'GET /html' do
|
55
|
-
subject(:response) { get '/html' }
|
56
|
-
|
57
|
-
it { should be_ok }
|
58
|
-
|
59
|
-
describe '#headers' do
|
60
|
-
subject { response.headers }
|
61
|
-
|
62
|
-
it { should be_has_key('X-SpeedGun-Profile-Id') }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe SpeedGun::Profile do
|
4
|
-
subject(:profile) { described_class.new }
|
5
|
-
|
6
|
-
describe '#id' do
|
7
|
-
subject { profile.id }
|
8
|
-
|
9
|
-
it { should be_kind_of(String) }
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '#events' do
|
13
|
-
subject { profile.events }
|
14
|
-
|
15
|
-
it { should be_kind_of(Array) }
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#record!' do
|
19
|
-
let(:logger) { double(debug: nil) }
|
20
|
-
let(:event) { SpeedGun::Event.new('spec.test') }
|
21
|
-
|
22
|
-
before { profile.config.logger = logger }
|
23
|
-
|
24
|
-
it 'records event' do
|
25
|
-
expect(profile.record!(event)).to eq(profile.events)
|
26
|
-
expect(profile.events).to include(event)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '#to_hash' do
|
31
|
-
let(:event) { SpeedGun::Event.new('spec.test') }
|
32
|
-
|
33
|
-
before { profile.record!(event) }
|
34
|
-
|
35
|
-
it 'valid serialize' do
|
36
|
-
expect(
|
37
|
-
SpeedGun::Profile.from_hash(profile.id, profile.to_hash).to_hash
|
38
|
-
).to eq(profile.to_hash)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/spec/lib/speed_gun_spec.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe SpeedGun do
|
4
|
-
subject { described_class }
|
5
|
-
|
6
|
-
describe '#config' do
|
7
|
-
subject { described_class.config }
|
8
|
-
|
9
|
-
it { should be_kind_of(SpeedGun::Config) }
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '#current_profile' do
|
13
|
-
let(:profile) { double }
|
14
|
-
subject(:current_profile) { described_class.current_profile }
|
15
|
-
|
16
|
-
it 'defaults to be nil' do
|
17
|
-
expect(current_profile).to be_nil
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'thread localy' do
|
21
|
-
described_class.current_profile = profile
|
22
|
-
expect(current_profile).to eq(profile)
|
23
|
-
|
24
|
-
thread = Thread.new { expect(described_class.current_profile).to be_nil }
|
25
|
-
thread.join
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '#discard_profile!' do
|
30
|
-
let(:profile) { double }
|
31
|
-
|
32
|
-
it 'discards current profile' do
|
33
|
-
described_class.current_profile = profile
|
34
|
-
described_class.discard_profile!
|
35
|
-
expect(described_class.current_profile).to be_nil
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe '#enabled?' do
|
40
|
-
context 'when enabled' do
|
41
|
-
before { described_class.config.stub(enabled?: true) }
|
42
|
-
|
43
|
-
it { should be_enabled }
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'when disabled' do
|
47
|
-
before { described_class.config.stub(enabled?: false) }
|
48
|
-
|
49
|
-
it { should_not be_enabled }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
data/spec/spec_helper.rb
DELETED
data/spec/support/simplecov.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'simplecov'
|
2
|
-
require 'simplecov-console'
|
3
|
-
require 'coveralls'
|
4
|
-
|
5
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
-
SimpleCov::Formatter::HTMLFormatter,
|
7
|
-
SimpleCov::Formatter::Console,
|
8
|
-
Coveralls::SimpleCov::Formatter
|
9
|
-
]
|
10
|
-
SimpleCov.start do
|
11
|
-
add_filter('spec')
|
12
|
-
end
|