Skip to content

Instantly share code, notes, and snippets.

@flaneur2020
Created October 23, 2012 07:57
Show Gist options
  • Select an option

  • Save flaneur2020/3937528 to your computer and use it in GitHub Desktop.

Select an option

Save flaneur2020/3937528 to your computer and use it in GitHub Desktop.
统计几个进程的vruntime
def pick_pids(tasks)
pids = tasks.map do |t|
pids = `pgrep #{t}`.scan(/\d+/).map(&:to_i)
pids.sample
end
pids
end
def vruntimes(pids)
results = []
pids.each_with_index do |pid, i|
open("/proc/#{pid}/sched") do |f|
content = f.read
results[i] = content.scan(/vruntime\D*(\d+\.\d+)/)[0][0].to_f
end
end
results
end
def min_vruntime
open('/proc/sched_debug').read.scan(/min_vruntime\D*(\d+\.\d+)/)[0][0].to_f
end
require 'json'
require 'pp'
if $0 == __FILE__
timestamp_start = Time.now.to_f
tasks = %w{chromium ksoftirqd gnome-terminal bash dbus-daemon gnome-panel ruby}
pids = pick_pids(tasks)
5000.times do
timestamp_offset = Time.now.to_f - timestamp_start
break if timestamp_offset > 30.0
puts [timestamp_offset, *vruntimes(pids), min_vruntime] * "\t"
sleep 0.005
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment