Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'ffi'
- # To change this template, choose Tools | Templates
- # and open the template in the editor.
- module Process
- class Foreign
- FFI = JRuby::FFI if JRUBY_VERSION =~ /1.1.4/
- extend FFI::Library
- class Times < FFI::Struct
- layout \
- :utime => :clock_t,
- :stime => :clock_t,
- :cutime => :clock_t,
- :cstime => :clock_t
- end
- attach_function :times, [ :pointer ], :clock_t
- attach_function :sysconf, [ :int ], :long
- SC_CLK_TCK = 3
- Tms = Struct.new("Foreign::Tms", :utime, :stime, :cutime, :cstime)
- end
- def self.times
- hz = Foreign.sysconf(Foreign::SC_CLK_TCK).to_f
- t = Foreign::Times.alloc_out(false)
- Foreign.times(t.pointer)
- Foreign::Tms.new(t[:utime] / hz, t[:stime] / hz, t[:cutime] / hz, t[:cstime] / hz)
- end
- end
- puts "Hello World"
- while true
- t = Process.times
- i = 0
- 100.times { f = File.open("/dev/null", File::RDONLY); f.close}
- 10.times { system("ls -l / > /dev/null") }
- puts "utime=#{t.utime} stime=#{t.stime} cutime=#{t.cutime} cstime=#{t.cstime}"
- sleep 1
- end
Add Comment
Please, Sign In to add comment