wip
This commit is contained in:
parent
ad8228ff8f
commit
3fa631b8f5
1 changed files with 7 additions and 7 deletions
14
procio.cr
14
procio.cr
|
@ -1,24 +1,24 @@
|
||||||
dir = ENV.fetch("PROCIO_DIR", "/proc")
|
dir = ENV.fetch("PROCIO_DIR", "/proc")
|
||||||
result = {} of String => Hash(Symbol, UInt64)
|
result = {} of String => Array(UInt64)
|
||||||
time = Time.local.to_s("%s%9N")
|
time = Time.local.to_s("%s%9N")
|
||||||
|
|
||||||
Dir.entries(dir).each do |entry|
|
Dir.entries(dir).each do |entry|
|
||||||
entry =~ /^\d+$/ || next
|
entry =~ /^\d+$/ || next
|
||||||
|
|
||||||
comm = File.read("#{dir}/#{entry}/comm").chomp
|
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|
|
File.read_lines("#{dir}/#{entry}/io").each do |line|
|
||||||
if line.starts_with?("read_bytes: ")
|
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: ")
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
result.each do |comm, v|
|
result.each do |comm, (r, w)|
|
||||||
if v[:r] + v[:w] > 0
|
if r + w > 0
|
||||||
puts %(procio comm="#{comm}" read_bytes=#{v[:r]},write_bytes=#{v[:w]} #{time})
|
puts %(procio comm="#{comm}" read_bytes=#{r},write_bytes=#{w} #{time})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue