Class: MwrapRack::Each
- Inherits:
-
Struct
- Object
- Struct
- MwrapRack::Each
- 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
-
#min ⇒ Object
Returns the value of attribute min.
-
#script_name ⇒ Object
Returns the value of attribute script_name.
-
#sort ⇒ Object
Returns the value of attribute sort.
Instance Method Summary collapse
Methods included from HtmlResponse
Instance Attribute Details
#min ⇒ Object
Returns the value of attribute min
36 37 38 |
# File 'lib/mwrap_rack.rb', line 36 def min @min end |
#script_name ⇒ Object
Returns the value of attribute script_name
36 37 38 |
# File 'lib/mwrap_rack.rb', line 36 def script_name @script_name end |
#sort ⇒ Object
Returns the value of attribute sort
36 37 38 |
# File 'lib/mwrap_rack.rb', line 36 def sort @sort end |
Instance Method Details
#each ⇒ Object
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 74 75 76 |
# File 'lib/mwrap_rack.rb', line 41 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 |