Skip to content

Commit

Permalink
top: Add psutil APIs for various OS support
Browse files Browse the repository at this point in the history
Signed-off-by: Peace Lee <[email protected]>
  • Loading branch information
iipeace committed Jul 12, 2021
1 parent 2fbf615 commit 9fb9114
Showing 1 changed file with 100 additions and 52 deletions.
152 changes: 100 additions & 52 deletions guider/guider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__credits__ = "Peace Lee"
__license__ = "GPLv2"
__version__ = "3.9.8"
__revision__ = "210711"
__revision__ = "210712"
__maintainer__ = "Peace Lee"
__email__ = "[email protected]"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -22575,7 +22575,7 @@ def printHelp(force=False):
# {0:1} {1:1} -g a.out -q STOPTARGET

- Trace all native calls except for no symbol functions for specific threads
# {0:1} {1:1} -g a.out -q EXCEPTNOSYM
# {0:1} {1:1} -g a.out -q ONLYSYMBOL

- Trace all native calls except for ld for specific threads
# {0:1} {1:1} -g a.out -q EXCEPTLD
Expand Down Expand Up @@ -23340,7 +23340,7 @@ def printHelp(force=False):
# {0:1} {1:1} -g a.out -q CPUCOND:10

- Monitor syscalls except for no symbol functions for specific threads
# {0:1} {1:1} a.out -g a.out -q EXCEPTNOSYM
# {0:1} {1:1} a.out -g a.out -q ONLYSYMBOL

- Monitor syscalls for specific threads after loading all symbols in stop status
# {0:1} {1:1} a.out -g a.out -q STOPTARGET
Expand Down Expand Up @@ -23409,7 +23409,7 @@ def printHelp(force=False):
# {0:1} {1:1} -g a.out -q CPUCOND:10

- Monitor python calls except for no symbol functions for specific threads
# {0:1} {1:1} a.out -g a.out -q EXCEPTNOSYM
# {0:1} {1:1} a.out -g a.out -q ONLYSYMBOL

- Monitor python calls for specific threads after loading all symbols in stop status
# {0:1} {1:1} a.out -g a.out -q STOPTARGET
Expand Down Expand Up @@ -23486,7 +23486,7 @@ def printHelp(force=False):
# {0:1} {1:1} -g a.out -q CPUCOND:10

- Monitor native function calls except for no symbol functions for specific threads
# {0:1} {1:1} a.out -g a.out -q EXCEPTNOSYM
# {0:1} {1:1} a.out -g a.out -q ONLYSYMBOL

- Monitor native function calls for specific threads after loading all symbols in stop status
# {0:1} {1:1} a.out -g a.out -q STOPTARGET
Expand Down Expand Up @@ -50212,7 +50212,7 @@ class Debugger(object):
envFlags = {
'TRACEBP': False,
'EXCEPTWAIT': False,
'EXCEPTNOSYM': False,
'ONLYSYMBOL': False,
'EXCEPTLD': False,
'NOMUTE': False,
'NOSTRIP': False,
Expand Down Expand Up @@ -52913,7 +52913,7 @@ def injectBp(
procInfo = '%s(%s)' % (self.comm, self.pid)

# skip no symbol function #
if sym and Debugger.envFlags['EXCEPTNOSYM'] and sym.startswith('0x'):
if sym and Debugger.envFlags['ONLYSYMBOL'] and sym.startswith('0x'):
SysMgr.printWarn(
'skip injecting breakpoint for no symbol function %s' % sym)
return False
Expand Down Expand Up @@ -56690,7 +56690,7 @@ def convAddrList(self, btList):
sym = res[0]

# skip no symbol function #
if Debugger.envFlags['EXCEPTNOSYM'] and \
if Debugger.envFlags['ONLYSYMBOL'] and \
sym and sym.startswith('0x'):
continue

Expand Down Expand Up @@ -57414,7 +57414,7 @@ def initPyEnv(self):
sys.exit(0)

# remove anonymous symbol #
Debugger.envFlags['EXCEPTNOSYM'] = True
Debugger.envFlags['ONLYSYMBOL'] = True

# check native function for python call #
addr = self.getAddrBySymbol(SysMgr.pyCallFunc)
Expand Down Expand Up @@ -67382,7 +67382,7 @@ def _getProcName(pinfo):



def __init__(self, fpath=None, onlyInstance=None):
def __init__(self, fpath=None, onlyInstance=False):

# exec variable #
if SysMgr.execEnable is None:
Expand Down Expand Up @@ -82134,7 +82134,7 @@ def saveProcStat(self):



def saveGenSystemInfo(self):
def saveSystemStatGen(self):
# get psutil object #
psutil = SysMgr.getPkg('psutil')

Expand All @@ -82144,47 +82144,95 @@ def saveGenSystemInfo(self):
'''

# CPU #
psutil.cpu_times(percpu=False)
psutil.cpu_percent(interval=None, percpu=False)
psutil.cpu_count(logical=True)
psutil.cpu_stats()
psutil.cpu_freq(percpu=False)
psutil.getloadavg()

# Memory #
psutil.virtual_memory()
psutil.swap_memory()

# Disk #
psutil.disk_partitions(all=False)
#psutil.disk_usage(path=None)
psutil.disk_io_counters(perdisk=False, nowrap=True)

# Network #
psutil.net_io_counters(pernic=False, nowrap=True)
psutil.net_connections(kind='inet')
psutil.net_if_addrs()
psutil.net_if_stats()

# ETC #
psutil.sensors_temperatures(fahrenheit=False)
psutil.sensors_fans()
psutil.sensors_battery()
psutil.users()

# Process #
psutil.process_iter(attrs=None, ad_value=None)
psutil.pid_exists(pid=os.getpid())
proc = psutil.Process(pid=None)
procDict = proc.as_dict(attrs=None, ad_value=None)
procMem = proc.memory_full_info()
proc.is_running()
proc.send_signal()
proc.suspend()
proc.resume()
proc.terminate()
proc.kill()
proc.wait()
cpuStat = psutil.cpu_times(percpu=False)
cpuOtherStat = psutil.cpu_stats()
clock = psutil.cpu_freq(percpu=True)
SysMgr.nrCore = psutil.cpu_count(logical=True)

# load #
try:
load = psutil.getloadavg()
except SystemExit:
sys.exit(0)
except:
load = None

# memory #
try:
mem = psutil.virtual_memory()
except SystemExit:
sys.exit(0)
except:
mem = None

# swap #
try:
swap = psutil.swap_memory()
except SystemExit:
sys.exit(0)
except:
swap = None

# disk #
partition = psutil.disk_partitions(all=SysMgr.showAll)
diskUsage = psutil.disk_usage(path='.')
diskStat = psutil.disk_io_counters(perdisk=False, nowrap=True)

# network #
netStat = psutil.net_io_counters(pernic=False, nowrap=True)
netConn = psutil.net_connections(kind='inet')
netAddr = psutil.net_if_addrs()
nicStat = psutil.net_if_stats()

# temperature #
try:
temp = psutil.sensors_temperatures(fahrenheit=False)
except SystemExit:
sys.exit(0)
except:
temp = None

# fan #
try:
fan = psutil.sensors_fans()
except SystemExit:
sys.exit(0)
except:
fan = None

# battery #
try:
battery = psutil.sensors_battery()
except SystemExit:
sys.exit(0)
except:
battery = None

# users #
try:
user = psutil.users()
except SystemExit:
sys.exit(0)
except:
user = None

# process #
#psutil.Process(pid=os.getpid())
#psutil.pid_exists(pid=os.getpid())
procs = psutil.process_iter(attrs=None, ad_value=None)
for proc in procs:
procDict = proc.as_dict(attrs=None, ad_value=None)
#procMem = proc.memory_full_info()
continue

# control #
proc.is_running()
proc.send_signal(0)
proc.suspend()
proc.resume()
proc.terminate()
proc.kill()
proc.wait()



Expand Down

0 comments on commit 9fb9114

Please sign in to comment.