Skip to content

Commit

Permalink
Add test, fix two bugs in new rusage stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
Al Tobey committed Apr 12, 2012
1 parent 6e14c21 commit 58bec69
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/ffi/libc/libc.rb
Expand Up @@ -162,11 +162,11 @@ def self.each_ifaddrs
RUSAGE_CHILDREN = -1 RUSAGE_CHILDREN = -1
RUSAGE_THREAD = 1 # Linux/glibc only RUSAGE_THREAD = 1 # Linux/glibc only


attach_function :getrusage, [:int, :pointer], :int attach_function :sys_getrusage, :getrusage, [:int, :pointer], :int


def self.getrusage(who=RUSAGE_SELF) def self.getrusage(who=RUSAGE_SELF)
ru = RUsage.new ru = RUsage.new
ret = getrusage(who, ru) ret = sys_getrusage(who, ru)
raise_error(ret) unless ret == 0 raise_error(ret) unless ret == 0
ru ru
end end
Expand Down
2 changes: 1 addition & 1 deletion lib/ffi/libc/rusage.rb
Expand Up @@ -19,7 +19,7 @@ class RUsage < FFI::Struct
:ru_msgrcv, :long, :ru_msgrcv, :long,
:ru_nsignals, :long, :ru_nsignals, :long,
:ru_nvcsw, :long, :ru_nvcsw, :long,
:ru_nivcsw, :long, :ru_nivcsw, :long
end end
end end
end end
6 changes: 6 additions & 0 deletions spec/libc_spec.rb
Expand Up @@ -6,4 +6,10 @@
require 'ffi/libc/libc' require 'ffi/libc/libc'
}.should_not raise_error(FFI::NotFoundError) }.should_not raise_error(FFI::NotFoundError)
end end

it "should be able to fetch its own memory usage" do
require 'ffi/libc'
ru = FFI::LibC.getrusage
ru[:ru_maxrss].should be > 4000
end
end end

0 comments on commit 58bec69

Please sign in to comment.