"""Profile one forward run (after a warm-up run) of a small and a large glacier."""
import cProfile, io, os, pstats, sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)) + '/..')
import aletsch_forward as af
for rid in ['RGI60-11.03845', 'RGI60-11.01450']:
    af.RGI_ID = rid
    gdir = af.setup(os.environ['WORKDIR'] + '/' + rid)
    s = gdir.settings
    th = (s['melt_f'], s['prcp_fac'], s['temp_bias'])
    af.forward(gdir, *th, suffix='_warm')
    pr = cProfile.Profile(); pr.enable()
    af.forward(gdir, *th, suffix='_prof')
    pr.disable()
    out = io.StringIO()
    pstats.Stats(pr, stream=out).sort_stats('cumulative').print_stats(30)
    print(f'===== {rid}'); print(out.getvalue()[:6000])
    out = io.StringIO()
    pstats.Stats(pr, stream=out).sort_stats('tottime').print_stats(15)
    print(f'===== {rid} tottime'); print(out.getvalue()[:4000])
