[Tutor] Fetch CPU and GPU values from python
Nandish N
nandishn17 at gmail.com
Thu Jan 16 08:00:33 EST 2020
Hi,
I want to fetch system cpu,process cpu and gpu values from task manager, on
exploring I got to know about psutil.cpu_percent() and GPUtil and here is
the code used:
import os
import time
import psutil
from GPUtil import GPUtil
string=xyz
timer=124
listOfProcessNames=[]
pInfoDict={}
while timer != 1:
for x in range(3):
print(psutil.cpu_percent(1))
#print("GPU:",GPUtil.showUtilization())
psutil.process_iter()
for proc in psutil.process_iter():
processName = proc.name()
processID = proc.pid
if processName.find("xyz") != -1:
#print(proc)
print(processName)
print(processID)
cpu=proc.cpu_percent()
print(cpu)
pInfoDict = proc.as_dict(attrs=('name', 'cpu_percent'))
# Append dict of process detail in list
listOfProcessNames.append(pInfoDict)
#print(listOfProcessNames)
os.system('wmic cpu get loadpercentage')
timer=timer-1
time.sleep(5)
What is the output of psutil.cpu_percent() is it system cpu values?
And does proc.cpu_percent() give process cpu value?
Is there any function to get values for Data-In/Data-Out, Memeory info?
How to call shell script from python?
I kindly request you to help me in getting the above values mentioned,
Thanks in advance.
Regards,
Nandish.
More information about the Tutor
mailing list