ghazel-rack-bug 0.3.0.1 → 0.3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rack/bug/panels/memory_panel.rb +32 -3
- data/rack-bug.gemspec +1 -1
- metadata +1 -1
@@ -1,15 +1,44 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require 'win32ole'
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
|
2
6
|
module Rack
|
3
7
|
class Bug
|
4
8
|
|
5
9
|
class MemoryPanel < Panel
|
6
10
|
|
11
|
+
def get_memory_usage
|
12
|
+
if defined? WIN32OLE
|
13
|
+
wmi = WIN32OLE.connect("winmgmts:root/cimv2")
|
14
|
+
mem = 0
|
15
|
+
query = "select * from Win32_Process where ProcessID = #{$$}"
|
16
|
+
wmi.ExecQuery(query).each do |wproc|
|
17
|
+
mem = wproc.WorkingSetSize
|
18
|
+
end
|
19
|
+
mem.to_i / 1000
|
20
|
+
elsif pages = File.read("/proc/self/statm") rescue nil
|
21
|
+
pages.to_i * statm_page_size
|
22
|
+
elsif proc_file = File.new("/proc/#{$$}/smaps") rescue nil
|
23
|
+
proc_file.map do |line|
|
24
|
+
size = line[/Size: *(\d+)/, 1] and size.to_i
|
25
|
+
end.compact.sum
|
26
|
+
else
|
27
|
+
`ps -o vsz= -p #{$$}`.to_i
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# try to get and cache memory page size. falls back to 4096.
|
32
|
+
def statm_page_size
|
33
|
+
@statm_page_size ||= (`getconf PAGESIZE`.strip.to_i rescue 4096) / 1024
|
34
|
+
end
|
35
|
+
|
7
36
|
def before(env)
|
8
|
-
@original_memory =
|
37
|
+
@original_memory = get_memory_usage
|
9
38
|
end
|
10
39
|
|
11
40
|
def after(env, status, headers, body)
|
12
|
-
@total_memory =
|
41
|
+
@total_memory = get_memory_usage
|
13
42
|
@memory_increase = @total_memory - @original_memory
|
14
43
|
end
|
15
44
|
|
data/rack-bug.gemspec
CHANGED