Class: Cuboid::System::Platforms::Windows

Inherits:
Base show all
Defined in:
lib/cuboid/system/platforms/windows.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#_exec, #cpu_count, #disk_directory, #disk_space_for_process, inherited

Class Method Details

.current?Boolean

Returns:

  • (Boolean)


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

def current?
    Cuboid.windows?
end

Instance Method Details

#disk_space_freeInteger

Returns Amount of free disk in bytes.

Returns:

  • (Integer)

    Amount of free disk in bytes.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cuboid/system/platforms/windows.rb', line 54

def disk_space_free
    device_id = disk_directory.split( '/' ).first

    drives = wmi.ExecQuery(
        "select FreeSpace from win32_LogicalDisk where DeviceID='#{device_id}'"
    )

    space = nil
    drives.each do |drive|
        space = drive.freeSpace.to_i
        drive.ole_free
    end
    drives.ole_free

    space
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.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cuboid/system/platforms/windows.rb', line 36

def memory_for_process_group( pgid )
    processes = wmi.ExecQuery(
        "select PrivatePageCount from win32_process where ProcessID='#{pgid}' or ParentProcessID='#{pgid}'"
    )

    memory = 0
    processes.each do |process|
        # Not actually pages but bytes, no idea why.
        memory += process.privatePageCount.to_i
        process.ole_free
    end
    processes.ole_free

    memory
end

#memory_freeInteger

Returns Amount of free RAM in bytes.

Returns:

  • (Integer)

    Amount of free RAM in bytes.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cuboid/system/platforms/windows.rb', line 16

def memory_free
    result = wmi.ExecQuery(
        'select AvailableBytes from Win32_PerfFormattedData_PerfOS_Memory'
    )

    memory = nil
    result.each do |e|
        memory = e.availableBytes.to_i
        e.ole_free
    end
    result.ole_free

    memory
end