def graph_profile_program(sourcefile):
    """
    @type sourcefile: str, unicode
    @return: None
    """
    if 0 != os.system("python -m cProfile -o output.pstats ./" + sourcefile):
        print("\033[31mprofile error:\033[0m")
        print("\033[33m", "pip install graphviz", "\033[0m")
        print("\033[33m", "pip install gprof2dot", "\033[0m")

    elif 0 != os.system("gprof2dot -f pstats output.pstats | dot -Tpng -o " + sourcefile.replace(".py", ".png")):
        print("\033[31mgprof2dot error:\033[0m")
        print("\033[33m", "pip install graphviz", "\033[0m")
        print("\033[33m", "pip install gprof2dot", "\033[0m")
        print("\033[33m", "gprof2dot is in path? (/usr/local/bin/gprof2dot)", "\033[0m")
    else:
        if not os.path.exists("./" + sourcefile.replace(".py", ".png")):
            print("\033[31mcannot find", sourcefile.replace(".py", ".png"), "\033[0m")
        else:
            os.system("open " + sourcefile.replace(".py", ".png"))

            if os.remove("output.pstats"):
                os.remove("output.pstats")
def graph_profile_program ( sourcefile ) : if 0 != os . system ( "python -m cProfile -o output.pstats ./" + sourcefile ) : print ( "\033[31mprofile error:\033[0m" ) print ( "\033[33m" , "pip install graphviz" , "\033[0m" ) print ( "\033[33m" , "pip install gprof2dot" , "\033[0m" ) elif 0 != os . system ( "gprof2dot -f pstats output.pstats | dot -Tpng -o " + sourcefile . replace ( ".py" , ".png" ) ) : print ( "\033[31mgprof2dot error:\033[0m" ) print ( "\033[33m" , "pip install graphviz" , "\033[0m" ) print ( "\033[33m" , "pip install gprof2dot" , "\033[0m" ) print ( "\033[33m" , "gprof2dot is in path? (/usr/local/bin/gprof2dot)" , "\033[0m" ) else : if not os . path . exists ( "./" + sourcefile . replace ( ".py" , ".png" ) ) : print ( "\033[31mcannot find" , sourcefile . replace ( ".py" , ".png" ) , "\033[0m" ) else : os . system ( "open " + sourcefile . replace ( ".py" , ".png" ) ) if os . remove ( "output.pstats" ) : os . remove ( "output.pstats" )
@type sourcefile: str, unicode
    @return: None