memory_usage 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/memory_usage.rb +14 -6
- data/lib/memory_usage_optparse.rb +6 -6
- metadata +4 -4
data/lib/memory_usage.rb
CHANGED
@@ -14,10 +14,16 @@ class MemoryUsage
|
|
14
14
|
refresh
|
15
15
|
end
|
16
16
|
|
17
|
+
#Filter process by name when printing
|
17
18
|
def filter (text="")
|
18
19
|
@options.filter = (text)
|
19
20
|
end
|
20
21
|
|
22
|
+
#Filter processes using greater than x MB
|
23
|
+
def gt( num=0 )
|
24
|
+
@options.min = num
|
25
|
+
end
|
26
|
+
|
21
27
|
|
22
28
|
#Recalculate Memory usage. stops have to call MemoryUsage.new
|
23
29
|
def refresh
|
@@ -37,9 +43,6 @@ class MemoryUsage
|
|
37
43
|
#Allow if no options set OR
|
38
44
|
#Allow if command matches filter but not with --filter (because that is this file) OR
|
39
45
|
#Filter is memory_usage we will allow it to profile itself
|
40
|
-
if (@options.filter == "") or
|
41
|
-
((command.match(/.*#{@options.filter}.*/)) and (not command.match(/.*--filter #{@options.filter}.*/) )) or
|
42
|
-
((command.match(/.*#{@options.filter}.*/)) and (@options.filter.match(/.*memory_usage.*/)))
|
43
46
|
rss = rss.to_f
|
44
47
|
@usage << {:pid=>pid, :rss=>(rss/1024), :command=>command }
|
45
48
|
@total += rss/1024
|
@@ -55,7 +58,6 @@ class MemoryUsage
|
|
55
58
|
if command.size > @max[:command]
|
56
59
|
@max[:command] = command.size
|
57
60
|
end
|
58
|
-
end
|
59
61
|
#puts pid + (" %.2f MB " % (rss/1024)) + command
|
60
62
|
|
61
63
|
end
|
@@ -68,8 +70,14 @@ class MemoryUsage
|
|
68
70
|
#Display to stdout Error report
|
69
71
|
def report
|
70
72
|
@usage.each do |x|
|
71
|
-
|
72
|
-
|
73
|
+
if (@options.filter == "") or
|
74
|
+
((x[:command].match(/.*#{@options.filter}.*/)) and (not x[:command].match(/.*--filter #{@options.filter}.*/) )) or
|
75
|
+
((x[:command].match(/.*#{@options.filter}.*/)) and (@options.filter.match(/.*memory_usage.*/)))
|
76
|
+
if x[:rss] > @options.min
|
77
|
+
#rjust string.rjust(min length)
|
78
|
+
puts x[:pid].rjust( @max[:pid] ) + (" %.2f MB " % x[:rss]).rjust( @max[:rss]+3 ) + x[:command]
|
79
|
+
end
|
80
|
+
end
|
73
81
|
end
|
74
82
|
puts "Total Memory Usage: %.2f MB" % @total
|
75
83
|
end
|
@@ -9,7 +9,7 @@ class MemoryUsageOptparse
|
|
9
9
|
# Return a structure describing the options.
|
10
10
|
#
|
11
11
|
def self.parse(args)
|
12
|
-
@VERSION = "0.0.
|
12
|
+
@VERSION = "0.0.4"
|
13
13
|
|
14
14
|
# The options specified on the command line will be collected in *options*.
|
15
15
|
# We set default values here.
|
@@ -26,22 +26,22 @@ class MemoryUsageOptparse
|
|
26
26
|
opts.separator "Common options:"
|
27
27
|
|
28
28
|
# No argument, shows at tail. This will print an options summary.
|
29
|
-
opts.
|
29
|
+
opts.on("-h", "--help", "Show this message") do
|
30
30
|
puts opts
|
31
31
|
exit
|
32
32
|
end
|
33
33
|
|
34
34
|
# Another typical switch to print the version.
|
35
|
-
opts.
|
35
|
+
opts.on("--version", "Show version") do
|
36
36
|
#puts OptionParser::Version.join('.')
|
37
37
|
puts "Version #{@VERSION}"
|
38
38
|
exit
|
39
39
|
end
|
40
40
|
|
41
41
|
# Boolean switch.
|
42
|
-
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
43
|
-
|
44
|
-
end
|
42
|
+
#opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
43
|
+
# options.verbose = v
|
44
|
+
#end
|
45
45
|
|
46
46
|
opts.separator ""
|
47
47
|
opts.separator "Specific options:"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: memory_usage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Morgan Prior
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-23 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|