Skip to content

Commit

Permalink
iotest: Add ELAPSED option
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <[email protected]>
  • Loading branch information
iipeace committed Nov 2, 2023
1 parent 14103cf commit af230f5
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 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__ = "231101"
__revision__ = "231102"
__maintainer__ = "Peace Lee"
__email__ = "[email protected]"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -40879,6 +40879,10 @@ def _getDesc(s, t=0):
# {0:1} {1:1} write:TEST
# {0:1} {1:1} -g write:TEST

- Read specific files infinitely with printing elapsed time
# {0:1} {1:1} "read:TEST1,TEST2" -R -q ELAPSED:0
# {0:1} {1:1} "read:TEST1,TEST2" -R -q ELAPSED:0.1

- Write 100MB of dummy data to the specific file
# {0:1} {1:1} write:TEST:100M
# {0:1} {1:1} "write:TEST:100M, write:TEST2:50M"
Expand Down Expand Up @@ -63329,17 +63333,37 @@ def _flushCache(verb=False):
SysMgr.dropCaches("3", verb)

def _iotask(num, load):
def _readChunk(fobj, chunk=4096, sync=False):
def _readChunk(fobj, chunk=4096, sync=False, elapsed=False):
while 1:
if elapsed != -1:
prev = time.time()

ret = os.read(fobj, chunk)

if elapsed != -1:
diff = time.time() - prev
if diff >= elapsed:
SysMgr.printWarn("elapsed %.3f" % (diff), True)

yield ret

def _writeChunk(fobj, chunk=4096, sync=False):
def _writeChunk(fobj, chunk=4096, sync=False, elapsed=False):
while 1:
chunkData = _getChunk()

if elapsed != -1:
prev = time.time()

ret = os.write(fobj, chunkData[:chunk])

if sync:
os.fsync(fobj)

if elapsed != -1:
diff = time.time() - prev
if diff >= elapsed:
SysMgr.printWarn("elapsed %.3f" % (diff), True)

yield ret

# set default signal handlers #
Expand All @@ -63363,6 +63387,9 @@ def _writeChunk(fobj, chunk=4096, sync=False):

# get progress value #
printProgress = "PROGRESS" in SysMgr.environList
printElapsed = UtilMgr.getEnvironNum(
"ELAPSED", False, -1, False, isFloat=True
)

# get data format #
if "RAND" in SysMgr.environList:
Expand Down Expand Up @@ -63393,6 +63420,9 @@ def _writeChunk(fobj, chunk=4096, sync=False):
SysMgr.printErr("failed to recognize '%s'" % path)
sys.exit(-1)

# declare shortcut function #
conv = UtilMgr.convNum

for path in pathList:
# check I/O type #
if os.path.isfile(path) or SysMgr.isBlkDev(path):
Expand Down Expand Up @@ -63420,9 +63450,6 @@ def _writeChunk(fobj, chunk=4096, sync=False):
# get output size #
fsize = UtilMgr.getFileSizeStr(path)

# declare shortcut function #
conv = UtilMgr.convNum

# make load string #
if size > 0:
loadStr = "only %s " % UtilMgr.convSize2Unit(size)
Expand Down Expand Up @@ -63497,7 +63524,7 @@ def _writeChunk(fobj, chunk=4096, sync=False):

done = 0
fd = os.open(path, flag)
for piece in opFunc(fd, chunk, sync):
for piece in opFunc(fd, chunk, sync, printElapsed):
# update progress #
if isinstance(piece, (int, long)):
done += piece
Expand Down Expand Up @@ -63543,7 +63570,9 @@ def _writeChunk(fobj, chunk=4096, sync=False):

# execute io job #
fd = os.open(fpath, flag)
for piece in opFunc(fd, chunk, sync):
for piece in opFunc(
fd, chunk, sync, printElapsed
):
if not piece:
break
os.close(fd)
Expand Down Expand Up @@ -88146,7 +88175,10 @@ def getRet(self, temp=False):
else:
ret = getattr(self.regs, self.retreg)

return c_long(ret).value
if c_int(ret).value == -1:
return -1
else:
return c_long(ret).value
except SystemExit:
sys.exit(0)
except:
Expand Down

0 comments on commit af230f5

Please sign in to comment.