|
| 1 | +# rails-dtrace |
| 2 | + |
| 3 | +The rails-dtrace gem hooks into the ActiveSupport::Notifications |
| 4 | +instruments in Rails, turning them into DTrace probes. |
| 5 | + |
| 6 | +## Requirements |
| 7 | + |
| 8 | +An OS that supports DTrace. For example: |
| 9 | +* MacOS X |
| 10 | +* Illumos |
| 11 | +* SmartOS |
| 12 | +* Solaris |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | +Add this line to your application's Gemfile: |
| 17 | + |
| 18 | +```ruby |
| 19 | +gem 'ruby-usdt', :git => 'https://github.com/chrisa/ruby-usdt.git', |
| 20 | + :submodules => true, :branch => 'disable_provider' |
| 21 | +gem 'rails-dtrace' |
| 22 | +``` |
| 23 | + |
| 24 | +And then execute: |
| 25 | + |
| 26 | +```bash |
| 27 | +$ bundle |
| 28 | +``` |
| 29 | + |
| 30 | +## Warning |
| 31 | + |
| 32 | +This gem in an experiment in progress. The code does not have automated |
| 33 | +tests, and the performance impact of ActiveSupport::Notifications |
| 34 | +combined with ruby-usdt and libusdt are unknown. **DO NOT USE THIS IN |
| 35 | +PRODUCTION** unless you love risk. |
| 36 | + |
| 37 | +Also, this gem requires experimental behavior in libusdt/ruby-usdt. |
| 38 | +Core behavior may drastically change between releases/commits of this |
| 39 | +gem. When this is no longer the case (and I figure out how to write |
| 40 | +tests around this gem) these warnings will disappear. |
| 41 | + |
| 42 | +## Usage |
| 43 | + |
| 44 | +Once you add the gem to your Rails application, it will automatically |
| 45 | +subscribe to all notifications, turning them into DTrace probes. The |
| 46 | +arguments to the probes will be: |
| 47 | + |
| 48 | +* `arg0` - Start time of notification - Integer |
| 49 | +* `arg1` - End time of notification - Integer |
| 50 | +* `arg2` - Unique identifier of notification - String |
| 51 | +* `arg3` - Stringified hash of notification payload - String |
| 52 | + |
| 53 | +The following dtrace command can be used, as an example: |
| 54 | + |
| 55 | +```bash |
| 56 | +sudo dtrace -n 'ruby*:rails:: { printf("%d %d %s %s", arg0, arg1, |
| 57 | + copyinstr(arg2), copyinstr(arg3)) }' |
| 58 | +``` |
| 59 | + |
| 60 | +Notifications are lazy-loaded, so even though rails-dtrace subscribes to |
| 61 | +all available instruments, they will only be converted to probes as |
| 62 | +they fire in Rails code. For this reason, in order to get a full picture |
| 63 | +of what is happening in a Rails process, enough load should be generated |
| 64 | +to ensure that all important probes are registered before tracing. |
| 65 | + |
| 66 | +## Contributing |
| 67 | + |
| 68 | +1. Fork it |
| 69 | +2. Create your feature branch (`git checkout -b my-new-feature`) |
| 70 | +3. Commit your changes (`git commit -am 'Added some feature'`) |
| 71 | +4. Push to the branch (`git push origin my-new-feature`) |
| 72 | +5. Create new Pull Request |
| 73 | + |
| 74 | +## Suggestions for Contributions |
| 75 | + |
| 76 | +* How the F do you test this thing? |
| 77 | +* Can Rails instruments be detected at initialization time? |
| 78 | +* Notifications do start/end in one instrument. DTrace probes tend to |
| 79 | + fire multiple probes, on entry and exit. This lets you write scripts |
| 80 | + to do neat analytics on event timing. Can Notifications be hacked to |
| 81 | + do this? |
| 82 | +* The Responder turns the Notification payload (a hash) into a string. |
| 83 | + This can surely be better. |
| 84 | + |
| 85 | +## License |
| 86 | + |
| 87 | +Copyright 2012 Eric Saxby |
| 88 | + |
| 89 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 90 | +you may not use this file except in compliance with the License. |
| 91 | +You may obtain a copy of the License at |
| 92 | + |
| 93 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 94 | + |
| 95 | +Unless required by applicable law or agreed to in writing, software |
| 96 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 97 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 98 | +See the License for the specific language governing permissions and |
| 99 | +limitations under the License. |
0 commit comments