Skip to content

Commit

Permalink
Improving the profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
MassimoLauria committed Aug 8, 2020
1 parent 16f469b commit b85dade
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions profile.py → cgprof.py
Expand Up @@ -6,34 +6,31 @@
import os
import sys
from cProfile import run
from contextlib import contextmanager


@contextmanager
def erase_stdout():

with open(os.devnull, "w") as null:
old_stdout = sys.stdout
sys.stdout = null

yield

sys.stdout = old_stdout
from cnfgen.clitools.cmdline import paginate_or_redirect_stdout


def cnfgen_call():
from cnfgen import cnfgen

cmd = ["cnfgen"] + sys.argv[1:]

with erase_stdout():
with open(os.devnull, "w") as null:
old_stdout = sys.stdout
sys.stdout = null

cnfgen(cmd)

sys.stdout = old_stdout

if __name__ == '__main__':

def main():
if len(sys.argv) <= 1:
print("Usage: {} <cnfgen_args>".format(sys.argv[0]), file=sys.stderr)
sys.exit(-1)

run('cnfgen_call()', sort='tottime')
with paginate_or_redirect_stdout(sys.stdout):
run('cnfgen_call()', sort='tottime')


if __name__ == '__main__':
main()

0 comments on commit b85dade

Please sign in to comment.