memory_usage 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/memory_usage +73 -0
- data.tar.gz.sig +0 -0
- metadata +93 -0
- metadata.gz.sig +3 -0
data/memory_usage
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#Class which has function for gathering memory stats.
|
4
|
+
# Should work on unix/linux and OS X
|
5
|
+
# Example usage at the bottom
|
6
|
+
class MemoryUsage
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
refresh
|
10
|
+
end
|
11
|
+
|
12
|
+
#Recalculate Memory usage. stops have to call MemoryUsage.new
|
13
|
+
def refresh
|
14
|
+
#Based on: http://gist.github.com/290988
|
15
|
+
@total = 0.0
|
16
|
+
@usage = Array.new
|
17
|
+
@max = {:pid=>0, :rss=>0, :command=>0}
|
18
|
+
|
19
|
+
`ps -u $USER -o pid,rss,command`.split("\n").each do |p|
|
20
|
+
p.strip!
|
21
|
+
if p.match(/^\d/)
|
22
|
+
p =~ /(\d+)\s+(\d+)\s+(.+)/
|
23
|
+
|
24
|
+
pid, rss, command = [$1, $2, $3]
|
25
|
+
rss = rss.to_f
|
26
|
+
@usage << {:pid=>pid, :rss=>(rss/1024), :command=>command }
|
27
|
+
@total += rss/1024
|
28
|
+
|
29
|
+
if pid.to_s.size > @max[:pid]
|
30
|
+
@max[:pid] = pid.to_s.size
|
31
|
+
end
|
32
|
+
|
33
|
+
if rss.to_s.size > @max[:rss]
|
34
|
+
@max[:rss] = rss.to_s.size
|
35
|
+
end
|
36
|
+
|
37
|
+
if command.size > @max[:command]
|
38
|
+
@max[:command] = command.size
|
39
|
+
end
|
40
|
+
#puts pid + (" %.2f MB " % (rss/1024)) + command
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
@usage = @usage.sort_by { |process| process[:rss] }
|
45
|
+
#puts "Your total usage: %.2f MB" % (total / 1024)
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
#Display to stdout Error report
|
50
|
+
def report
|
51
|
+
@usage.each do |x|
|
52
|
+
#rjust string.rjust(min length)
|
53
|
+
puts x[:pid].rjust( @max[:pid] ) + (" %.2f MB " % x[:rss]).rjust( @max[:rss]+3 ) + x[:command]
|
54
|
+
end
|
55
|
+
puts "Total Memory Usage: %.2f MB" % @total
|
56
|
+
end
|
57
|
+
|
58
|
+
#Return total memory as a String
|
59
|
+
def total
|
60
|
+
"%.2f" % @total
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
#Run example only if called directly
|
65
|
+
#ie not if included/required for class
|
66
|
+
if $0 == __FILE__
|
67
|
+
a = MemoryUsage.new
|
68
|
+
a.report
|
69
|
+
|
70
|
+
#a.refresh
|
71
|
+
#a.report
|
72
|
+
#puts a.total
|
73
|
+
end
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: memory_usage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Morgan Prior
|
14
|
+
autorequire:
|
15
|
+
bindir: ./
|
16
|
+
cert_chain:
|
17
|
+
- |
|
18
|
+
-----BEGIN CERTIFICATE-----
|
19
|
+
MIIDYDCCAkigAwIBAgIBADANBgkqhkiG9w0BAQUFADBWMQ8wDQYDVQQDDAZtb3Jn
|
20
|
+
YW4xGzAZBgoJkiaJk/IsZAEZFgthbWFyYXMtdGVjaDESMBAGCgmSJomT8ixkARkW
|
21
|
+
AmNvMRIwEAYKCZImiZPyLGQBGRYCdWswHhcNMTAwNjE3MjE1NDA5WhcNMTEwNjE3
|
22
|
+
MjE1NDA5WjBWMQ8wDQYDVQQDDAZtb3JnYW4xGzAZBgoJkiaJk/IsZAEZFgthbWFy
|
23
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
+
date: 2010-06-17 00:00:00 +01:00
|
41
|
+
default_executable:
|
42
|
+
dependencies: []
|
43
|
+
|
44
|
+
description: |-
|
45
|
+
Reports memory used by all current user processes
|
46
|
+
This relies on command line tools available in unix, so will not
|
47
|
+
work on windows but all unix, linux and Mac OS X machines should be fine.
|
48
|
+
This can be executed stand alone or required and used as an object type.
|
49
|
+
email: memory_usage_gem@amaras-tech.co.uk
|
50
|
+
executables:
|
51
|
+
- memory_usage
|
52
|
+
extensions: []
|
53
|
+
|
54
|
+
extra_rdoc_files: []
|
55
|
+
|
56
|
+
files:
|
57
|
+
- ./memory_usage
|
58
|
+
has_rdoc: true
|
59
|
+
homepage:
|
60
|
+
licenses: []
|
61
|
+
|
62
|
+
post_install_message: To use 'memory_usage' as a standalone application your gems folder must be on your path
|
63
|
+
rdoc_options: []
|
64
|
+
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.7
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Report memory usage on Mac OS X, Linux and Unix.
|
92
|
+
test_files: []
|
93
|
+
|
metadata.gz.sig
ADDED