From 3fa631b8f5ffa39426b72139dbd3fc9bbd22ccf1 Mon Sep 17 00:00:00 2001 From: mwiegand Date: Fri, 5 Nov 2021 18:51:30 +0100 Subject: [PATCH] wip --- procio.cr | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/procio.cr b/procio.cr index ba74b0a..4cabf7d 100644 --- a/procio.cr +++ b/procio.cr @@ -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