Skip to content

Commit aaed55c

Browse files
committed
Also handle no process ids...
1 parent 508ee97 commit aaed55c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/memory/leak/system.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ def self.total_memory_size
3838
def self.memory_usages(process_ids)
3939
return to_enum(__method__, process_ids) unless block_given?
4040

41-
IO.popen(["ps", "-o", "pid=,rss=", "-p", process_ids.join(",")]) do |io|
42-
io.each_line.map(&:split).each do |process_id, size|
43-
yield process_id.to_i, size.to_i * 1024
41+
if process_ids.any?
42+
IO.popen(["ps", "-o", "pid=,rss=", "-p", process_ids.join(",")]) do |io|
43+
io.each_line.map(&:split).each do |process_id, size|
44+
yield process_id.to_i, size.to_i * 1024
45+
end
4446
end
4547
end
4648
end

test/memory/leak/system.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
end
2424

2525
with ".memory_usages" do
26+
it "can determine the memory usages of no processes" do
27+
result = subject.memory_usages([])
28+
29+
expect(result).to be_a(Enumerator)
30+
expect(result.to_a).to be(:empty?)
31+
end
32+
2633
it "can determine the memory usages" do
2734
pids = 3.times.map{Process.spawn("sleep 1")}
2835

0 commit comments

Comments
 (0)