module Ragweed; end module Ragweed::Wraposx::ThreadState #Thread run states RUNNING = 1 #/* thread is running normally */ STOPPED = 2 #/* thread is stopped */ WAITING = 3 #/* thread is waiting normally */ UNINTERRUPTIBLE = 4 #/* thread is in an uninterruptible wait */ HALTED = 5 #/* thread is halted at a clean point */ end module Ragweed::Wraposx::TFlags #Thread flags (flags field). SWAPPED = 0x1 #/* thread is swapped out */ IDLE = 0x2 #/* thread is an idle thread */ end class Ragweed::Wraposx::ThreadInfo include Ragweed attr_accessor :user_time attr_accessor :system_time (FIELDS = [ [:user_time_s, "I"], [:user_time_us, "I"], [:system_time_s, "I"], [:system_time_us, "I"], [:cpu_usage, "I"], [:policy, "I"], [:run_state, "I"], [:flags, "I"], [:suspend_count, "I"], [:sleep_time, "I"]]).each {|x| attr_accessor x[0]} def initialize(str=nil) refresh(str) if str end #(re)loads the data from str def refresh(str) if str and not str.empty? str.unpack(FIELDS.map {|x| x[1]}.join("")).each_with_index do |val, i| raise "i is nil" if i.nil? instance_variable_set "@#{ FIELDS[i][0] }".intern, val end end @user_time = @user_time_s + (@user_time_us/1000000.0) @system_time = @system_time_s + (@system_time_us/1000000.0) end def to_s FIELDS.map {|f| send(f[0])}.pack(FIELDS.map {|x| x[1]}.join("")) end def self.get(t) self.new(Wraposx::thread_info_raw(t)) end def get(t) refresh(Wraposx::thread_info_raw(t)) end def inspect body = lambda do FIELDS.map do |f| "#{f[0]}=#{send(f[0]).to_s}" end.join(", ") end "#" end def dump(&block) maybe_hex = lambda {|a| begin; "\n" + (" " * 9) + block.call(a, 16).hexdump(true)[10..-2]; rescue; ""; end } maybe_dis = lambda {|a| begin; "\n" + block.call(a, 16).distorm.map {|i| " " + i.mnem}.join("\n"); rescue; ""; end } string =<