~amavect/makeu

65fe9ec566a9f97add673a6baf88fa42a548d46f — amavect 1 year, 5 months ago 3a813f6
refactor debug info
1 files changed, 49 insertions(+), 23 deletions(-)

M makeu.c
M makeu.c => makeu.c +49 -23
@@ 320,11 320,6 @@ kbdproc(void *aux)
	threadexits(nil);
}

vlong startt, stopt;
#define STARTTIME() startt = nsec()
#define STOPTIME() stopt = nsec(); \
	fprint(2, "%lld\n", stopt-startt)

void
egetwindow(void)
{


@@ 334,11 329,60 @@ egetwindow(void)
	screenbuf = allocimage(display, screen->r, screen->chan, 0, DBlack);
}

#define DEBUG 0
vlong startt, stopt;

/* 
 * small benchmark window size
 * window -dx 900 -dy 600
 * large benchmark window size
 * window -dx 1600 -dy 900
 *
 * while the debug info affects redraw time,
 * it should be negligible.
 */
void
_debuginfo(void)
{
	Rectangle rekt;
	static ulong frames;
	char ftext[32];
	static vlong last;
	static vlong now;
	
	snprint(ftext, sizeof(ftext), "frames: %uld", (ulong)frames);
	rekt = Rpt(screenbuf->r.min, addpt(screenbuf->r.min, stringsize(display->defaultfont, ftext)));
	draw(screenbuf, rekt, display->white, nil, ZP);
	string(screenbuf, screenbuf->r.min, display->black, ZP, display->defaultfont, ftext);
	frames++;
	
	snprint(ftext, sizeof(ftext), "flushtime: %lld", stopt - startt);
	rekt.min = Pt(rekt.min.x, rekt.max.y);
	rekt = Rpt(rekt.min, addpt(rekt.min, stringsize(display->defaultfont, ftext)));
	draw(screenbuf, rekt, display->white, nil, ZP);
	string(screenbuf, rekt.min, display->black, ZP, display->defaultfont, ftext);
	
	now = nsec();
	snprint(ftext, sizeof(ftext), "looptime: %lld", now - last);
	rekt.min = Pt(rekt.min.x, rekt.max.y);
	rekt = Rpt(rekt.min, addpt(rekt.min, stringsize(display->defaultfont, ftext)));
	draw(screenbuf, rekt, display->white, nil, ZP);
	string(screenbuf, rekt.min, display->black, ZP, display->defaultfont, ftext);
	last = now;
}

void
show(void)
{
	if(DEBUG){
		_debuginfo();
		startt = nsec();
	}
	draw(screen, screen->r, screenbuf, nil, screen->r.min);
	flushimage(display, 1);
	if(DEBUG){
		stopt = nsec();
	}
}

void


@@ 423,25 467,7 @@ threadmain(int argc, char **argv)
		[NONE]   = {nil, nil, CHANEND}
	};
	
	/* DEBUG frame counter */
	/*
	Rectangle rekt;
	ulong frames = 0;
	char ftext[10];
	STARTTIME();
	*/
	
	for(;;){
		/* DEBUG frame counter */
		/*
		snprint(ftext, sizeof(ftext), "%uld", (ulong)frames);
		rekt = Rpt(screenbuf->r.min, addpt(screenbuf->r.min, stringsize(display->defaultfont, ftext)));
		draw(screenbuf, rekt, display->white, nil, ZP);
		string(screenbuf, screenbuf->r.min, display->black, ZP, display->defaultfont, ftext);
		frames++;
		show();
		*/
		
		switch(alt(alts)){
		case MOUSE:
			if(m.buttons == 4){