Guest User

Untitled

a guest
Jan 19th, 2012
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. text = `ps -eo comm,rss`
  2. #split the input to two colums
  3. table=text.lines.collect {|l|
  4.         [l.split[0..-2].join ,l.split[-1].to_i/1024]}
  5.  
  6. #summing rows with same progname
  7. sum=Hash.new(0)
  8. table.each {|i| sum[i[0]]+=i[1]}
  9.  
  10. # sort decrasing on second field (memory use)
  11. table=sum.to_a.sort{|x,y| y[1]<=>x[1]}
  12.  
  13. #format and print output
  14. puts table[0..4].inject("Memory usage (MB):\n"){|res,i|
  15.          res+= i[0]+" ("+i[1].to_s+") "
  16. }.chop
Advertisement
Add Comment
Please, Sign In to add comment