Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

profiling

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

profiling

  • 4.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

alt ruby_silhouette

Profiling

Non-discriminatory profiling for your MRI Ruby code. This gem is a small wrapper around the ruby-prof gem, which is its only dependency. It lets you do simple but powerful profiling of your friend's bad code.

Gem Version CircleCI

Installation

Add this line to your application's Gemfile:

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:

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

FileDescription
graph.htmlDrill down into the call tree to see where the time is spent
stack.htmlSee the profiled code as a nested stack
flat.txtList 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 which is partly written in C, so it's as fast as it can be.

Options

Use the configure method to set some options:

Profiler.configure({
  dir: '/tmp/my-dir',
  exclude_gems: true,
  exclude_standard_lib: true
})
OptionDescriptionDefault
dirDirectory the files will be created in (can be relative or absolute)"profiling"
exclude_gemsExclude ruby gems from the resultsfalse
exclude_standard_libExclude ruby standard library from resultsfalse

Rails Initializer

This initializer is recommended if you're planning to profile in Rails:

# 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:

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.

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:

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:

Profiler.run("post/create") do
  # Slow code here...
end

Profiler.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.

FAQs

Package last updated on 14 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc