Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Storming #61

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
133 changes: 113 additions & 20 deletions ptop/interfaces/GUI.py

Large diffs are not rendered by default.

34 changes: 33 additions & 1 deletion ptop/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,34 @@ def main():
For example 500
''')

parser.add_argument('-gsrt',
dest='gsrt',
action='store',
type=float,
required=False,
help=
'''
GPU sensor response time;
Input sensor
update interval in
milli seconds less than 1000.
For example 500
''')

parser.add_argument('-tsrt',
dest='tsrt',
action='store',
type=float,
required=False,
help=
'''
Temperature sensor response time;
Input sensor
update interval in
milli seconds less than 1000.
For example 500
''')

parser.add_argument('-v',
action='version',
version='ptop {}'.format(__version__))
Expand All @@ -175,9 +203,13 @@ def main():
psrt = (1000 if psrt>1000 else psrt)
ssrt = (results.ssrt if results.ssrt else 1000)
ssrt = (1000 if ssrt>1000 else ssrt)
gsrt = (results.gsrt if results.gsrt else 1000)
gsrt = (1000 if gsrt>1000 else gsrt)
tsrt = (results.tsrt if results.tsrt else 1000)
tsrt = (1000 if tsrt>1000 else tsrt)
nsrt = 1000 # network sensor rate is always 1 second

srts = [csrt, dsrt, msrt, nsrt, psrt, ssrt]
srts = [csrt, dsrt, msrt, nsrt, psrt, ssrt, gsrt, tsrt]
sensor_refresh_rates = {SENSORS_LIST[i]: srts[i] for i in range(len(SENSORS_LIST))}

# try to update ptop
Expand Down
4 changes: 4 additions & 0 deletions ptop/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from .process_sensor import process_sensor
from .system_sensor import system_sensor
from .network_sensor import network_sensor
from .gpu_sensor import gpu_sensor
from .temperature_sensor import temperature_sensor

# Sensors List
SENSORS_LIST = [
Expand All @@ -17,4 +19,6 @@
network_sensor,
process_sensor,
system_sensor,
gpu_sensor,
temperature_sensor,
]
2 changes: 1 addition & 1 deletion ptop/plugins/cpu_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self,**kwargs):
# there can be many text (key,value) pairs to display corresponding to each key
self.currentValue['text'] = {}
# there will be one averaged value
self.currentValue['graph'] = {'percentage' : ''}
self.currentValue['graph'] = {'percentage' : 0}

# overriding the update method
def update(self):
Expand Down
39 changes: 39 additions & 0 deletions ptop/plugins/gpu_sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#-*- coding: utf-8 -*-
'''
GPU sensor plugin

Generates the GPU usage stats
'''
from ptop.core import Plugin
import GPUtil,subprocess

class GPUSensor(Plugin):
def __init__(self,**kwargs):
super(GPUSensor,self).__init__(**kwargs)
# there will be two parts of the returned value, one will be text and other graph
# there can be many text (key,value) pairs to display corresponding to each key
self.currentValue['text'] = {'number_of_gpus' : len(GPUtil.getGPUs()), 'temperature' : ''}
# there will be one averaged value
self.currentValue['graph'] = {'percentage' : 0}

# overriding the update method
def update(self):
# gpu usage
gpus = GPUtil.getGPUs()
num_gpus = len(gpus)
gpu_usage = [x.load for x in gpus]
self.currentValue['text']['number_of_gpus'] = num_gpus
for ctr in range(num_gpus):
self.currentValue['text']['gpu{0}'.format(ctr+1)] = gpu_usage[ctr]
#average gpu usage
if(num_gpus!=0):
self.currentValue['graph']['percentage'] = (sum(gpu_usage)*100)/num_gpus
proc = subprocess.Popen('nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader',
stdout=subprocess.PIPE,stderr=subprocess.STDOUT,shell=True)
output,error = proc.communicate()
temp = output.split()[0]
self.currentValue['text']['temperature']=temp+'°C'
else:
self.currentValue['graph']['percentage'] = 0

gpu_sensor = GPUSensor(name='GPU',sensorType='chart',interval=0.5)
4 changes: 2 additions & 2 deletions ptop/plugins/memory_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self,**kwargs):
# there can be many text (key,value) pairs to display corresponding to each key
self.currentValue['text'] = { 'memory' : {},'swap_memory' : {}}
# there will be only one graph info
self.currentValue['graph'] = {'percentage' : ''}
self.currentValue['graph'] = {'percentage' : 0}

# overriding the update method
def update(self):
Expand All @@ -22,7 +22,7 @@ def update(self):
self.currentValue['text']['memory']['total'] = int(float(vmem.total)/(1024*1024))
self.currentValue['text']['memory']['active'] = int(float(vmem.active)/(1024*1024))
self.currentValue['text']['memory']['percentage'] = int(vmem.percent)
self.currentValue['graph']['percentage'] = int(vmem.percent)
self.currentValue['graph']['percentage'] = vmem.percent
# swap memory
smem = psutil.swap_memory()
self.currentValue['text']['swap_memory']['total'] = int(float(smem.total)/(1024*1024))
Expand Down
2 changes: 1 addition & 1 deletion ptop/plugins/process_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def update(self):
proc_info['command'] = ' '.join(p.cmdline())
# incrementing the thread_count and proc_count
thread_count += p.num_threads()
proc_info['cpu'] = p.cpu_percent()
proc_info['cpu'] = round(p.cpu_percent(interval=0.01),2)
proc_info['memory'] = round(p.memory_percent(),2)
# Add information of the local ports used by the process
proc_info['local_ports'] = [x.laddr[1] for x in p.connections()]
Expand Down
24 changes: 24 additions & 0 deletions ptop/plugins/temperature_sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#-*- coding: utf-8 -*-
'''
Temperature sensor plugin

Generates the Temperature usage stats
'''
from ptop.core import Plugin
import psutil

class TemperatureSensor(Plugin):
def __init__(self,**kwargs):
super(TemperatureSensor,self).__init__(**kwargs)
self.currentValue['text'] = {}

# overriding the update method
def update(self):
# temperature usage
temperature = psutil.sensors_temperatures(fahrenheit=False)
cpu_temp = temperature["coretemp"][0].current
# update the temperature
self.currentValue['text']['temp'] = str(cpu_temp)+'°C'


temperature_sensor = TemperatureSensor(name='Temperature',sensorType='text',interval=0.5)