Guest User

Untitled

a guest
May 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. require 'ffi'
  2.  
  3. # To change this template, choose Tools | Templates
  4. # and open the template in the editor.
  5. module Process
  6. class Foreign
  7. FFI = JRuby::FFI if JRUBY_VERSION =~ /1.1.4/
  8. extend FFI::Library
  9. class Times < FFI::Struct
  10. layout \
  11. :utime => :clock_t,
  12. :stime => :clock_t,
  13. :cutime => :clock_t,
  14. :cstime => :clock_t
  15. end
  16. attach_function :times, [ :pointer ], :clock_t
  17. attach_function :sysconf, [ :int ], :long
  18. SC_CLK_TCK = 3
  19. Tms = Struct.new("Foreign::Tms", :utime, :stime, :cutime, :cstime)
  20. end
  21. def self.times
  22. hz = Foreign.sysconf(Foreign::SC_CLK_TCK).to_f
  23. t = Foreign::Times.alloc_out(false)
  24. Foreign.times(t.pointer)
  25. Foreign::Tms.new(t[:utime] / hz, t[:stime] / hz, t[:cutime] / hz, t[:cstime] / hz)
  26. end
  27.  
  28. end
  29. puts "Hello World"
  30. while true
  31. t = Process.times
  32. i = 0
  33. 100.times { f = File.open("/dev/null", File::RDONLY); f.close}
  34. 10.times { system("ls -l / > /dev/null") }
  35. puts "utime=#{t.utime} stime=#{t.stime} cutime=#{t.cutime} cstime=#{t.cstime}"
  36. sleep 1
  37. end
Add Comment
Please, Sign In to add comment