Skip to content

Commit

Permalink
memtest: Split a huge workload by 100M
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <iipeace5@gmail.com>
  • Loading branch information
iipeace committed Nov 6, 2024
1 parent b850a99 commit b367b87
Showing 1 changed file with 39 additions and 21 deletions.
60 changes: 39 additions & 21 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__ = "241105"
__revision__ = "241106"
__maintainer__ = "Peace Lee"
__email__ = "iipeace5@gmail.com"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -28661,52 +28661,62 @@ def getNrCrash():

@staticmethod
def waitForResource(cpuRes=-1, cpuCond="MORE", memRes=-1, memCond="MORE"):
# check exit condition #
if cpuRes < 0 and memRes < 0:
return False

# check condition #
if cpuRes >= 0:
SysMgr.printInfo(
"wait for system CPU usage %s than %s%%"
% (cpuCond, UtilMgr.convNum(cpuRes))
)
elif memRes >= 0:
if memRes >= 0:
SysMgr.printInfo(
("wait for system available memory %s than %s MB")
% (memCond, UtilMgr.convNum(memRes))
)
else:
return False

# convert condition #
if cpuCond:
cpuCond = cpuCond.upper()
if memCond:
memCond = memCond.upper()
cpuCond = str(cpuCond).upper()
memCond = str(memCond).upper()

# init variables #
SysMgr.updateUptime()
dobj = Debugger(SysMgr.pid, attach=False)
dobj.initValues()

while 1:
# wait next interval #
time.sleep(1)
SysMgr.updateUptime()

# check cpu #
if cpuRes >= 0:
cpuStat = dobj.getCpuUsage(system=True)
if cpuStat and cpuStat[3]:
cpuUsage = 100 - (cpuStat[3] / SysMgr.uptimeDiff)
SysMgr.cpuUsage = cpuUsage
if cpuCond == "MORE" and cpuUsage >= cpuRes:
return True
cpuRes = -1
elif cpuCond == "LESS" and cpuUsage <= cpuRes:
return True
cpuRes = -1
continue

# check mem #
if memRes >= 0:
memAvail = SysMgr.getAvailMemInfo(retstr=False)
if memAvail:
SysMgr.memAvail = memAvail = memAvail >> 20
if memCond == "MORE" and memAvail >= memRes:
return True
memRes = -1
elif memCond == "LESS" and memAvail <= memRes:
return True
memRes = -1
continue

time.sleep(1)
SysMgr.updateUptime()
# check final status #
if cpuRes < 0 and memRes < 0:
break

@staticmethod
def loadLibcObj(exit=False):
Expand Down Expand Up @@ -36452,7 +36462,7 @@ def getCmdline(pid, retList=False, cache=False, default=""):
@staticmethod
def getTracerId(pid):
tpid = SysMgr.getTaskAttr(pid, "TracerPid")
return tpid if tpid else 0
return long(tpid) if tpid else 0

@staticmethod
def getUid(pid, itype="real"):
Expand Down Expand Up @@ -75561,12 +75571,16 @@ def _allocMemory(size, wrPipe=None, ret=False):

# allocate memory #
try:
if "RAND" in SysMgr.environList:
chunk = bytearray(os.urandom(size))
else:
chunk = bytearray(size)

SysMgr.procBuffer = chunk
chunk = bytearray(1)
while 1:
x = min(size, 100 << 20)
if "RAND" in SysMgr.environList:
chunk += bytearray(os.urandom(x))
else:
chunk += bytearray(x)
size -= x
if size <= 0:
break
except SystemExit:
sys.exit(0)
except:
Expand Down Expand Up @@ -75677,6 +75691,10 @@ def _printUsage(obj, size, alloc=True):
pager=False,
)

# check termination condition #
if not SysMgr.getChildList():
sys.exit(0)

# set stream #
SysMgr.setStream(cut=False)

Expand Down

0 comments on commit b367b87

Please sign in to comment.