# module GxG::Engine

### Public Class Methods

[](the_path="") click to toggle source

    # File lib/gxg/gxg_engine.rb, line 49
    def self.[](the_path="")
      # Public interface for accessing system keyed values.
      # access cached or system-read values on /proc (sysctl-style) keys. (frankly missing from BSD, etc)
      result = nil
      reference = ::GxG::Engine::detail_mapping()
      #
      reference.to_enum.each do |mapping|
        if mapping[:key] == the_path
          @@thread_safety.synchronize {
            result = @@details.get_at_path(mapping[:path]).clone
          }
          break
        end
      end
      #      unless result
      #        # attempt to fetch the data from the system somehow.
      #        result = get_system_data(the_path)
      #        unless result.keys.size > 0
      #          result = nil
      #        end
      #      end
      #
      result
    end

abort(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 252
    def self.abort(*args)
      ::Process::abort(*args)
    end

available_event_descriptors() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 758
    def self.available_event_descriptors()
      result = 0
      current = 0
      @@thread_safety.synchronize {
        current = (::GxG::Engine::maximum_event_descriptors() - @@event_descriptors)
      }
      if current > 0
        result = current
      end
      result
    end

available_file_descriptors() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 729
    def self.available_file_descriptors()
      (::GxG::Engine::maximum_file_descriptors() - ::GxG::Engine::file_descriptors().size)
    end

daemon(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 383
    def self.daemon(*args)
      ::Process::daemon(*args)
    end

descriptor_heap_used() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 687
    def self.descriptor_heap_used()
      result = {:total => 0}
      slot_size = ::GxG::Engine::profile[:slot_size]
      file_total = 0
      GxG::Engine::file_descriptors().to_enum.each do |item|
        file_total += item.heap_used()
      end
      @@thread_safety.synchronize {
        result[:files] = file_total
        unless ::GxG::Engine::descriptor_limits()[:events] == :files
          # see available_file_descriptors : beware counting event descriptors twice (w/ file descriptors)
          # TODO: GxG::Engine::descriptor_heap_used : sync w/ more precise event socket size determination
          result[:events] = (@@event_descriptors * (slot_size + 4))
        end
      }
      result[:total] = (result[:files].to_i + result[:events].to_i)
      #
      result
    end

descriptor_limits() click to toggle source

Descriptors in general

    # File lib/gxg/gxg_engine.rb, line 683
    def self.descriptor_limits()
      {:events => @@details[:events][:maximum_event_descriptors], :files => @@details[:files][:maximum_file_descriptors]}.clone
    end

detach(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 280
    def self.detach(*args)
      ::Process::detach(*args)
    end

detail_mapping() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 45
    def self.detail_mapping()
      @@details[:key_map]
    end

determine_engine_load() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 155
    def self.determine_engine_load()
      max_event_descriptors = ::GxG::Engine::maximum_event_descriptors()
      available_events = ::GxG::Engine::available_event_descriptors()
      current_load = (((max_event_descriptors - available_events).to_f / max_event_descriptors.to_f) * 100.0)
      if (0.0..40.0).include?(current_load)
        # low
        @@thread_safety.synchronize {
          @@details[:engine_load][:high] = false
          @@details[:engine_load][:medium] = false
          @@details[:engine_load][:low] = true
          @@details[:memory_load][:percent] = current_load
        }
      else
        if (40.0..70.0).include?(current_load)
          # medium
          @@thread_safety.synchronize {
            @@details[:engine_load][:high] = false
            @@details[:engine_load][:medium] = true
            @@details[:engine_load][:low] = false
            @@details[:engine_load][:percent] = current_load
          }
        else
          if current_load > 70.0
            # high
            @@thread_safety.synchronize {
              @@details[:engine_load][:high] = true
              @@details[:engine_load][:medium] = false
              @@details[:engine_load][:low] = false
              @@details[:engine_load][:percent] = current_load
            }
          end
        end
      end
    end

determine_event_allocations() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 794
    def self.determine_event_allocations()
      #
      total = ::GxG::Engine::maximum_event_descriptors()
      dispatchers = []
      [::GxG::Events::EventDispatcher, ::GxG::Events::EventDispatcher::descendants()].flatten!.each do |the_class|
        ::ObjectSpace.each_object(the_class) do |the_dispatcher|
          if the_dispatcher.alive?()
            if the_dispatcher.running?()
              dispatchers << the_dispatcher
            end
          end
        end
      end
      # Note : a ghost-dispatcher representing all other system funcitons is added to the dispatcher count.
      maximum_events = (total.to_f / (dispatchers.size + 1).to_f).to_i
      threshold = (maximum_events.to_f * ::GxG::Engine::event_descriptors_threshold().to_f).to_i
      unless threshold > 0
        threshold = 1
      end
      @@thread_safety.synchronize {
        @@details[:events][:event_minimum_threshold] = threshold
        @@details[:events][:event_descriptors_envelope] = ((threshold)..(maximum_events))
      }
      true
    end

determine_loads() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 190
    def self.determine_loads()
      ::GxG::Engine::determine_memory_load()
      ::GxG::Engine::determine_engine_load()
    end

determine_memory_load() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 122
    def self.determine_memory_load()
      current_load = ((GxG::Engine::memory_used()[:total].to_f / GxG::SYSTEM.memory_limits()[:process].first.to_f) * 100.0)
      if (0.0..40.0).include?(current_load)
        # low
        @@thread_safety.synchronize {
          @@details[:memory_load][:high] = false
          @@details[:memory_load][:medium] = false
          @@details[:memory_load][:low] = true
          @@details[:memory_load][:percent] = current_load
        }
      else
        if (40.0..70.0).include?(current_load)
          # medium
          @@thread_safety.synchronize {
            @@details[:memory_load][:high] = false
            @@details[:memory_load][:medium] = true
            @@details[:memory_load][:low] = false
            @@details[:memory_load][:percent] = current_load
          }
        else
          if current_load > 70.0
            # high
            @@thread_safety.synchronize {
              @@details[:memory_load][:high] = true
              @@details[:memory_load][:medium] = false
              @@details[:memory_load][:low] = false
              @@details[:memory_load][:percent] = current_load
            }
          end
        end
      end
    end

egid(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 365
    def self.egid(*args)
      ::Process::egid(*args)
    end

engine_data_keys(other_platform=nil) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 520
    def self.engine_data_keys(other_platform=nil)
      #
      result = []
      data = []
      data << {:key => "files.max_descriptors", :platforms => [:linux], :operation => {:getconf => "OPEN_MAX", :format => :to_int}}
      # TODO: Research maximum socket limit under zmq:
      # See: http://news.ycombinator.com/item?id=1740823
      # Also : http://stackoverflow.com/questions/651665/how-many-socket-connections-possible
      # inventory the various platform variables that affect what threshold of max_socket_count a given system would end up with.
      # TODO: find a way to ask the OS and ZMQ for: how many descriptors available to this process, and how many in use under zmq 2.x & 3.x respectively?
      # ALSO: factor in passed preferences for these settings.
      # update available_file_descriptors when all that becomes clear and is a bit settled.
      # current_memory = ::GxG::Engine::memory_available()[:actual]
      # TODO: GxG::Engine::engine_data_keys : determine precise socket size (32bit/64bit arch) for event zmq sockets used (exact type used).
      # GxG::Engine::profile()[:bits]
      # zmq_socket_size = 16384
      #
      # event_allocation = 0.5
      #
      # TODO: GxG::Engine::engine_data_keys : tie event allocation percentage into defaults / config.file loader.
      data << {:key => "events.max_descriptors", :platforms => [:linux], :operation => {:event_allocation => 0.5, :format => :noop}}
      # See: http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-3
      # Sysctl tuning: http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-1
      # LATER: develop a series of formulas for calculating approx. how many clients one can support under one 'cluster' controller (session manager).
      data.to_enum.each do |entry|
        if entry[:platforms].include?((other_platform || ::GxG::SYSTEM.platform()[:platform]))
          result << entry
        end
      end
      #
      result
    end

engine_gear() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 195
    def self.engine_gear()
      # inverse of load
      result = :low
      @@thread_safety.synchronize {
        if @@details[:engine_load][:medium]
          result = :medium
        end
        if @@details[:engine_load][:low]
          result = :high
        end
      }
      result
    end

engine_load() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 116
    def self.engine_load()
      @@thread_safety.synchronize {
        @@details[:engine_load][:percent]
      }
    end

engine_load_high?() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 98
    def self.engine_load_high?()
      @@thread_safety.synchronize {
        @@details[:engine_load][:high]
      }
    end

engine_load_low?() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 110
    def self.engine_load_low?()
      @@thread_safety.synchronize {
        @@details[:engine_load][:low]
      }
    end

engine_load_medium?() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 104
    def self.engine_load_medium?()
      @@thread_safety.synchronize {
        @@details[:engine_load][:medium]
      }
    end

euid(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 361
    def self.euid(*args)
      ::Process::euid(*args)
    end

event_allocation_envelope() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 820
    def self.event_allocation_envelope()
      result = (20..100)
      @@thread_safety.synchronize {
        result = @@details[:events][:event_descriptors_envelope]
      }
      result
    end

event_descriptors_threshold() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 738
    def self.event_descriptors_threshold()
      # Percentage of allocation that must be available for events to be released.
      @@thread_safety.synchronize {
        @@details[:events][:event_descriptors_threshold].clone
      }
    end

event_minimum_threshold() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 745
    def self.event_minimum_threshold()
      # Percentage of allocation that must be available for events to be released.
      @@thread_safety.synchronize {
        @@details[:events][:event_minimum_threshold].clone
      }
    end

events_in_use() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 752
    def self.events_in_use()
      @@thread_safety.synchronize {
        @@event_descriptors
      }
    end

exec(*args) click to toggle source

overrides

[:exec, :fork, :spawn, :exit!, :exit, :abort, :kill, :wait, :wait2, :waitpid, :waitpid2, :waitall, :detach, :pid, :ppid, .

    # File lib/gxg/gxg_engine.rb, line 232
    def self.exec(*args)
      ::Process::exec(*args)
    end

exit(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 248
    def self.exit(*args)
      ::Process::exit(*args)
    end

exit!(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 244
    def self.exit!(*args)
      ::Process::exit!(*args)
    end

file_descriptors() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 711
    def self.file_descriptors()
      # Return an Array of currently opened file descriptors.
      # About File Descriptors: http://stackoverflow.com/questions/848717/handling-more-than-1024-file-descriptors-in-c-on-linux
      #
      result = []
      exclude_list = []
      [::IO, ::IO::descendants()].flatten!.to_enum.each do |the_class|
        unless exclude_list.include?(the_class)
          ::ObjectSpace.each_object(the_class) do |the_io|
            unless (the_io.closed? || result.include?(the_io))
              result << the_io
            end
          end
        end
      end
      result
    end

fork(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 236
    def self.fork(*args)
      ::Process::fork(*args)
    end

gear() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 223
    def self.gear()
      "#{::GxG::Engine::engine_gear().to_s}_#{::GxG::Engine::memory_gear().to_s}".to_sym
    end

get_engine_data(keys=[]) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 553
    def self.get_engine_data(keys=[])
      # Support for <SYSTEM>.refresh_data_for(a_path) (private_method)
      # some sort of sysctl + config + etc for *all* platforms:
      # "sysctl -n net.ipv4.tcp_sack" becomes: "/net/ipv4/tcp/selective_ack" (external use path)
      # @details[:memory_limits][:buffers][:socket][:ipc] becomes colllection_point = @details.at_path(":memory_limits/:buffers/:socket/:ipc");collection_point[(key)]=value
      # procs for gathering data, and formatting for use.
      # by_platform key between sysctl/config-key and @details hash path.
      # {:synonyms => ["external-path"], :sysctl => "key-string', :format => :proc-name, :location => "hash-path", :location_key => (:sym or int)}
      #
      unless keys.is_a?(::Array)
        keys = [(keys)]
      end
      result = {}
      #
      format_noop = Proc.new do |the_data|
        the_data
      end
      format_to_int = Proc.new do |the_string|
        (the_string.numeric_values()[:integer] || 0)
      end
      format_to_float = Proc.new do |the_string|
        (the_string.numeric_values()[:float] || 0.0)
      end
      format_zerofalse = Proc.new do |the_string|
        ( format_to_int.call(the_string) > 0 )
      end
      format_valid_with_initial = Proc.new do |the_string|
        raw_data = the_string.split(" ")
        {:initial => format_to_int.call(raw_data[1]), :valid => ((format_to_int.call(raw_data[0]))..(format_to_int.call(raw_data[2])))}
      end
      sysctl_read = Proc.new do |a_key,the_formatter|
        ( the_formatter.call(`sysctl -n #{a_key.to_s}`.split("\n")[0]) )
      end
      getconf_read = Proc.new do |a_key, the_formatter|
        ( the_formatter.call(`getconf #{a_key.to_s}`.split("\n")[0]) )
      end
      event_allocation = Proc.new do |the_allocation, the_formatter|
        # more precise zmq socket byte size goes here.
        zmq_socket_size = 16384
        #
        (((::GxG::Engine::memory_available()[:actual].to_f * the_allocation.to_f).to_i / zmq_socket_size) - 1)
      end
      #
      reference = ::GxG::Engine::engine_data_keys()
      #
      fetch_data = Proc.new do |the_key|
        data = nil
        reference.to_enum.each do |entry|
          if entry[:key] == the_key
            case entry[:operation][:format]
            when :noop
              the_formatter = format_noop
            when :zerofalse
              the_formatter = format_zerofalse
            when :to_int
              the_formatter = format_to_int
            when :to_float
              the_formatter = format_to_float
            when :valid_with_initial
              the_formatter = format_valid_with_initial
            else
              the_formatter = format_noop
            end
            if entry[:operation][:sysctl]
              data = sysctl_read.call(entry[:operation][:sysctl],the_formatter)
            else
              if entry[:operation][:getconf]
                data = getconf_read.call(entry[:operation][:getconf],the_formatter)
              else
                if entry[:operation][:event_allocation]
                  data = event_allocation.call(entry[:operation][:event_allocation],the_formatter)
                else
                  #
                end
                #
              end
            end
            if data
              break
            end
          end
        end
        data
      end
      #
      keys.to_enum.each do |specifier|
        if specifier.is_a?(::String)
          # if element is String: serves as result Hash key to hold result value.
          # single result with this result key
          result[(specifier)] = fetch_data.call(specifier)
        else
          if specifier.is_a?(::Hash)
            # if element is Hash: {ukey => hash_path}, {:key => <keystring>, :path => <hash_path>}
            # if hash_path supplied, read the data; set the @details hash element, and return the formatted data
            if specifier[:key]
              # {:key => <keystring>, :path => <hash_path>}
              result[(specifier[:key])] = fetch_data.call(specifier[:key])
              if specifier[:path]
                @@thread_safety.synchronize {
                  @@details.set_at_path(specifier[:path],result[(specifier[:key])])
                }
              end
            else
              # {ukey => hash_path}
              subkeys = specifier.keys
              subkeys.to_enum.each do |a_key|
                result[(a_key)] = fetch_data.call(a_key)
                @@thread_safety.synchronize {
                  @@details.set_at_path(specifier[(a_key)],result[(a_key)])
                }
              end
            end
          end
        end
      end
      #
      result
    end

getpgid(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 302
    def self.getpgid(*args)
      ::Process::getpgid(*args)
    end

getpgrp(*args) click to toggle source

:getpgrp, :setpgrp, :getpgid, :setpgid, :setsid, :getpriority, :setpriority, :getrlimit, :setrlimit, :uid, :gid, :euid, :egid,

    # File lib/gxg/gxg_engine.rb, line 294
    def self.getpgrp(*args)
      ::Process::getpgrp(*args)
    end

getpriority(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 314
    def self.getpriority(*args)
      ::Process::getpriority(*args)
    end

getrlimit(key) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 322
    def self.getrlimit(key)
      result = nil
      # FIX: GxG::Engine::getrlimit : Awaiting rbx bug #2112 fix : https://github.com/rubinius/rubinius/issues/2112
      case ::GxG::Engine::profile()[:engine]
      when :ruby
        raw_data = ::Process::getrlimit(key)
        case key
        when :AS
          if GxG::SYSTEM
            memory_limits = GxG::SYSTEM.memory_limits()
            result = [raw_data[0],(memory_limits[:process].max)]
          else
            result = raw_data
          end
        else
          result = raw_data
        end
      when :jruby
        memory_limits = GxG::SYSTEM.memory_limits()
        result = [(memory_limits[:process].first),(memory_limits[:process].last)]
      when :rbx
        memory_limits = GxG::SYSTEM.memory_limits()
        result = [(memory_limits[:process].first),(memory_limits[:process].last)]
      end
      result
    end

gid(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 357
    def self.gid(*args)
      ::Process::gid(*args)
    end

groups(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 375
    def self.groups(*args)
      ::Process::groups(*args)
    end

initgroups(*args) click to toggle source

:initgroups, :groups, :maxgroups, :daemon, :times]

    # File lib/gxg/gxg_engine.rb, line 371
    def self.initgroups(*args)
      ::Process::initgroups(*args)
    end

kill(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 256
    def self.kill(*args)
      ::Process::kill(*args)
    end

maxgroups(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 379
    def self.maxgroups(*args)
      ::Process::maxgroups(*args)
    end

maximum_event_descriptors() click to toggle source

Event Descriptors

    # File lib/gxg/gxg_engine.rb, line 734
    def self.maximum_event_descriptors()
      ::GxG::Engine::descriptor_limits()[:events]
    end

maximum_file_descriptors() click to toggle source

`File` Descriptors

    # File lib/gxg/gxg_engine.rb, line 707
    def self.maximum_file_descriptors()
        ::GxG::Engine::descriptor_limits()[:files]
    end

memory_available() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 481
    def self.memory_available()
      # Memory available for this process
      result = {:actual => 0, :virtual => 0, :total => 0}
      if ::GxG::SYSTEM
        used_memory = ::GxG::Engine::memory_used()
        free_memory = ::GxG::SYSTEM.memory()
        limits = ::GxG::Engine::getrlimit(:AS)
        latitude_total = (limits[0] - used_memory[:actual])
        if latitude_total < 0
          latitude_total = 0
        end
        # latitude_virtual = (limits[0] - used_memory[:actual])
        # latitude_actual = (limits[0] - used_memory[:virtual])
        # indicates available ram vs. paged swap first
        if free_memory[:actual][:free].to_i > limits[0]
          result[:actual] = latitude_total
          result[:virtual] = 0
        else
          result[:actual] = free_memory[:actual][:free]
          # vm calc is crack-monkey, but someplace close to reality.
          if free_memory[:virtual][:free] > ((limits[0] - result[:actual]) - used_memory[:total])
            result[:virtual] = ((limits[0] - result[:actual]) - used_memory[:total])
            unless result[:virtual] > 0
              result[:virtual] = 0
            end
          else
            if ((free_memory[:virtual][:free] - result[:actual]) - used_memory[:total]) > 0
              result[:virtual] = ((free_memory[:virtual][:free] - result[:actual]) - used_memory[:total])
            else
              result[:virtual] = 0
            end
          end
        end
        #
      end
      result[:total] = (result[:actual] + result[:virtual])
      result
    end

memory_gear() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 209
    def self.memory_gear()
      # inverse of load
      result = :low
      @@thread_safety.synchronize {
        if @@details[:memory_load][:medium]
          result = :medium
        end
        if @@details[:memory_load][:low]
          result = :high
        end
      }
      result
    end

memory_load() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 92
    def self.memory_load()
      @@thread_safety.synchronize {
        @@details[:memory_load][:percent]
      }
    end

memory_load_high?() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 74
    def self.memory_load_high?()
      @@thread_safety.synchronize {
        @@details[:memory_load][:high]
      }
    end

memory_load_low?() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 86
    def self.memory_load_low?()
      @@thread_safety.synchronize {
        @@details[:memory_load][:low]
      }
    end

memory_load_medium?() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 80
    def self.memory_load_medium?()
      @@thread_safety.synchronize {
        @@details[:memory_load][:medium]
      }
    end

memory_used() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 415
    def self.memory_used()
      # ok... why in the fly'n F isn't this provided by core ruby?!?
      # Attribution: http://stackoverflow.com/questions/7220896/get-current-ruby-process-memory-usage
      result = {:actual => 0, :virtual => 0, :total => 0}
      #
      if ::GxG::SYSTEM
        case ::GxG::SYSTEM.platform[:platform]
        when :windows
          # FORNOW: user object space enumeration
          result[:actual] = ::GxG::Engine::object_memory_used()
        when :bsd
          pid_string = "#{::Process::pid}"
          env = self.environment()
          case env[:environment]
          when :openbsd
            # See: http://modman.unixdev.net/?sektion=1&page=procmap&manpath=OpenBSD-3.6
            # use `procmap -p #{pid_string}`
            # LATER: GxG::Engine::memory_used (OpenBSD) : determine how to cull procmap text data into :actual and :virtual memory usage.
            # FORNOW: user object space enumeration
            result[:actual] = ::GxG::Engine::object_memory_used()
            #
          when :freebsd, :dragonfly, :pcbsd
            # TODO: GxG::Engine::memory_used: Test with FreeBSD, DragonFlyBSD, and PCBSD.
            raw_data = `top -d 1`
            raw_data.to_enum(:each_line).each do |the_line|
              if the_line.split(" ")[0] == pid_string
                result[:actual] = (the_line.split(" ")[6] << "B").numeric_values([:byte])[:byte].to_i
                # TODO: GxG::Engine.memory_used() (netbsd) : Find a reliable way to get result[:virtual] mem used.
                break
              end
            end
          when :netbsd
            # TODO: GxG::Engine::memory_used: Test with NetBSD.
            raw_data = `top -d 1`
            raw_data.to_enum(:each_line).each do |the_line|
              if the_line.split(" ")[0] == pid_string
                result[:actual] = (the_line.split(" ")[4] << "B").numeric_values([:byte])[:byte].to_i
                # TODO: GxG::Engine.memory_used() (netbsd) : Find a reliable way to get result[:virtual] mem used.
                break
              end
            end
          when :darwin, :macos
            # TODO: GxG::Engine::memory_used: Test with Darwin/MacOSX.
            raw_data = `top -l 1`
            raw_data.to_enum(:each_line).each do |the_line|
              if the_line.split(" ")[0] == pid_string
                result[:actual] = (the_line.split(" ")[9] << "B").numeric_values([:byte])[:byte].to_i
                # TODO: GxG::Engine.memory_used() (darwin) : Find a reliable way to get result[:virtual] mem used.
                break
              end
            end
          end
        when :linux, :solaris
          # PS is universal, but unfortunately universally incorrect, See: http://stackoverflow.com/questions/131303/linux-how-to-measure-actual-memory-usage-of-an-application-or-process
          # TODO: GxG::Engine::memory_used: create a non-toolbox version for bootstrap memory profiling.
          # TODO: GxG::Engine::memory_used: Test with Solaris.
          raw_data = `pmap -d #{::Process::pid} | tail -n 1`.split(" ")
          result[:actual] = (raw_data[3].to_s << "B").numeric_values()[:byte].to_i
          result[:virtual] = (raw_data[1].to_s << "B").numeric_values()[:byte].to_i
          # result[:shared] = (raw_data[5] << "B").numeric_values()[:byte].to_i
        end
      end
      result[:total] = (result[:actual] + result[:virtual])
      result
    end

object_memory_used() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 399
    def self.object_memory_used()
      #
      slots = 0
      other = 0
      ::ObjectSpace.each_object do |the_object|
        slots += 1
        if the_object.alive?()
          if the_object.is_a?(::String)
            other += the_object.bytesize()
          end
        end
      end
      #
      ((::GxG::Engine::profile()[:slot_size].to_i * slots) + other)
    end

pid(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 284
    def self.pid(*args)
      ::Process::pid(*args)
    end

ppid(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 288
    def self.ppid(*args)
      ::Process::ppid(*args)
    end

profile() click to toggle source

extensions

    # File lib/gxg/gxg_engine.rb, line 393
    def self.profile()
      @@thread_safety.synchronize {
        {:engine => @@details[:runtime], :version => @@details[:runtime_version], :bits => @@details[:runtime_bits], :slot_size => @@details[:runtime_rvalue_size]}.clone
      }
    end

release_event_descriptor() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 783
    def self.release_event_descriptor()
      result = false
      @@thread_safety.synchronize {
        if @@event_descriptors > 0
          @@event_descriptors -= 1
        end
      }
      result = true
      result
    end

reserve_event_descriptor() click to toggle source

    # File lib/gxg/gxg_engine.rb, line 770
    def self.reserve_event_descriptor()
      result = false
      if ::GxG::Engine::available_event_descriptors() > 0
        @@thread_safety.synchronize {
          @@event_descriptors += 1
        }
        result = true
      else
        raise Errno::ENOMEM, "maximum number of event descriptors in use (#{GxG::Engine::maximum_event_descriptors().to_s})"
      end
      result
    end

set_engine_data(keys=[]) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 672
    def self.set_engine_data(keys=[])
      # LATER: GxG::Engine::set_engine_data : when you figure out system(sudo) authentication - use this for ops that require elevated privs to set system parameters.
      # Define a set of universal_keys that affect what other keys; upon setting any one, unique-list a set of keys to read back in w/ hash paths.
      result = nil
      if nil
        ::GxG::Engine::get_engine_data(nil,nil)
        # compare hash value to the_value; return true if successful
      end
      result
    end

setpgid(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 306
    def self.setpgid(*args)
      ::Process::setpgid(*args)
    end

setpgrp(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 298
    def self.setpgrp(*args)
      ::Process::setpgrp(*args)
    end

setpriority(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 318
    def self.setpriority(*args)
      ::Process::setpriority(*args)
    end

setrlimit(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 349
    def self.setrlimit(*args)
      ::Process::setrlimit(*args)
    end

setsid(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 310
    def self.setsid(*args)
      ::Process::setsid(*args)
    end

spawn(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 240
    def self.spawn(*args)
      ::Process::spawn(*args)
    end

times(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 387
    def self.times(*args)
      ::Process::times(*args)
    end

uid(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 353
    def self.uid(*args)
      ::Process::uid(*args)
    end

wait(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 260
    def self.wait(*args)
      ::Process::wait(*args)
    end

wait2(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 264
    def self.wait2(*args)
      ::Process::wait2(*args)
    end

waitall(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 276
    def self.waitall(*args)
      ::Process::waitall(*args)
    end

waitpid(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 268
    def self.waitpid(*args)
      ::Process::waitpid(*args)
    end

waitpid2(*args) click to toggle source

    # File lib/gxg/gxg_engine.rb, line 272
    def self.waitpid2(*args)
      ::Process::waitpid2(*args)
    end