Class: LiquidProf::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/liquidprof/reporter.rb

Direct Known Subclasses

AsciiReporter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prof) ⇒ Reporter

Returns a new instance of Reporter.



5
6
7
# File 'lib/liquidprof/reporter.rb', line 5

def initialize(prof)
  @prof = prof
end

Instance Attribute Details

#profObject (readonly)

Returns the value of attribute prof.



3
4
5
# File 'lib/liquidprof/reporter.rb', line 3

def prof
  @prof
end

Instance Method Details

#format_bytes(bytes) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/liquidprof/reporter.rb', line 18

def format_bytes(bytes)
  units = ["B", "K", "M"]

  if bytes.to_i < 1024
    exponent = 0
  else
    exponent = (Math.log(bytes)/Math.log(1024)).to_i
    bytes /= 1024 ** [exponent, units.size].min
  end

  if exponent == 0
    "#{bytes.to_i}#{units[exponent]}"
  else
    "%.2f%s" % [ bytes, units[exponent] ]
  end
end

#summarize_stats(template) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/liquidprof/reporter.rb', line 9

def summarize_stats(template)
  Profiler.dfs(template.root) do |node, pos|
    next unless pos == :pre
    next unless prof.stats.key?(node)
    node_summarize_stats(prof.stats[node])
  end
  self
end