00001 #!/usr/bin/python 00002 00003 # Copyright (C) 2009 Ferdinand Majerech 00004 # This file is part of IMGCrush 00005 # For conditions of distribution and use, see copyright notice in LICENSE.txt 00006 00007 import subprocess 00008 import getopt 00009 import pstats 00010 import sys 00011 00012 def main(): 00013 """Profiles python program command and prints most time consuming functions. 00014 """ 00015 opts, args = getopt.getopt(sys.argv[1:], "", []) 00016 #command to profile 00017 subprocess.call("python -m cProfile -o prof.out " + args[0], shell=True) 00018 p = pstats.Stats("prof.out") 00019 p.sort_stats("cumulative") 00020 print "\nFirst 50 functions:\n" 00021 p.print_stats(50) 00022 print "\nFirst 50 imgcrush functions:\n" 00023 p.print_stats("imgcrush", 50) 00024 00025 if __name__ == '__main__': 00026 main()