TIME NOW
World current time now,
CALENDAR
Calendar monthly, yearly
login CONVERT LENGTH
login CONVERT TEMPERATURE
login DICTIONARIES, LISTS
login SCIENCE EDUCATION RELIGION
login WORK CALCULATOR
login CALCULATE LIFE

Python 3 programming language, learn python, tutorial

Previous articlePage bottomNext article  ALL TOPICS

Python 3. Monitoring. RAM Memory

 1. RAM monitoring
# scripts\pip install memory_profiler
# scripts\pip install psutil
# scripts\pip install profilehooks
# python -m memory_profiler 1.py
 
import psutil
import sys
 
def RAM():
list = str(psutil.virtual_memory()).split()
print (list)
return int(str(list[3]).strip(",").split("=")[1])
 
begin = RAM()
 
i = 0
 
# only for functions and "python -m memory_profiler 1.py"
#@profile
def memory():
    global variable; global i
    i=i+1
    mem = sys.getsizeof(variable)
    print ( str(i) + ' Var: ' + str(variable) + ', Memory '+str(mem))
    
 
 
# 1
variable = ""; memory();
 
# 2
variable = ""; memory();
 
# 3
variable = variable + "1";   memory();
 
# 4
variable = list (variable);  memory();
 
# 5
variable = str  (variable);  memory();
 
# 6
variable = list (variable);  memory();
 
# 7
variable = str  (variable);  memory();
 
# 8
del variable; variable = ""; memory();
 
end = RAM(); print ("USEAGE: " + str (round( (end - begin) /1024)) + " kB")
# 8
del variable; variable = ""; memory();
 
end = RAM(); print ("USEAGE: " + str (round( (end - begin) /1024)) + " kB")

2. RAM monitoring:
# scripts\pip install memory_profiler
# scripts\pip install psutil
# scripts\pip install profilehooks
# python -m memory_profiler 1.py
 
import psutil
import sys
 
 
def RAM():
list = str(psutil.virtual_memory()).split()
return int(str(list[3]).strip(",").split("=")[1])
 
begin = RAM()
 
i = 0
 
# only for functions and "python -m memory_profiler 2.py"
#@profile
def memory():
    global variable; global i
    i=i+1
    mem = sys.getsizeof(variable)
    print ( str(i) + ' Var: ' + str(variable) + ', Memory '+str(mem))
 
# 1
variable = ""; memory();
 
# 2
variable = ""; memory();
 
# 3
variable = variable + "1";   memory();
 
# 4
variable = variable.split();  memory();
 
# 5
variable = variable[0];  memory();
 
# 6
variable = variable.split();  memory();
 
# 7
variable = variable[0];  memory();
 
end = RAM(); print ("USEAGE: " + str (round( (end - begin) /1024)) + " kB")
# 8
del variable; variable = ""; memory();
 
end = RAM(); print ("USEAGE: " + str (round( (end - begin) /1024)) + " kB")

3. Windows OS parameters:
# scripts\pip install profilehooks
# scripts\pip install pypiwin32
import wmi

computer = wmi.WMI()
computer_info = computer.Win32_ComputerSystem()[0]
os_info = computer.Win32_OperatingSystem()[0]
proc_info = computer.Win32_Processor()[0]
gpu_info = computer.Win32_VideoController()[0]

os_name = os_info.Name.encode('utf-8').split(b'|')[0]
os_version = ' '.join([os_info.Version, os_info.BuildNumber])
system_ram = float(os_info.TotalVisibleMemorySize) / 1048576  # KB to GB

print('OS Name: {0}'.format(os_name))
print('OS Version: {0}'.format(os_version))
print('CPU: {0}'.format(proc_info.Name))
print('RAM: {0} GB'.format(system_ram))
print('Graphics Card: {0}'.format(gpu_info.Name))

Linux OS:
import os 

# RAM information
# Output is in kb, here I convert it in Mb for readability
RAM_stats = os.getRAMinfo()
RAM_total = round(int(RAM_stats[0]) / 1000,1)
RAM_used = round(int(RAM_stats[1]) / 1000,1)
RAM_free = round(int(RAM_stats[2]) / 1000,1)

--
  
Previous articlePage topNext article  ALL TOPICS



 Use username: Guest, Anonymous, Programmer






QUOTES:
Oh, never mind the fashion. When one has a style of one's own, it is always twenty times better.
Margaret Oliphant
If we want a love message to be heard, it has to be sent out. To keep a lamp burning, we have to keep putting oil in it.
Mother Theresa
I like to listen. I have learned a great deal from listening carefully. Most people never listen.
Ernest Hemingway