-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
top: Add psutil APIs for various OS support
Signed-off-by: Peace Lee <[email protected]>
- Loading branch information
Showing
1 changed file
with
100 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -50212,7 +50212,7 @@ class Debugger(object): | |
envFlags = { | ||
'TRACEBP': False, | ||
'EXCEPTWAIT': False, | ||
'EXCEPTNOSYM': False, | ||
'ONLYSYMBOL': False, | ||
'EXCEPTLD': False, | ||
'NOMUTE': False, | ||
'NOSTRIP': False, | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
||
|
@@ -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) | ||
|
@@ -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: | ||
|
@@ -82134,7 +82134,7 @@ def saveProcStat(self): | |
|
||
|
||
|
||
def saveGenSystemInfo(self): | ||
def saveSystemStatGen(self): | ||
# get psutil object # | ||
psutil = SysMgr.getPkg('psutil') | ||
|
||
|
@@ -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() | ||
|
||
|
||
|
||
|