Class: MwrapRack::Each

Inherits:
Struct
  • Object
show all
Includes:
HtmlResponse
Defined in:
lib/mwrap_rack.rb

Overview

:nodoc:

Constant Summary collapse

HEADER =
'<tr><th>' + %w(total allocations frees mean_life max_life
location).join('</th><th>') + '</th></tr>'
FIELDS =
%w(total allocations frees mean_life max_life location)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HtmlResponse

#response

Instance Attribute Details

#minObject

Returns the value of attribute min

Returns:

  • (Object)

    the current value of min



33
34
35
# File 'lib/mwrap_rack.rb', line 33

def min
  @min
end

#script_nameObject

Returns the value of attribute script_name

Returns:

  • (Object)

    the current value of script_name



33
34
35
# File 'lib/mwrap_rack.rb', line 33

def script_name
  @script_name
end

#sortObject

Returns the value of attribute sort

Returns:

  • (Object)

    the current value of sort



33
34
35
# File 'lib/mwrap_rack.rb', line 33

def sort
  @sort
end

Instance Method Details

#eachObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/mwrap_rack.rb', line 38

def each
  Mwrap.quiet do
    t = -"Mwrap.each(#{min})"
    sn = script_name
    all = []
    f = FIELDS.dup
    sc = FIELDS.index(sort || 'total') || 0
    f[sc] = -"<b>#{f[sc]}</b>"
    f.map! do |hdr|
      if hdr.start_with?('<b>')
        hdr
      else
        -%Q(<a\nhref="#{sn}/each/#{min}?sort=#{hdr}">#{hdr}</a>)
      end
    end
    Mwrap.each(min) do |loc, total, allocations, frees, age_sum, max_life|
      mean_life = frees == 0 ? Float::INFINITY : age_sum/frees.to_f
      all << [total,allocations,frees,mean_life,max_life,loc]
    end
    all.sort_by! { |cols| -cols[sc] }

    yield(-"<html><head><title>#{t}</title></head>" \
           "<body><h1>#{t}</h1>\n" \
           "<h2>Current generation: #{GC.count}</h2>\n<table>\n" \
           "<tr><th>#{f.join('</th><th>')}</th></tr>\n")
    all.each do |cols|
      loc = cols.pop
      cols[3] = sprintf('%0.3f', cols[3]) # mean_life
      href = -(+"#{sn}/at/#{CGI.escape(loc)}").encode!(xml: :attr)
      yield(%Q(<tr><td>#{cols.join('</td><td>')}<td><a\nhref=#{
              href}>#{-loc.encode(xml: :text)}</a></td></tr>\n))
      cols.clear
    end.clear
    yield "</table></body></html>\n"
  end
end