tracer_bullet 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,29 +1,91 @@
1
- # TracerBullet
1
+ Tracer Bullet
2
+ ===========
2
3
 
3
- TODO: Write a gem description
4
+ > The idea of tracer bullets comes obviously from gunnery artillery. In the heavy artillery days, you would take your gun position, your target position, the wind, temperature, elevation, and other factors, and feed that into a firing table. You would get a solution that said to aim your gun at this angle and elevation, and fire. And you'd fire your gun and hope that your shell landed somewhere close to your target.
4
5
 
5
- ## Installation
6
+ > An alternative to that approach is to use tracer bullets. If your target is moving, or if you don't know all the factors,you use tracer bullets—little phosphorous rounds intermixed with real rounds in your gun. As you fire, you can actually see the tracer bullets. And where they are landing is where the actual bullets are landing. If you're not quite on target—because you can see if you're not on target—you can adjust your position.
6
7
 
7
- Add this line to your application's Gemfile:
8
+ > Dave Thomas, [Artima](http://www.artima.com/intv/tracer.html)
8
9
 
9
- gem 'tracer_bullet'
10
+ Tracer Bullets makes studying the performance of your Rails app from it's log file in development a lot easier. All it does is give you a method to call:
10
11
 
11
- And then execute:
12
+ ```ruby
13
+ tracer_bullet
14
+ ```
12
15
 
13
- $ bundle
16
+ 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 it's location in your Controller or View.
14
17
 
15
- Or install it yourself as:
18
+ Sprinkle them around and it's a lot easier to narrow your focus on the slow parts of the request.
16
19
 
17
- $ gem install tracer_bullet
20
+ ## Syntax
18
21
 
19
- ## Usage
22
+ In a controller, just call the method:
20
23
 
21
- TODO: Write usage instructions here
24
+ ```ruby
25
+ tracer_bullet
26
+ ```
27
+
28
+ In a view, call it with:
29
+
30
+ ```erb
31
+ <%= tracer_bullet %>
32
+ ```
33
+
34
+ You can also use the alias:
35
+
36
+ ```ruby
37
+ tb
38
+ ```
39
+
40
+ if you want to save the keystrokes.
41
+
42
+ The output in your development.log file will now have these:
43
+
44
+ ```
45
+ Elapsed: 4.505ms /Users/nate/git/afternoon/app/views/documents/edit.html.erb:482
46
+
47
+ # Other things in your log file
48
+
49
+ Elapsed: 7.096ms /Users/nate/git/afternoon/app/views/documents/edit.html.erb:539
50
+ ```
51
+
52
+ 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.
53
+
54
+ 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.
55
+
56
+ ## Background
57
+
58
+ Performance tuning a Rails app is still pretty damn hard. There's great tools out there like New Relic, and even Rails own performance tests, but still I find areas where I'm still tearing my hair out looking for the slow bits.
59
+
60
+ 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.
61
+
62
+ 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)**
63
+
64
+ These aren't the same "tracer bullets" that Dave was referring to above, but I like the metaphor just the same.
65
+
66
+ So here's a really simple version I made for everyone to use.
67
+
68
+ Installation
69
+ ------------
70
+
71
+ 1. Add `gem 'tracer_bullet'` to your Gemfile.
72
+ 2. Run `bundle install`.
73
+ 3. Restart your server
74
+ 4. Call the tracer_bullet method in your actions:
75
+
76
+ ```ruby
77
+ tracer_bullet
78
+ ```
79
+
80
+ or view code:
81
+
82
+ ```erb
83
+ <%= tracer_bullet %>
84
+ ```
85
+
86
+
87
+ Feedback
88
+ --------
89
+ [Source code available on Github](https://github.com/n8/tracer_bullet). Feedback and pull requests are greatly appreciated. Let me know if I can improve this.
22
90
 
23
- ## Contributing
24
91
 
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
@@ -5,7 +5,7 @@ module TracerBullet
5
5
  module Methods
6
6
  def tracer_bullet
7
7
  if Rails.env.development?
8
- Rails.logger.debug( "Elapsed: #{(Time.now - @tracer_bullet_start_time)*1000}ms #{caller(0)[1]}" )
8
+ Rails.logger.debug( "Elapsed: #{(Time.now - @tracer_bullet_start_time)*1000.00}ms #{caller(0)[1]}" )
9
9
  @tracer_bullet_start_time = Time.now
10
10
  end
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module TracerBullet
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tracer_bullet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-30 00:00:00.000000000 Z
12
+ date: 2013-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler