X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=tools%2Fscaling.py;h=a354e72cf9f60f4c62a76f4c05c6b7b7b394b5bb;hb=refs%2Fheads%2Fmaster;hp=6240718f490782a1647d3b39109ed2c0326c2f13;hpb=9bdc5bae5786db07e19a43136a126ae8723eb191;p=ipdf%2Fcode.git diff --git a/tools/scaling.py b/tools/scaling.py index 6240718..a354e72 100755 --- a/tools/scaling.py +++ b/tools/scaling.py @@ -1,5 +1,7 @@ #!/usr/bin/python -u +#much copy paste such python + import sys import os from matplotlib.pyplot import * @@ -14,83 +16,122 @@ def FixedScales(binname, x0=0, y0=0, w0=1, h0=1, s=0.5, steps=100, xz = 0.5, yz performance = [] n = open("/dev/null", "w") #n = sys.stderr - p = subprocess.Popen(binname + " -s stdin", bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=n, shell=True) - p.stdin.write("%s\n" % renderer) - p.stdin.write("setbounds %s %s %s %s\n" % (str(x0),str(y0),str(w0),str(h0))) - p.stdin.write("loadsvg %s\n" % testsvg) - p.stdin.write("querygpubounds original.dat\n") - p.stdin.write("screenshot original.bmp\n") - for i in xrange(steps): - p.stdin.write("clear\n") - p.stdin.write("loop 1 zoom %s %s %s\n" % (str(xz), str(yz), str(s))) + try: + p = subprocess.Popen(binname + " -s stdin", bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=n, shell=True) + p.stdin.write("%s\n" % renderer) + p.stdin.write("setbounds %s %s %s %s\n" % (str(x0),str(y0),str(w0),str(h0))) p.stdin.write("loadsvg %s\n" % testsvg) - p.stdin.write("querygpubounds step%d.dat\n" % i) - while not os.path.isfile("step%d.dat" % i): - pass - p.stdin.write("loop %d printfps\n" % fps) # Print an FPS count to signal it is safe to read the file - fpsout = p.stdout.readline().strip(" \r\n").split("\t") + p.stdin.write("querygpubounds original.dat\n") + p.stdin.write("screenshot original.bmp\n") + except Exception, e: + print "%s - Couldn't start - %s" % (binname, str(e)) + return {"accuracy" : asarray(accuracy), \ + "performance" : asarray(performance)} + + for i in xrange(steps): + try: + start_time = time.time() + p.stdin.write("clear\n") + p.stdin.write("loop 1 zoom %s %s %s\n" % (str(xz), str(yz), str(s))) + p.stdin.write("loadsvg %s\n" % testsvg) + p.stdin.write("querygpubounds step%d.dat\n" % i) + #while not os.path.isfile("step%d.dat" % i): + # pass + p.stdin.write("loop %d printspf\n" % fps) # Print an FPS count to signal it is safe to read the file + fpsout = p.stdout.readline().strip(" \r\n").split("\t") #print(str(fpsout)) - p.stdin.write("printbounds\n") - bounds = map(float, p.stdout.readline().strip(" \r\n").split("\t")) + p.stdin.write("printbounds\n") + bounds = p.stdout.readline().strip(" \r\n").split("\t") + try: + bounds = map(float, bounds) + except: + pass - performance += [map(float, fpsout)] - accuracy += [bounds + [gpubounds.ComputeError("original.dat", "step%d.dat" % i), \ + performance += [map(float, fpsout) + [time.time() - start_time]] + accuracy += [bounds + [gpubounds.ComputeError("original.dat", "step%d.dat" % i), \ gpubounds.UniqueBounds("step%d.dat" % i)]] - os.unlink("step%d.dat" % i) # Don't need it any more - if accuracy[-1][-1] <= 0: - print "%s - Quit early after %d steps" % (binname, i) + os.unlink("step%d.dat" % i) # Don't need it any more + #print accuracy[-1][-1] + if accuracy[-1][-1] <= 1: + print "%s - Quit early after %d steps - No precision left" % (binname, i) + break + if performance[-1][-1] > 60: + print "%s - Quit early after %d steps - Took too long to render frames" % (binname, i) + break + except Exception, e: + print "%s - Quit early after %d steps - Exception %s" % (binname, i, str(e)) break - p.stdin.write("screenshot final.bmp\n") - p.stdin.write("quit\n") - p.stdin.close() + try: + p.stdin.write("screenshot final.bmp\n") + p.stdin.write("quit\n") + p.stdin.close() + except Exception, e: + print "%s - Couldn't exit - %s" % (binname, str(e)) + return {"accuracy" : asarray(accuracy), "performance" : asarray(performance)} -def TestInvariance(binname, x0=0, y0=0, w0=1, h0=1, s=-1, steps=1000, xz = 0.5, yz = 0.5, testsvg="svg-tests/grid.svg", renderer="gpu", fps=1): +def TestInvariance(binname, x0=0, y0=0, w0=1, h0=1, s=-1, steps=1000, xz = 400, yz = 300, testsvg="svg-tests/grid.svg", renderer="gpu", fps=1): accuracy = [] performance = [] n = open("/dev/null", "w") #n = sys.stderr - p = subprocess.Popen(binname + " -s stdin", bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=n, shell=True) - p.stdin.write("%s\n" % renderer) - p.stdin.write("setbounds %s %s %s %s\n" % (str(x0),str(y0),str(w0),str(h0))) - p.stdin.write("loadsvg %s\n" % testsvg) - p.stdin.write("querygpubounds original.dat\n") - p.stdin.write("screenshot original.bmp\n") - p.stdin.write("printbounds\n") - bounds_orig = map(float, p.stdout.readline().strip(" \r\n").split("\t")) - for i in xrange(1,steps,50): - p.stdin.write("loop %d pxzoom %s %s %s\n" % (i, str(xz), str(yz), str(int(s)))) + try: + p = subprocess.Popen(binname + " -s stdin", bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=n, shell=True) + p.stdin.write("%s\n" % renderer) + p.stdin.write("setbounds %s %s %s %s\n" % (str(x0),str(y0),str(w0),str(h0))) + p.stdin.write("loadsvg %s\n" % testsvg) + p.stdin.write("querygpubounds original.dat\n") + p.stdin.write("screenshot original.bmp\n") p.stdin.write("printbounds\n") - bounds = map(float, p.stdout.readline().strip(" \r\n").split("\t")) - p.stdin.write("loop %d pxzoom %s %s %s\n" % (i, str(xz), str(yz), str(-int(s)))) - p.stdin.write("querygpubounds step%d.dat\n" % i) - while not os.path.isfile("step%d.dat" % i): - pass - p.stdin.write("loop %d printfps\n" % fps) # Print an FPS count to signal it is safe to read the file - fpsout = p.stdout.readline().strip(" \r\n").split("\t") - #print(str(fpsout)) + bounds_orig = map(float, p.stdout.readline().strip(" \r\n").split("\t")) + except Exception, e: + print "%s - Couldn't start - %s" % (binname, str(e)) + return {"accuracy" : asarray(accuracy), + "performance" : asarray(performance)} + + for i in xrange(1,steps,50): + try: + start_time = time.time() + p.stdin.write("loop %d pxzoom %s %s %s\n" % (i, str(xz), str(yz), str(int(s)))) + p.stdin.write("printbounds\n") + bounds = map(float, p.stdout.readline().strip(" \r\n").split("\t")) + p.stdin.write("loop %d pxzoom %s %s %s\n" % (i, str(xz), str(yz), str(-int(s)))) + p.stdin.write("querygpubounds step%d.dat\n" % i) + while not os.path.isfile("step%d.dat" % i): + pass + p.stdin.write("loop %d printspf\n" % fps) # Print an FPS count to signal it is safe to read the file + fpsout = p.stdout.readline().strip(" \r\n").split("\t") + #print(str(fpsout)) - bounds[0] = bounds[0]-bounds_orig[0] - bounds[1] = bounds[1]-bounds_orig[1] - bounds[2] = bounds[2]/bounds_orig[2] - bounds[3] = bounds[3]/bounds_orig[3] - performance += [map(float, fpsout)] - accuracy += [bounds + [gpubounds.ComputeError("original.dat", "step%d.dat" % i), \ + bounds[0] = bounds[0]-bounds_orig[0] + bounds[1] = bounds[1]-bounds_orig[1] + bounds[2] = bounds[2]/bounds_orig[2] + bounds[3] = bounds[3]/bounds_orig[3] + performance += [map(float, fpsout) + [time.time() - start_time]] + accuracy += [bounds + [gpubounds.ComputeError("original.dat", "step%d.dat" % i), \ gpubounds.UniqueBounds("step%d.dat" % i)]] - os.unlink("step%d.dat" % i) # Don't need it any more - if accuracy[-1][-1] <= 0: - print "%s - Quit early after %d steps" % (binname, i) - break - - p.stdin.write("screenshot final.bmp\n") - p.stdin.write("quit\n") - p.stdin.close() + os.unlink("step%d.dat" % i) # Don't need it any more + if accuracy[-1][-1] <= 10: + print "%s - Quit early after %d steps - No precision left" % (binname, i) + break + if performance[-1][-1] > 60: + print "%s - Quit early after %d steps - Took too long to render frames" % (binname, i) + break + except Exception, e: + print "%s - Quit early after %d steps - %s" % (binname, i, str(e)) + + try: + p.stdin.write("screenshot final.bmp\n") + p.stdin.write("quit\n") + p.stdin.close() + except Exception, e: + print "%s - Couldn't exit - %s" % (binname, str(e)) return {"accuracy" : asarray(accuracy), "performance" : asarray(performance)}