From e2aac0d7ea5ddec0458058717ef3017f72d98363 Mon Sep 17 00:00:00 2001 From: mwiegand Date: Wed, 17 Nov 2021 16:20:25 +0100 Subject: [PATCH] wip --- procio.cr | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/procio.cr b/procio.cr index 5d65712..6473a44 100644 --- a/procio.cr +++ b/procio.cr @@ -5,15 +5,18 @@ 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] ||= [0.to_u64, 0.to_u64] + begin + comm = File.read("#{dir}/#{entry}/comm").chomp + 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][0] += line.split(" ").last.to_u64 - elsif line.starts_with?("write_bytes: ") - result[comm][1] += line.split(" ").last.to_u64 + File.read_lines("#{dir}/#{entry}/io").each do |line| + if line.starts_with?("read_bytes: ") + result[comm][0] += line.split(" ").last.to_u64 + elsif line.starts_with?("write_bytes: ") + result[comm][1] += line.split(" ").last.to_u64 + end end + rescue File::NotFoundError end end