Created
October 24, 2014 13:07
-
-
Save bucketsize/9681bff90e044a9f753f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# name: ptool.rb | |
# author: [email protected] | |
require 'pp' | |
USER='jb' | |
PUSER='jb' | |
PNAME='chrom' | |
TI = { cpu: 8, mem:9 } | |
def mtop tag='sys', remote='localhost' | |
cmd = "top -u #{PUSER} -d 2 -b > /tmp/top_#{tag}-#{remote}.log &" | |
if remote != 'localhost' | |
cmd = "rsh #{USER}@#{remote} "+cmd | |
end | |
puts cmd | |
system(cmd) | |
end | |
def mtop_kill tag='sys', remote='localhost' | |
cmd = "pkill -f \"top -u #{PUSER} -d 2 -b\" &" | |
if remote != 'localhost' | |
cmd = "rsh #{USER}@#{remote} "+cmd | |
end | |
system(cmd) | |
end | |
def mtop_report tag='sys', remote='localhost' | |
r, t, acpu, amem =[], 0.0, 0.0, 0.0 | |
File.open("/tmp/top_#{tag}-#{remote}.log") do |f| | |
acc=[] | |
f.each_line do |line| | |
# accum | |
if (line =~ /#{PNAME}/) | |
# puts line | |
cpu, mem = line.split(" ")[TI[:cpu]].to_f, line.split(" ")[TI[:mem]].to_f | |
acc << [cpu, mem] | |
end | |
# reduce/iter | |
if (line =~ /^top/) | |
#pp acc | |
#puts '-------------' | |
ccpu, cmem = 0.0, 0.0 | |
acc.each do |e| | |
ccpu, cmem = ccpu+e[0], cmem+e[1] | |
end | |
acc=[] | |
acpu, amem = acpu+ccpu, amem+cmem | |
r << [t += 2, ccpu, cmem] | |
end | |
end | |
end | |
# average | |
r << [acpu/r.size, amem/r.size] | |
cvs_out r | |
r | |
end | |
def cvs_out rlist | |
av = rlist.pop | |
puts "time,cpu,mem,acpu,amem" | |
r = rlist.each do |e| | |
puts "#{e[0]},#{e[1]},#{e[2]},#{av[0]},#{av[1]}" | |
end | |
end | |
self.send ARGV[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment