lib/timify.rb
def add(*label)
	return 0 if @status==:off
    if !label.empty?
      label=label[0]
    else
      label=""
    end

    time_now=Time.new
    time_spent=(time_now-@timify_prev).to_f
    @total=(time_now-@initial_time).to_f
    new_max=false
    location=caller[0].scan(/(.+):in\s/).join
    if time_spent > @max_time_spent then
      new_max = true
      @max_time_spent = time_spent
    end
    @timify[location]=@timify[location].to_f+time_spent
    @count[location]=@count[location].to_i+1
    if !label.empty?
      @timify_by_label[label]=@timify_by_label[label].to_f+time_spent
      @count[label]=@count[label].to_i+1
    end
    if !@location_prev.nil?
      @timify_by_range["#{@location_prev} - #{location}"]=@timify_by_range["#{@location_prev} - #{location}"].to_f + time_spent
      @count["#{@location_prev} - #{location}"]=@count["#{@location_prev} - #{location}"].to_i+1
    end


    if @total > 0
      percent=((@timify[location]/@total)*100).round(0)
    else
      percent=0
    end
    if time_spent>=@min_time_to_show
      if @show
        puts "<#{@name}>#{"<#{label}>" if !label.empty?}#{"(New Max)" if new_max}: #{location} (#{percent}%): #{@total.round(2)}; #{time_spent.round(2)}"
      end
    end
    @timify_prev=time_now
    @location_prev=location
    return time_spent
  end
###############################################################
# Adds a new point to count the time elapsed.
# It will count from the last 'add' call or Timify creation in case of the first 'add'.
#
#   input:
#     label: (optional) In case supplied it will summarize all the ones with the same label
#
#   output: (float)
#     time elapsed in seconds
#
#   examples:
#     t=Timify.new :example
#     t.add; run_sqls; t.add :database
#     t.add
#     #some processes
#     t.add
#     #some processes
#     send_email_alert if t.add > 0.2
#     #some processes
#     do_log(t.totals[:message]) if t.add > 0.5
###############################################################
Adds a new point to count the time elapsed.
It will count from the last 'add' call or Timify creation in case of the first 'add'.

(optional) In case supplied it will summarize all the ones with the same label

(float)
time elapsed in seconds


Adds a new point to count the time elapsed . It will count from the last ' add ' call or Timify creation in case of the first ' add ' . ( optional ) In case supplied it will summarize all the ones with the same label ( float ) time elapsed in seconds
def add(*label)
	return 0 if @status==:off
    if !label.empty?
      label=label[0]
    else
      label=""
    end
    time_now=Time.new
    time_spent=(time_now-@timify_prev).to_f
    @total=(time_now-@initial_time).to_f
    new_max=false
    location=caller[0].scan(/(.+):in\s/).join
    if time_spent > @max_time_spent then
      new_max = true
      @max_time_spent = time_spent
    end
    @timify[location]=@timify[location].to_f+time_spent
    @count[location]=@count[location].to_i+1
    if !label.empty?
      @timify_by_label[label]=@timify_by_label[label].to_f+time_spent
      @count[label]=@count[label].to_i+1
    end
    if !@location_prev.nil?
      @timify_by_range["#{@location_prev} - #{location}"]=@timify_by_range["#{@location_prev} - #{location}"].to_f + time_spent
      @count["#{@location_prev} - #{location}"]=@count["#{@location_prev} - #{location}"].to_i+1
    end
    if @total > 0
      percent=((@timify[location]/@total)*100).round(0)
    else
      percent=0
    end
    if time_spent>=@min_time_to_show
      if @show
        puts "<#{@name}>#{"<#{label}>" if !label.empty?}#{"(New Max)" if new_max}: #{location} (#{percent}%): #{@total.round(2)}; #{time_spent.round(2)}"
      end
    end
    @timify_prev=time_now
    @location_prev=location
    return time_spent
  end
def add ( * label ) return 0 if @status == :off if ! label . empty? label = label [ 0 ] else label = "" end time_now = Time . new time_spent = ( time_now - @timify_prev ) . to_f @total = ( time_now - @initial_time ) . to_f new_max = false location = caller [ 0 ] . scan ( / (.+):in \s / ) . join if time_spent > @max_time_spent then new_max = true @max_time_spent = time_spent end @timify [ location ] = @timify [ location ] . to_f + time_spent @count [ location ] = @count [ location ] . to_i + 1 if ! label . empty? @timify_by_label [ label ] = @timify_by_label [ label ] . to_f + time_spent @count [ label ] = @count [ label ] . to_i + 1 end if ! @location_prev . nil? @timify_by_range [ "#{@location_prev} - #{location}" ] = @timify_by_range [ "#{@location_prev} - #{location}" ] . to_f + time_spent @count [ "#{@location_prev} - #{location}" ] = @count [ "#{@location_prev} - #{location}" ] . to_i + 1 end if @total > 0 percent = ( ( @timify [ location ] / @total ) * 100 ) . round ( 0 ) else percent = 0 end if time_spent >= @min_time_to_show if @show puts "<#{@name}>#{"<#{label}>" if !label.empty?}#{"(New Max)" if new_max}: #{location} (#{percent}%): #{@total.round(2)}; #{time_spent.round(2)}" end end @timify_prev = time_now @location_prev = location return time_spent end
Adds a new point to count the time elapsed.
Adds a new point to count the time elapsed .
label