Skip to content

Commit

Permalink
Add CSV export functionality
Browse files Browse the repository at this point in the history
Add parameter to export csv file as additional output.

Signed-off-by: Marc Koderer <[email protected]>
  • Loading branch information
mkoderer committed Mar 15, 2021
1 parent e899761 commit b446bb0
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions mdbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
-n, --no-clean : do not delete created files and directories
--no-container : do not create the 'mdbench.<name>.<pid>' directory
-e, --extended-checks: runs extended tests as chmod and mv
-C, --csv-file : export csv file with the results
-h, --help : help message
and PATH points to the directory where tests should run. Current directory
Expand Down Expand Up @@ -247,10 +248,13 @@ def total_micros(td):
def total_millis(td):
return total_micros(td)/1000

def report(title, counter):
def report(title, counter, csvFile = None):
print('{:16}: {:6.2f}ms ±{:=6.2f}ms, {:6.2f} op/s' \
.format(title, counter.avg(), counter.std(), counter.count()/counter.sum()*10**3))

if csvFile is not None:
with open(csvFile, "a") as f:
txt = '%s,%.2f,%.2f,%.2f\n' % (title, counter.avg(), counter.std(), counter.count()/counter.sum()*10**3)
f.write(txt)
DIR_COUNT = 1000
FILE_COUNT = 10
FILE_SIZE = 0
Expand All @@ -267,10 +271,11 @@ def main():
cleanup = True
createContainer = True
extendedChecks = False
csvFile = None

try:
options, remainder = getopt.gnu_getopt(sys.argv[1:], 'f:d:s:nhe', \
['files=','dirs=','size=','no-clean','no-container','extended-checks','help'])
options, remainder = getopt.gnu_getopt(sys.argv[1:], 'f:d:s:C:nhe', \
['files=','dirs=','size=','no-clean','no-container','extended-checks','csv-file=','help'])
except getopt.GetoptError as err:
print(str(err))
usage()
Expand All @@ -288,6 +293,8 @@ def main():
createContainer = False
elif opt in ('-e', '--extended-checks'):
extendedChecks = True
elif opt in ('-C', '--csv-file'):
csvFile = arg
elif opt in ('-h', '--help'):
usage()

Expand All @@ -300,27 +307,30 @@ def main():

if createContainer:
os.mkdir(root)
if csvFile:
# Create empty file
open(csvFile, 'w').close()

make_dirs(root, dir_count)
report("dir creates", dir_creates)
report("dir creates", dir_creates, csvFile)
make_files(root, dir_count, file_count , file_size)
report("file creates", file_creates)
report("file creates", file_creates, csvFile)
stat_files(root, dir_count, file_count)
report("file stats", file_stats)
report("file stats", file_stats, csvFile)
if extendedChecks:
chmod_files(root, dir_count, file_count)
report("chmod stats", chmod_stats)
report("chmod stats", chmod_stats, csvFile)
mv_files(root, dir_count, file_count)
report("mv stats", mv_stats)
report("mv stats", mv_stats, csvFile)

stat_dirs(root, dir_count)
report("dir stats", dir_stats)
report("dir stats", dir_stats, csvFile)

if cleanup:
del_files(root, dir_count, file_count )
report("file removes", file_removes)
report("file removes", file_removes, csvFile)
del_dirs(root, dir_count )
report("dir removes", dir_removes)
report("dir removes", dir_removes, csvFile)
if createContainer:
os.rmdir(root)

Expand Down

0 comments on commit b446bb0

Please sign in to comment.