mruby-resource
C Ruby
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test
.clang-format
.gitignore
.travis.yml
LICENSE
README.md
Rakefile
build_config.rb
mrbgem.rake
mruby-resource.gem

README.md

mruby-resource Build Status

mruby-resouce is the binding of setrlimit(2) and getrlimit(2), getrusage(2) system call

install by mrbgems

  • add conf.gem line to build_config.rb
MRuby::Build.new do |conf|

    # ... (snip) ...

    conf.gem :github => 'harasou/mruby-resource'
end

example

  • setrlimit

    include Resource
    lim = setrlimit(RLIMIT_CPU,5)  #=> nil
  • getrlimit

    include Resource
    lim = getrlimit(RLIMIT_STACK)                                       #=> [8388608, 1.844674407371e+19]
    lim.map{|i| i == RLIM_INFINITY ? "unlimited" : "#{i/(1024**2)}MB" } #=> ["8MB", "unlimited"]
  • getrusage(resource)

    include Resource
    ru = getrusage(RUSAGE_SELF)      #=> {:ru_utime=>0.008506, :ru_stime=>0.008506, :ru_maxrss=>2512, :ru_ixrss=>0, :ru_idrss=>0, :ru_isrss=>0, :ru_minflt=>466, :ru_majflt=>0, :ru_nswap=>0, :ru_inblock=>0, :ru_oublock=>0, :ru_msgsnd=>0, :ru_msgrcv=>0, :ru_nsignals=>0, :ru_nvcsw=>4, :ru_nivcsw=>9}
  • Resource::Rusage#ru_utime

    # TODO: add other rusage method like ru_stime
    Resource::Rusage.new(Resource::RUSAGE_SELF).ru_utime #=> 0.002736

License

under the MIT License: