0.0
No commit activity in last 3 years
No release in over 3 years
Nest code blocks and time them easily to grab a greater insight on what is happening to your code.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.7
~> 10.0
= 3.3.0
 Project Readme

DebugTimer

This gem is to help debug slow portions of the code. When RubyProf isn't enough and you need to get deeper into the code base this is the solution. The output will look like this:

 1.8040 └── search
 1.0554    └── 1st
 0.0033        └── config
 0.0001        └── 1.1
 0.6579        └── 1.2
 0.0087            └── 1.2.1
 0.0075            └── 1.2.2
 0.6416            └── set_custom_variable
 0.3941        └── 1.3
 0.3938            └── 1.3.1
 0.0002            └── 1.3.2
 0.1487    └── 2nd
 0.5999    └── 3rd
 0.0133        └── presenter
 0.0023        └── serialize
 0.5843        └── respond_to
 0.5842            └── render
 0.1506                └── presenter.view

Installation

Add this line to your application's Gemfile:

gem 'debug_timer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install debug_timer

Configuration

You can add your logger instance if you want:

# Straight assignment
DebugTimer.logger = Logger.new('asdf')
DebugTimer.object_allocations = true

# or config assignment
DebugTimer.config do |config|
  config.logger = Logger.new('asdf')
  config.object_allocations = true
end

Usage

To use DebugTimer simply wrap the code you want to time in a block.

DebugTimer.start('search function') do
  Search.searchysearchsearch('search query')
  SomeOtherCode.DoWhatever?

  IhazFunction?
end

When you run that piece of code you will see in your log. The number on the left is the time that block of code took to run

1.8040 └── search function

Nesting

You can nest blocks within blocks.

DebugTimer.start('search function') do
  Search.searchysearchsearch('search query')

  DebugTimer.start('Some other code') do
    SomeOtherCode.DoWhatever?
  end

  IhazFunction?
end

And the output will look like:

 1.8040 └── search function
 1.0554    └── Some other code

Object Allocations

# Enable it
DebugTimer.object_allocations = true

# Time
DebugTimer.start('search function') do
  Search.todo('in here')
end

And the output will look like:

INFO -- : 0.0036 | T_OBJECT: 1 | FREE: -91  └── search function

The second pipe is the is ObjectSpace's T_OBJECT change

The third pipe is the ObjectSpace's :FREE change

Running Specs

> rake

Finished in 0.00926 seconds (files took 0.11604 seconds to load)
5 examples, 0 failures

Contributing

  1. Fork it ( https://github.com/[my-github-username]/debug_timer/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request