From b446bb02126049cda8d10e35da2e97439db6a4c7 Mon Sep 17 00:00:00 2001 From: Marc Koderer Date: Mon, 15 Mar 2021 11:02:22 +0100 Subject: [PATCH 1/3] Add CSV export functionality Add parameter to export csv file as additional output. Signed-off-by: Marc Koderer --- mdbench.py | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/mdbench.py b/mdbench.py index 28e807c..8618cfe 100755 --- a/mdbench.py +++ b/mdbench.py @@ -21,6 +21,7 @@ -n, --no-clean : do not delete created files and directories --no-container : do not create the 'mdbench..' 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 @@ -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 @@ -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() @@ -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() @@ -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) From a6125e5c787a25f6991e4e6bf5afdd3476b8659a Mon Sep 17 00:00:00 2001 From: Marc Koderer Date: Mon, 15 Mar 2021 11:09:46 +0100 Subject: [PATCH 2/3] Use -c for CSV exports The '-c' in '--no-container' matches unfortunately for the new parameter. Signed-off-by: Marc Koderer --- mdbench.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mdbench.py b/mdbench.py index 8618cfe..9b94e9e 100755 --- a/mdbench.py +++ b/mdbench.py @@ -21,7 +21,7 @@ -n, --no-clean : do not delete created files and directories --no-container : do not create the 'mdbench..' directory -e, --extended-checks: runs extended tests as chmod and mv - -C, --csv-file : export csv file with the results + -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 @@ -274,7 +274,7 @@ def main(): csvFile = None try: - options, remainder = getopt.gnu_getopt(sys.argv[1:], 'f:d:s:C:nhe', \ + 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)) @@ -289,11 +289,11 @@ def main(): file_size = get_size(arg) elif opt in ('-n', '--no-clean'): cleanup = False - elif opt in ('--no-container'): + elif opt == '--no-container': createContainer = False elif opt in ('-e', '--extended-checks'): extendedChecks = True - elif opt in ('-C', '--csv-file'): + elif opt in ('-c', '--csv-file'): csvFile = arg elif opt in ('-h', '--help'): usage() From 331dd8314da5ebfa2f9a9870d38ffc42fe776d42 Mon Sep 17 00:00:00 2001 From: Marc Koderer Date: Mon, 15 Mar 2021 11:21:50 +0100 Subject: [PATCH 3/3] Add title line in CSV Signed-off-by: Marc Koderer --- mdbench.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mdbench.py b/mdbench.py index 9b94e9e..759b7eb 100755 --- a/mdbench.py +++ b/mdbench.py @@ -309,7 +309,8 @@ def main(): os.mkdir(root) if csvFile: # Create empty file - open(csvFile, 'w').close() + with open(csvFile, 'w') as f: + f.write("title,average,std,IOPS\n") make_dirs(root, dir_count) report("dir creates", dir_creates, csvFile)