This commit is contained in:
mwiegand 2021-11-05 18:51:30 +01:00
parent ad8228ff8f
commit 3fa631b8f5

View file

@ -1,24 +1,24 @@
dir = ENV.fetch("PROCIO_DIR", "/proc")
result = {} of String => Hash(Symbol, UInt64)
result = {} of String => Array(UInt64)
time = Time.local.to_s("%s%9N")
Dir.entries(dir).each do |entry|
entry =~ /^\d+$/ || next
comm = File.read("#{dir}/#{entry}/comm").chomp
result[comm] ||= {r: 0.to_u64, w: 0.to_u64}.to_h
result[comm] ||= [0.to_u64, 0.to_u64]
File.read_lines("#{dir}/#{entry}/io").each do |line|
if line.starts_with?("read_bytes: ")
result[comm][:r] += line.split(" ").last.to_u64
result[comm][0] += line.split(" ").last.to_u64
elsif line.starts_with?("write_bytes: ")
result[comm][:w] += line.split(" ").last.to_u64
result[comm][1] += line.split(" ").last.to_u64
end
end
end
result.each do |comm, v|
if v[:r] + v[:w] > 0
puts %(procio comm="#{comm}" read_bytes=#{v[:r]},write_bytes=#{v[:w]} #{time})
result.each do |comm, (r, w)|
if r + w > 0
puts %(procio comm="#{comm}" read_bytes=#{r},write_bytes=#{w} #{time})
end
end