mirror of
https://github.com/lloeki/meminfo.git
synced 2025-12-06 01:54:41 +01:00
initial commit
This commit is contained in:
commit
9897ae9e22
8 changed files with 120 additions and 0 deletions
2
.rubocop.yml
Normal file
2
.rubocop.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
PerlBackrefs:
|
||||||
|
Enabled: false
|
||||||
7
.travis.yml
Normal file
7
.travis.yml
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
language: ruby
|
||||||
|
rvm:
|
||||||
|
- '2.1'
|
||||||
|
- '2.2'
|
||||||
|
script:
|
||||||
|
- bundle exec rubocop
|
||||||
|
- bundle exec ruby -e'load "lib/meminfo.rb"; Process.rss; ObjectSpace.memsize'
|
||||||
3
Gemfile
Normal file
3
Gemfile
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
|
gemspec
|
||||||
40
Gemfile.lock
Normal file
40
Gemfile.lock
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
PATH
|
||||||
|
remote: .
|
||||||
|
specs:
|
||||||
|
meminfo (0.1.0)
|
||||||
|
|
||||||
|
GEM
|
||||||
|
remote: https://rubygems.org/
|
||||||
|
specs:
|
||||||
|
ast (2.0.0)
|
||||||
|
astrolabe (1.3.1)
|
||||||
|
parser (~> 2.2)
|
||||||
|
coderay (1.1.0)
|
||||||
|
method_source (0.8.2)
|
||||||
|
parser (2.2.2.6)
|
||||||
|
ast (>= 1.1, < 3.0)
|
||||||
|
powerpack (0.1.1)
|
||||||
|
pry (0.10.1)
|
||||||
|
coderay (~> 1.1.0)
|
||||||
|
method_source (~> 0.8.1)
|
||||||
|
slop (~> 3.4)
|
||||||
|
rainbow (2.0.0)
|
||||||
|
rubocop (0.32.1)
|
||||||
|
astrolabe (~> 1.3)
|
||||||
|
parser (>= 2.2.2.5, < 3.0)
|
||||||
|
powerpack (~> 0.1)
|
||||||
|
rainbow (>= 1.99.1, < 3.0)
|
||||||
|
ruby-progressbar (~> 1.4)
|
||||||
|
ruby-progressbar (1.7.5)
|
||||||
|
slop (3.6.0)
|
||||||
|
|
||||||
|
PLATFORMS
|
||||||
|
ruby
|
||||||
|
|
||||||
|
DEPENDENCIES
|
||||||
|
meminfo!
|
||||||
|
pry
|
||||||
|
rubocop
|
||||||
|
|
||||||
|
BUNDLED WITH
|
||||||
|
1.10.6
|
||||||
20
LICENSE.md
Normal file
20
LICENSE.md
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
Copyright (c) 2014 Loic Nageleisen
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
23
lib/meminfo.rb
Normal file
23
lib/meminfo.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
require 'objspace'
|
||||||
|
require 'meminfo/ext'
|
||||||
|
|
||||||
|
# MemInfo gives a handful of methods allowing inspection of process memory use.
|
||||||
|
module MemInfo
|
||||||
|
module_function
|
||||||
|
|
||||||
|
class ProcessNotFound < StandardError; end
|
||||||
|
|
||||||
|
def rss(pid = Process.pid)
|
||||||
|
Integer(ps_rss(pid)) * 1024
|
||||||
|
rescue TypeError
|
||||||
|
raise ProcessNotFound, pid
|
||||||
|
end
|
||||||
|
|
||||||
|
def memsize
|
||||||
|
ObjectSpace.each_object.reduce(0) { |a, e| a + ObjectSpace.memsize_of(e) }
|
||||||
|
end
|
||||||
|
|
||||||
|
private def ps_rss(pid)
|
||||||
|
`ps ax -o rss,pid`.each_line.grep(/^\s*(\d+)\s+#{pid}$/) { $1 }.first
|
||||||
|
end
|
||||||
|
end
|
||||||
11
lib/meminfo/ext.rb
Normal file
11
lib/meminfo/ext.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
Process.instance_eval do
|
||||||
|
def rss(pid = Process.pid)
|
||||||
|
MemInfo.rss(pid)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ObjectSpace.instance_eval do
|
||||||
|
def memsize
|
||||||
|
MemInfo.memsize
|
||||||
|
end
|
||||||
|
end
|
||||||
14
meminfo.gemspec
Normal file
14
meminfo.gemspec
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
Gem::Specification.new do |s|
|
||||||
|
s.name = 'meminfo'
|
||||||
|
s.version = '0.1.0'
|
||||||
|
s.licenses = ['MIT']
|
||||||
|
s.summary = 'Obtain process memory information'
|
||||||
|
s.description = 'Obtain process memory information'
|
||||||
|
s.authors = ['Loic Nageleisen']
|
||||||
|
s.email = 'loic.nageleisen@gmail.com'
|
||||||
|
s.files = ['lib/meminfo.rb', 'lib/meminfo/ext.rb']
|
||||||
|
s.homepage = 'https://github.com/lloeki/meminfo'
|
||||||
|
|
||||||
|
s.add_development_dependency 'pry'
|
||||||
|
s.add_development_dependency 'rubocop'
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue