Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lukes/profiling
Non-discriminatory profiling of Ruby code leveraging the ruby-prof gem
https://github.com/lukes/profiling
code gem memory optimisation optimization profiler profiling ruby
Last synced: about 2 hours ago
JSON representation
Non-discriminatory profiling of Ruby code leveraging the ruby-prof gem
- Host: GitHub
- URL: https://github.com/lukes/profiling
- Owner: lukes
- License: mit
- Created: 2018-04-19T03:36:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-04-14T03:43:26.000Z (over 3 years ago)
- Last Synced: 2024-04-29T11:42:55.680Z (7 months ago)
- Topics: code, gem, memory, optimisation, optimization, profiler, profiling, ruby
- Language: Ruby
- Homepage:
- Size: 194 KB
- Stars: 12
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![alt ruby_silhouette](https://raw.githubusercontent.com/lukes/profiling/master/img/ruby.png)
# Profiling
Non-discriminatory profiling for your MRI Ruby code. This gem is a small wrapper around the [ruby-prof](https://github.com/ruby-prof/ruby-prof) gem, which is its only dependency. It lets you do simple but powerful profiling of your friend's bad code.
[![Gem Version](https://badge.fury.io/rb/profiling.svg)](https://badge.fury.io/rb/profiling)
[![CircleCI](https://circleci.com/gh/lukes/profiling/tree/master.svg?style=shield)](https://circleci.com/gh/lukes/profiling/tree/master)## Installation
Add this line to your application's Gemfile:
```ruby
gem 'profiling', "~> 4.0"
```And then execute:
$ bundle
Or install it yourself as:
$ gem install profiling
## Getting Started
Profile slow code from your friend or colleague like this:
```ruby
Profiler.run do
# Slow code here...
end
```The next time you call the code it will be profiled and three files will be written into a directory called `profiling`.
### Files Generated
| File | Description |
| ------------- | ------------- |
| `graph.html` | Drill down into the call tree to see where the time is spent |
| `stack.html` | See the profiled code as a nested stack |
| `flat.txt` | List of all functions called, the time spent in each and the number of calls made to that function |### Is it Fast?
No, no it's not. It's really slow. For especially gnarly, deeply nested code you will want to get up and get a coffee. This gem wraps [ruby-prof](https://github.com/ruby-prof/ruby-prof) which is partly written in C, so it's as fast as it can be.
## OptionsUse the `configure` method to set some options:
```ruby
Profiler.configure({
dir: '/tmp/my-dir',
exclude_gems: true,
exclude_standard_lib: true
})
```| Option | Description | Default |
| ------ | --------|------------ |
| `dir` | Directory the files will be created in (can be relative or absolute) | `"profiling"` |
| `exclude_gems` | Exclude ruby gems from the results | `false` |
| `exclude_standard_lib` | Exclude ruby standard library from results | `false` |## Rails Initializer
This initializer is recommended if you're planning to profile in Rails:
```ruby
# config/initializer/profiling.rb
Profiler.configure({
dir: Rails.root.join('tmp/profiling')
})
```## Conditional Profiling
Pass an argument `if:` to enable or disable profiling at run time:
```ruby
Profiler.run(if: user.is_admin?) do
# Slow code here...
end
```## Labels
Labels translate to sub directories that the files will be generated in. This is handy for profiling multiple things at once, preserving files between runs, or grouping profiling results logically.
```ruby
Profiler.run("some-label") do
# Slow code here...
end
```### Preserving files between runs
Keep old files by adding the current time in the label so new files are generated with each run:
```ruby
Profiler.run("some-label-#{Time.now.to_i}") do
# Slow code here...
end
```### Organizing
Use `/` in your labels to group profiling results together in directories:
```ruby
Profiler.run("post/create") do
# Slow code here...
endProfiler.run("post/update") do
# Slow code here...
end
```## Contributing
Bug reports and pull requests are welcome. Pull requests with passing tests are even better.
To run the test suite:
bundle exec rspec
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).