From: Sam Moore Date: Thu, 9 Oct 2014 10:30:50 +0000 (+0800) Subject: Really hacky python performance scripts! X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=c786732a062b493be1e53c0223d7cb1858fd3d0f;p=ipdf%2Fcode.git Really hacky python performance scripts! DebugScript can be controlled by stdin Python subprocess lets us control IPDF without having to make DebugScript turing complete. --- diff --git a/src/debugscript.cpp b/src/debugscript.cpp index ff00f9e..59631aa 100644 --- a/src/debugscript.cpp +++ b/src/debugscript.cpp @@ -3,11 +3,17 @@ #include using namespace IPDF; +using namespace std; void DebugScript::ParseAction(View * view, Screen * scr) { + if (m_input == NULL || !m_input->good()) + return; + istream & inp = *m_input; + Debug("Get action type..."); std::string actionType; inp >> actionType; + Debug("Action type: %s", actionType.c_str()); // Skip comments while (actionType[0] == '#') { @@ -158,12 +164,15 @@ void DebugScript::ParseAction(View * view, Screen * scr) { currentAction.type = AT_QueryGPUBounds; inp >> currentAction.textargs; + currentAction.loops = 1; } else if (actionType == "screenshot") { currentAction.type = AT_ScreenShot; inp >> currentAction.textargs; } + else + Fatal("Unknown action %s", actionType.c_str()); } diff --git a/src/debugscript.h b/src/debugscript.h index 9e85b51..ae2c8eb 100644 --- a/src/debugscript.h +++ b/src/debugscript.h @@ -13,12 +13,9 @@ namespace IPDF class DebugScript { public: - DebugScript() : inp(), currentAction(), m_actions(), m_labels(), m_index(0) {} + DebugScript(std::istream * in) : m_input(in), currentAction(), m_actions(), m_labels(), m_index(0) {} virtual ~DebugScript() {} - void Load(const char *filename) - { - inp.open(filename); - } + bool Execute(View *view, Screen *scr); private: enum ActionType @@ -62,7 +59,7 @@ private: Action() : type(AT_WaitFrame), x(0), y(0), ix(0), iy(0), z(0), loops(0), textargs("") {} }; - std::ifstream inp; + std::istream * m_input; Action currentAction; std::vector m_actions; diff --git a/src/foxzoom.script b/src/foxzoom.script index bf191e0..525df58 100644 --- a/src/foxzoom.script +++ b/src/foxzoom.script @@ -1,12 +1,9 @@ label start setbounds 0 0 1 1 +gpubounds loadsvg svg-tests/fox-vector.svg -querygpubounds original.dat -screenshot original.bmp -loop 1950 pxzoom 0 0 -1 -loop 200 wait -debug hi -loop 1950 pxzoom 0 0 1 -querygpubounds transformed.dat -screenshot transformed.bmp +approachz 0.5 0.5 1e-37 1e-37 2 +loadsvg svg-tests/fox-vector.svg +approachz 0 0 1 1 2 +approachz 0.5 0.5 1e-37 1e-37 2 wait diff --git a/src/main.h b/src/main.h index bd43c12..d7945e6 100644 --- a/src/main.h +++ b/src/main.h @@ -77,16 +77,25 @@ void RatCatcher(int x, int y, int buttons, int wheel, Screen * scr, View * view) void MainLoop(Document & doc, Screen & scr, View & view, int max_frames = -1) { // order is important... segfaults occur when screen (which inits GL) is not constructed first -_- - DebugScript script; + scr.DebugFontInit("fonts/DejaVuSansMono.ttf", 12); //scr.DebugFontInit("fonts/DejaVuSansMono.ttf", 18); scr.SetMouseHandler(RatCatcher); - if (script_filename) + ifstream tmp; + istream * script_input = NULL; + if (script_filename != NULL) { - script.Load(script_filename); + if (strcmp(script_filename, "stdin") == 0) + script_input = &cin; + else + { + tmp.open(script_filename); + script_input = &tmp; + } } + DebugScript script(script_input); double total_cpu_time = 0; double total_gpu_time = 0; diff --git a/tools/grid_scaling.py b/tools/grid_scaling.py new file mode 100755 index 0000000..92c66c6 --- /dev/null +++ b/tools/grid_scaling.py @@ -0,0 +1,50 @@ +#!/usr/bin/python -u + +import sys +import os +from pylab import * +import subprocess +import time + +import gpubounds_error + +def grid_scaling(binname, x0, y0, w0, h0, s, steps=100,testsvg="svg-tests/grid.svg"): + data = [] + n = open("/dev/null", "w") + p = subprocess.Popen(binname + " -s stdin", bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=n, shell=True) + 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 0.5 0.5 %s\n" % 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("clearperf\n") + p.stdin.write("loop 10 wait\n") + p.stdin.write("recordperf\n") + p.stdin.write("printperf\n") + perf = p.stdout.readline() + time.sleep(0.5) + data += [gpubounds_error.ComputeError("original.dat", "step%d.dat" % i)] + #data += [gpubounds_error.UniqueBounds("step%d.dat" % i)] + + + print "Quit" + p.stdin.write("screenshot final.bmp\n") + p.stdin.write("quit\n") + p.stdin.close() + + data = asarray(data) + plot(data) + show(block=True) + + +if __name__ == "__main__": + binname = "../src/ipdf" + if len(sys.argv) > 1: + binname = sys.argv[1] + grid_scaling(binname, 0.5, 0.5, 1, 1, 0.5)