Class: Cuboid::System

Inherits:
Object show all
Includes:
Singleton
Defined in:
lib/cuboid/system.rb,
lib/cuboid/system/slots.rb,
lib/cuboid/system/platforms.rb,
lib/cuboid/system/platforms/osx.rb,
lib/cuboid/system/platforms/linux.rb,
lib/cuboid/system/platforms/windows.rb,
lib/cuboid/system/platforms/mixins/unix.rb

Defined Under Namespace

Modules: Platforms Classes: Slots

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSystem

Returns a new instance of System.



14
15
16
17
# File 'lib/cuboid/system.rb', line 14

def initialize
    @platforms = []
    @slots     = Slots.new( self )
end

Instance Attribute Details

#platformsArray<Platforms::Base> (readonly)

Returns:



9
10
11
# File 'lib/cuboid/system.rb', line 9

def platforms
  @platforms
end

#slotsSlots (readonly)

Returns:



12
13
14
# File 'lib/cuboid/system.rb', line 12

def slots
  @slots
end

Class Method Details

.method_missing(sym, *args, &block) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/cuboid/system.rb', line 103

def method_missing( sym, *args, &block )
    if instance.respond_to?( sym )
        instance.send( sym, *args, &block )
    else
        super( sym, *args, &block )
    end
end

.respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/cuboid/system.rb', line 111

def respond_to?( *args )
    super || instance.respond_to?( *args )
end

Instance Method Details

#cpu_countInteger

Returns Amount of CPU cores.

Returns:

  • (Integer)

    Amount of CPU cores.



74
75
76
# File 'lib/cuboid/system.rb', line 74

def cpu_count
    @cpu_count ||= platform.cpu_count
end

#disk_directoryString Location for temporary file storage.

Returns String Location for temporary file storage.

Returns:

  • (String Location for temporary file storage.)

    String Location for temporary file storage.



59
60
61
# File 'lib/cuboid/system.rb', line 59

def disk_directory
    platform.disk_directory
end

#disk_space_for_process(pid) ⇒ Integer

Returns Amount of disk space in bytes used by the given PID.

Parameters:

  • pid (Integer)

    Process ID.

Returns:

  • (Integer)

    Amount of disk space in bytes used by the given PID.



68
69
70
# File 'lib/cuboid/system.rb', line 68

def disk_space_for_process( pid )
    platform.disk_space_for_process( pid )
end

#disk_space_freeInteger

Returns Amount of free disk space in bytes.

Returns:

  • (Integer)

    Amount of free disk space in bytes.



53
54
55
# File 'lib/cuboid/system.rb', line 53

def disk_space_free
    platform.disk_space_free
end

#max_utilization?Bool

Returns:

  • (Bool)


32
33
34
# File 'lib/cuboid/system.rb', line 32

def max_utilization?
    utilization == 1
end

#memory_for_process_group(pgid) ⇒ Integer

Returns Amount of RAM in bytes used by the given GPID.

Parameters:

  • pgid (Integer)

    Process group ID.

Returns:

  • (Integer)

    Amount of RAM in bytes used by the given GPID.



47
48
49
# File 'lib/cuboid/system.rb', line 47

def memory_for_process_group( pgid )
    platform.memory_for_process_group( pgid )
end

#memory_freeInteger

Returns Amount of free RAM in bytes.

Returns:

  • (Integer)

    Amount of free RAM in bytes.



38
39
40
# File 'lib/cuboid/system.rb', line 38

def memory_free
    platform.memory_free
end

#platformPlatforms::Base

Returns:



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/cuboid/system.rb', line 79

def platform
    return @platform if @platform

    platforms.each do |klass|
        next if !klass.current?

        return @platform = klass.new
    end

    raise "Unsupported platform: #{RUBY_PLATFORM}"
end

#register_platform(platform) ⇒ Object



92
93
94
# File 'lib/cuboid/system.rb', line 92

def register_platform( platform )
    platforms << platform
end

#resetObject



97
98
99
100
# File 'lib/cuboid/system.rb', line 97

def reset
    @cpu_count = nil
    @platform  = nil
end

#utilizationFloat

Returns System utilization based on slots.

  • ‘0.0` => No utilization.

  • ‘1.0` => Max utilization.

Returns:

  • (Float)

    System utilization based on slots.

    • ‘0.0` => No utilization.

    • ‘1.0` => Max utilization.



24
25
26
27
28
29
# File 'lib/cuboid/system.rb', line 24

def utilization
    total_slots = System.slots.total
    return 1.0 if total_slots == 0

    System.slots.used / Float( total_slots )
end