Class: Rack::Bug::MemoryPanel
- Inherits:
-
Panel
- Object
- Panel
- Rack::Bug::MemoryPanel
show all
- Defined in:
- lib/rack/bug/panels/memory_panel.rb
Instance Attribute Summary
Attributes inherited from Panel
#request
Instance Method Summary
collapse
Methods inherited from Panel
#call, #initialize, #panel_app, #render
Methods included from Render
#compile, #compile!, #compiled_source, #method_name, #method_name_without_locals, #render_template, #signed_params
Instance Method Details
#after(env, status, headers, body) ⇒ Object
40
41
42
43
|
# File 'lib/rack/bug/panels/memory_panel.rb', line 40
def after(env, status, , body)
@total_memory = get_memory_usage
@memory_increase = @total_memory - @original_memory
end
|
#before(env) ⇒ Object
36
37
38
|
# File 'lib/rack/bug/panels/memory_panel.rb', line 36
def before(env)
@original_memory = get_memory_usage
end
|
#get_memory_usage ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/rack/bug/panels/memory_panel.rb', line 11
def get_memory_usage
if defined? WIN32OLE
wmi = WIN32OLE.connect("winmgmts:root/cimv2")
mem = 0
query = "select * from Win32_Process where ProcessID = #{$$}"
wmi.ExecQuery(query).each do |wproc|
mem = wproc.WorkingSetSize
end
mem.to_i / 1000
elsif pages = ::File.read("/proc/self/statm") rescue nil
pages.to_i * statm_page_size
elsif proc_file = ::File.new("/proc/#{$$}/smaps") rescue nil
proc_file.map do |line|
size = line[/Size: *(\d+)/, 1] and size.to_i
end.compact.sum
else
`ps -o vsz= -p #{$$}`.to_i
end
end
|
#has_content? ⇒ Boolean
49
50
51
|
# File 'lib/rack/bug/panels/memory_panel.rb', line 49
def has_content?
false
end
|
#heading ⇒ Object
45
46
47
|
# File 'lib/rack/bug/panels/memory_panel.rb', line 45
def heading
"#{@memory_increase} KB Δ, #{@total_memory} KB total"
end
|
#statm_page_size ⇒ Object
try to get and cache memory page size. falls back to 4096.
32
33
34
|
# File 'lib/rack/bug/panels/memory_panel.rb', line 32
def statm_page_size
@statm_page_size ||= (`getconf PAGESIZE`.strip.to_i rescue 4096) / 1024
end
|