oink 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/oink/base.rb CHANGED
@@ -2,7 +2,7 @@ module Oink
2
2
 
3
3
  class Base
4
4
 
5
- VERSION = '0.1.1'
5
+ VERSION = '0.1.2'
6
6
  FORMATS = %w[verbose short-summary summary]
7
7
  FORMAT_ALIASES = { "v" => "verbose", "ss" => "short-summary", "s" => "summary" }
8
8
  HODEL_LOG_FORMAT_REGEX = /^(\w+ \d{2} \d{2}:\d{2}:\d{2})/
@@ -21,6 +21,8 @@ module Oink
21
21
  mem = wproc.WorkingSetSize
22
22
  end
23
23
  mem.to_i / 1000
24
+ elsif pages = File.read("/proc/self/statm") rescue nil
25
+ pages.to_i * statm_page_size
24
26
  elsif proc_file = File.new("/proc/#{$$}/smaps") rescue nil
25
27
  proc_file.map do |line|
26
28
  size = line[/Size: *(\d+)/, 1] and size.to_i
@@ -30,6 +32,11 @@ module Oink
30
32
  end
31
33
  end
32
34
 
35
+ # try to get and cache memory page size. falls back to 4096.
36
+ def statm_page_size
37
+ @statm_page_size ||= (`getconf PAGESIZE`.strip.to_i rescue 4096) / 1024
38
+ end
39
+
33
40
  def log_memory_usage
34
41
  if logger
35
42
  memory_usage = get_memory_usage
@@ -43,7 +43,18 @@ end
43
43
  describe Oink::MemoryUsageLogger do
44
44
  unless defined? WIN32OLE
45
45
  describe "get_memory_usage" do
46
- it "should work on linux" do
46
+ it "should work on linux with statm" do
47
+ pages = 6271
48
+ statm_file = "#{pages} 1157 411 1 0 763 0\n"
49
+
50
+ File.should_receive(:read).with("/proc/self/statm").and_return(statm_file)
51
+ controller = ApplicationController.new
52
+ controller.should_receive(:`).with('getconf PAGESIZE').and_return("4096\n")
53
+ controller.index
54
+ controller.logger.log.should == [[:info, "Memory usage: #{pages * 4} | PID: #{$$}"]]
55
+ end
56
+
57
+ it "should work on linux with smaps" do
47
58
  proc_file = <<-STR
48
59
  Header
49
60
 
@@ -56,6 +67,7 @@ describe Oink::MemoryUsageLogger do
56
67
 
57
68
  STR
58
69
 
70
+ File.stub!(:read).and_raise(Errno::ENOENT.new("No such file or directory"))
59
71
  File.should_receive(:new).with("/proc/#{$$}/smaps").and_return(proc_file)
60
72
  controller = ApplicationController.new
61
73
  controller.index
@@ -63,6 +75,7 @@ describe Oink::MemoryUsageLogger do
63
75
  end
64
76
 
65
77
  it "should work on non-linux" do
78
+ File.stub!(:read).and_raise(Errno::ENOENT.new("No such file or directory"))
66
79
  File.stub!(:new).and_raise(Errno::ENOENT.new("No such file or directory"))
67
80
  controller = ApplicationController.new
68
81
  controller.index
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oink
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Noah Davis
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-30 00:00:00 -04:00
18
+ date: 2010-10-08 00:00:00 -04:00
19
19
  default_executable: oink
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency