tracer_bullets 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tracer_bullets.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 nate
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,102 @@
1
+ Tracer Bullets
2
+ ===========
3
+
4
+ > Tracer ammunition (tracers) are bullets or cannon caliber projectiles that are built with a small pyrotechnic charge in their base. Ignited by the burning powder, the pyrotechnic composition burns very brightly, making the projectile visible to the naked eye. This enables the shooter to follow the projectile trajectory to make aiming corrections.
5
+
6
+ > [Wikipedia](http://en.wikipedia.org/wiki/Tracer_ammunition)
7
+
8
+ Tracer Bullet is also an alter ego of Calvin in the comic strip Calvin and Hobbes. :)
9
+
10
+ -----------------------
11
+
12
+ The *Tracer Bullets* gem makes studying the performance of your Rails app from its development log file a lot easier.
13
+
14
+
15
+ ## Background
16
+
17
+ Performance tuning a Rails app is still pretty damn hard. There are great tools out there like New Relic, and even Rails own performance tests, but still, I find areas where I'm tearing my hair out looking for slow bits.
18
+
19
+ On the Obama re-election campaign, I did a ton of performance engineering, and the tool that helped me out the most was simply something I built to add "tracer bullets" to my code. These bullets were just method calls to log the current location of the program and how much time had elapsed since the last time it was called.
20
+
21
+ I keep finding myself reinventing this same type of performance logging tool to solve performance bottlenecks in things I work on today, like **[Draft (an app to help people write better)](http://draftin.com)**
22
+
23
+ So here's a really simple version I made for everyone to use. It gives you a method to call:
24
+
25
+ ```ruby
26
+ tracer_bullet
27
+ ```
28
+
29
+ in your controllers and views. When you request an action from your Rails app, that method will log the elapsed time since the last time it was called as well as its location in your controller or view.
30
+
31
+ As you intermix them with your code, you'll notice it becomes a lot easier to narrow your focus on the slow parts of the request.
32
+
33
+ ## Syntax
34
+
35
+ In a controller, just call the method:
36
+
37
+ ```ruby
38
+ tracer_bullet
39
+ ```
40
+
41
+ In a view, call it with:
42
+
43
+ ```erb
44
+ <%= tracer_bullet %>
45
+ ```
46
+
47
+ To save keystrokes, you can also use the alias:
48
+
49
+ ```ruby
50
+ tb
51
+ ```
52
+
53
+ ## Example Log
54
+
55
+ The output of your development.log file will look like:
56
+
57
+ ```
58
+ Elapsed: 4.505ms /Users/nate/git/afternoon/app/views/documents/edit.html.erb:482
59
+
60
+ # Other things in your log file
61
+
62
+ Elapsed: 7.096ms /Users/nate/git/afternoon/app/views/documents/edit.html.erb:539
63
+ ```
64
+
65
+ Letting you know that between line 482 of my edit.html.erb file and line 539, 7ms had passed. That isn't my slow section.
66
+
67
+ Now if it was obviously a lot slower like 200ms, I might take a good look at what's happening in that block of code.
68
+
69
+ ## Development Only
70
+
71
+ These traces only run in Development mode. So you can leave them in your code if you really want to. I prefer to remove them, once I've got my problem solved.
72
+
73
+
74
+ Installation
75
+ ------------
76
+
77
+ 1) Add 'tracer_bullet' to your Gemfile. Probably best to just add it to your development group:
78
+
79
+ ```
80
+ group :development do
81
+ gem 'tracer_bullet'
82
+ end
83
+ ```
84
+
85
+ 2) Run `bundle install`.
86
+ 3) Restart your server
87
+ 4) Call the tracer_bullet method in your actions:
88
+
89
+ ```ruby
90
+ tracer_bullet
91
+ ```
92
+
93
+ or view code:
94
+
95
+ ```erb
96
+ <%= tracer_bullet %>
97
+ ```
98
+
99
+
100
+ Feedback
101
+ --------
102
+ [Source code available on Github](https://github.com/n8/tracer_bullets). Feedback and pull requests are greatly appreciated. Let me know if I can improve this.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module TracerBullets
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1,54 @@
1
+ require "tracer_bullets/version"
2
+
3
+ module TracerBullets
4
+
5
+ module Methods
6
+ def tracer_bullet
7
+ if Rails.env.development?
8
+ Rails.logger.debug( "Elapsed: #{((Time.now - @tracer_bullet_start_time)*1000).to_i}ms #{caller(0)[1]}" )
9
+ @tracer_bullet_start_time = Time.now
10
+ end
11
+ end
12
+ alias_method :tb, :tracer_bullet
13
+ end
14
+
15
+ module Controller
16
+ extend ActiveSupport::Concern
17
+
18
+ included do
19
+ before_filter :setup_tracer_bullet_start_time
20
+ end
21
+
22
+ module InstanceMethods
23
+ include Methods
24
+
25
+ def setup_tracer_bullet_start_time
26
+ @tracer_bullet_start_time = Time.now
27
+ end
28
+ end
29
+ end
30
+
31
+ module View
32
+ extend ActiveSupport::Concern
33
+
34
+ module InstanceMethods
35
+ include Methods
36
+ end
37
+ end
38
+
39
+
40
+ class Railtie < Rails::Railtie
41
+ initializer "tracer_bullet.action_controller" do
42
+ ActiveSupport.on_load(:action_controller) do
43
+ include TracerBullets::Controller
44
+ end
45
+ end
46
+
47
+ initializer "tracer_bullet.action_view" do
48
+ ActiveSupport.on_load(:action_view) do
49
+ include TracerBullets::View
50
+ end
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tracer_bullets/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tracer_bullets"
8
+ spec.version = TracerBullets::VERSION
9
+ spec.authors = ["nate"]
10
+ spec.email = ["nate@cityposh.com"]
11
+ spec.description = %q{A simple way to see time expiration in your Rails log files}
12
+ spec.summary = %q{A simple way to see time expiration in your Rails log files}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tracer_bullets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - nate
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: A simple way to see time expiration in your Rails log files
47
+ email:
48
+ - nate@cityposh.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/tracer_bullets.rb
59
+ - lib/tracer_bullets/version.rb
60
+ - tracer_bullets.gemspec
61
+ homepage: ''
62
+ licenses:
63
+ - MIT
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.23
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: A simple way to see time expiration in your Rails log files
86
+ test_files: []