ghazel-rack-bug 0.3.0.1 → 0.3.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 = `ps -o rss= -p #{$$}`.to_i
37
+ @original_memory = get_memory_usage
9
38
  end
10
39
 
11
40
  def after(env, status, headers, body)
12
- @total_memory = `ps -o rss= -p #{$$}`.to_i
41
+ @total_memory = get_memory_usage
13
42
  @memory_increase = @total_memory - @original_memory
14
43
  end
15
44
 
data/rack-bug.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ghazel-rack-bug}
5
- s.version = "0.3.0.1"
5
+ s.version = "0.3.0.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Bryan Helmkamp"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghazel-rack-bug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.1
4
+ version: 0.3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Helmkamp