Commit f91765a8c68d6056af3e262a8e012878ccd23ab0
1 parent
ac4e274c
Exists in
master
and in
68 other branches
ENH: Implemented get physical memory amount with sigar lib
Showing
1 changed file
with
11 additions
and
25 deletions
Show diff stats
invesalius/utils.py
| ... | ... | @@ -20,6 +20,7 @@ import os |
| 20 | 20 | import platform |
| 21 | 21 | import subprocess |
| 22 | 22 | import re |
| 23 | +import sigar | |
| 23 | 24 | import sys |
| 24 | 25 | |
| 25 | 26 | if sys.platform == 'win32': |
| ... | ... | @@ -95,12 +96,11 @@ def frange(start, end=None, inc=None): |
| 95 | 96 | |
| 96 | 97 | def PredictingMemory(qtd, x, y, p): |
| 97 | 98 | m = qtd * (x * y * p) |
| 99 | + #physical_memory in Byte | |
| 100 | + physical_memory = GetPhysicalMemoryAmount() | |
| 98 | 101 | |
| 99 | 102 | if (sys.platform == 'win32'): |
| 100 | 103 | |
| 101 | - #physical_memory in Byte | |
| 102 | - physical_memory = GetWindowsInformation()[0] | |
| 103 | - | |
| 104 | 104 | if (platform.architecture()[0] == '32bit'): |
| 105 | 105 | #(314859200 = 300 MB) |
| 106 | 106 | #(26999999 = 25 MB) |
| ... | ... | @@ -133,8 +133,6 @@ def PredictingMemory(qtd, x, y, p): |
| 133 | 133 | |
| 134 | 134 | elif(sys.platform == 'linux2'): |
| 135 | 135 | |
| 136 | - physical_memory = GetLinuxInformation()[0] | |
| 137 | - | |
| 138 | 136 | if (platform.architecture()[0] == '32bit'): |
| 139 | 137 | # 839000000 = 800 MB |
| 140 | 138 | if (m <= 839000000) and (physical_memory <= 2147483648): |
| ... | ... | @@ -171,27 +169,15 @@ def BytesConvert(bytes): |
| 171 | 169 | return str(bytes) + ' bytes' |
| 172 | 170 | |
| 173 | 171 | |
| 174 | -def GetWindowsInformation(): | |
| 175 | - computer = wmi.WMI() | |
| 176 | - for i in computer.Win32_ComputerSystem (): | |
| 177 | - memory = int(i.TotalPhysicalMemory) | |
| 178 | - | |
| 179 | - information = (memory,) | |
| 180 | - | |
| 181 | - return information | |
| 182 | - | |
| 172 | +def GetPhysicalMemoryAmount(): | |
| 173 | + """ | |
| 174 | + Return physical memory amount in bytes | |
| 175 | + """ | |
| 176 | + sg = sigar.open() | |
| 177 | + mem = sg.mem() | |
| 178 | + sg.close() | |
| 179 | + return int(mem.total()) | |
| 183 | 180 | |
| 184 | -def GetDarwinInformation(): | |
| 185 | - memory = 2.0 | |
| 186 | - return (memory) | |
| 187 | 181 | |
| 188 | 182 | |
| 189 | -def GetLinuxInformation(): | |
| 190 | - #Getting memory | |
| 191 | - with open('/proc/meminfo') as f: | |
| 192 | - for i in f: | |
| 193 | - if i.startswith('MemTotal'): | |
| 194 | - # To translate from KB to Bytes | |
| 195 | - mem = int(i.split()[1]) * 1024 | |
| 196 | 183 | |
| 197 | - return (mem,) | ... | ... |