diff options
author | Martin Nowack <m.nowack@imperial.ac.uk> | 2020-02-20 12:41:26 +0000 |
---|---|---|
committer | Cristian Cadar <c.cadar@imperial.ac.uk> | 2020-03-01 20:29:18 +0000 |
commit | fdaa441abbd47b7e0daba680eddf72c859c47f08 (patch) | |
tree | d8bd715fa5ca7491c17a544a30051cf74582da2a /tools | |
parent | f28f0272bb2d18b450a3151164deb663eef62a68 (diff) | |
download | klee-fdaa441abbd47b7e0daba680eddf72c859c47f08.tar.gz |
[klee-stats] Do not crash if tabulate is not installed but requested
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/klee-stats/klee-stats | 62 |
1 files changed, 39 insertions, 23 deletions
diff --git a/tools/klee-stats/klee-stats b/tools/klee-stats/klee-stats index 25fb6136..ab28ba0f 100755 --- a/tools/klee-stats/klee-stats +++ b/tools/klee-stats/klee-stats @@ -17,14 +17,6 @@ import sys import argparse import sqlite3 -try: - from tabulate import TableFormat, Line, DataRow, tabulate, _table_formats -except: - print('Error: Package "tabulate" required for table formatting. ' - 'Please install it using "pip" or your package manager.' - 'You can still use --grafana and --to-csv without tabulate.', - file=sys.stderr) - Legend = [ ('Instrs', 'number of executed instructions'), ('Time', 'total wall time (s)'), @@ -44,15 +36,6 @@ Legend = [ ('QCexCHits', 'Counterexample cache hits'), ] -KleeTable = TableFormat(lineabove=Line("-", "-", "-", "-"), - linebelowheader=Line("-", "-", "-", "-"), - linebetweenrows=None, - linebelow=Line("-", "-", "-", "-"), - headerrow=DataRow("|", "|", "|"), - datarow=DataRow("|", "|", "|"), - padding=0, - with_header_hide=None) - def getInfoFile(path): """Return the path to info""" return os.path.join(path, 'info') @@ -256,6 +239,17 @@ def write_csv(data): def write_table(args, data, dirs, pr): + from tabulate import TableFormat, Line, DataRow, tabulate + + KleeTable = TableFormat(lineabove=Line("-", "-", "-", "-"), + linebelowheader=Line("-", "-", "-", "-"), + linebetweenrows=None, + linebelow=Line("-", "-", "-", "-"), + headerrow=DataRow("|", "|", "|"), + datarow=DataRow("|", "|", "|"), + padding=0, + with_header_hide=None) + if len(data) > 1: dirs = stripCommonPathPrefix(dirs) # attach the stripped path @@ -301,17 +295,30 @@ def write_table(args, data, dirs, pr): def main(): + tabulate_available = False + epilog = "" + + try: + from tabulate import tabulate, _table_formats + epilog = 'LEGEND\n' + tabulate([(f[:2]) for f in Legend]) + + tabulate_available = True + except: + pass + parser = argparse.ArgumentParser( description='output statistics logged by klee', - epilog='LEGEND\n' + tabulate(Legend), + epilog=epilog, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('dir', nargs='+', help='klee output directory') - parser.add_argument('--table-format', - choices=['klee'] + list(_table_formats.keys()), - dest='tableFormat', default='klee', - help='Table format for the summary.') + if tabulate_available: + parser.add_argument('--table-format', + choices=['klee'] + list(_table_formats.keys()), + dest='tableFormat', default='klee', + help='Table format for the summary.') + parser.add_argument('--to-csv', action='store_true', dest='toCsv', help='Output stats as comma-separated values (CSV)') @@ -375,7 +382,16 @@ def main(): write_csv(data) return - write_table(args, data, dirs, pr) + if tabulate_available: + write_table(args, data, dirs, pr) + return + + print('Error: Package "tabulate" required for table formatting. ' + 'Please install it using "pip" or your package manager.' + 'You can still use --grafana and --to-csv without tabulate.', + file=sys.stderr) + sys.exit(1) + if __name__ == '__main__': |