Skip to content

Instantly share code, notes, and snippets.

@Wonicon
Created July 30, 2016 12:06
Show Gist options
  • Save Wonicon/dc6f228b4753b62821d92b95bf8aee5a to your computer and use it in GitHub Desktop.
Save Wonicon/dc6f228b4753b62821d92b95bf8aee5a to your computer and use it in GitHub Desktop.
gem5 dump stat
#!/usr/bin/env ruby
def StatDump(seq_num)
Dir.glob('/proc/*').each do |process|
next if not File.directory?(process)
pid = process.split('/')[2]
next if not pid =~ /\d+/
is_gem5 = false
is_user = false
name = "N/A"
File.readlines(process + '/status').each do |line|
lines = line.split()
case lines[0]
when 'Name:'
is_gem5 = lines[1].include?('gem5.')
name = lines[1]
when 'Uid:'
is_user = lines[1].to_i == Process.uid
end
end
if is_gem5 and is_user
signal = 'SIGUSR1'
puts "##{seq_num} send #{signal} to #{name} with pid #{pid}"
Process.kill(signal, pid.to_i)
end
end
end
seq_num = 0
loop do
seq_num += 1
StatDump(seq_num)
sleep 10
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment