shithub: libgraphics

Download patch

ref: fc8284f73c62cc205bcdc1be04802763a019ec1b
parent: 4d88a3779d1f5e15ea7ea3bca5330b9c8d1ef2fd
author: rodri <rgl@antares-labs.eu>
date: Mon Apr 15 18:26:34 EDT 2024

add some instrumentation to measure pipeline stage time.

--- a/camera.c
+++ b/camera.c
@@ -21,6 +21,16 @@
 }
 
 static void
+updatetimes(Camera *c, Renderjob *j)
+{
+	c->times.R[c->times.cur] = j->times.R;
+	c->times.E[c->times.cur] = j->times.E;
+	c->times.Tn[c->times.cur] = j->times.Tn;
+	c->times.Rn[c->times.cur] = j->times.Rn;
+	c->times.cur = ++c->times.cur % nelem(c->times.R);
+}
+
+static void
 verifycfg(Camera *c)
 {
 	assert(c->vp != nil);
@@ -98,6 +108,7 @@
 	t1 = nanosec();
 	c->vp->fbctl->swap(c->vp->fbctl);
 
+	updatetimes(c, job);
 	chanfree(job->donec);
 	free(job);
 
--- a/graphics.h
+++ b/graphics.h
@@ -29,6 +29,7 @@
 typedef struct SUparams SUparams;
 typedef struct Shadertab Shadertab;
 typedef struct Renderer Renderer;
+typedef struct Rendertime Rendertime;
 typedef struct Renderjob Renderjob;
 typedef struct Framebuf Framebuf;
 typedef struct Framebufctl Framebufctl;
@@ -175,6 +176,11 @@
 	Channel *c;
 };
 
+struct Rendertime
+{
+	uvlong t0, t1;
+};
+
 struct Renderjob
 {
 	Ref;
@@ -183,6 +189,10 @@
 	Shadertab *shaders;
 	Channel *donec;
 
+	struct {
+		Rendertime R, E, Tn, Rn;
+	} times;
+
 	Renderjob *next;
 };
 
@@ -234,6 +244,11 @@
 		uvlong min, avg, max, acc, n, v;
 		uvlong nframes;
 	} stats;
+
+	struct {
+		Rendertime R[100], E[100], Tn[100], Rn[100];
+		int cur;
+	} times;
 };
 
 /* camera */
--- a/render.c
+++ b/render.c
@@ -361,6 +361,7 @@
 	Rastertask *task;
 	SUparams *params;
 	Memimage *frag;
+	uvlong t0;
 
 	threadsetname("rasterizer");
 
@@ -368,6 +369,8 @@
 	frag = rgb(DBlack);
 
 	while((task = recvp(taskc)) != nil){
+		t0 = nanosec();
+
 		params = task->params;
 		/* end of job */
 		if(params->entity == nil){
@@ -379,6 +382,9 @@
 			continue;
 		}
 
+		if(params->job->times.Rn.t0 == 0)
+			params->job->times.Rn.t0 = t0;
+
 		params->frag = frag;
 		rasterize(task);
 
@@ -385,6 +391,7 @@
 		delvattrs(&task->t[0]);
 		delvattrs(&task->t[1]);
 		delvattrs(&task->t[2]);
+		params->job->times.Rn.t1 = nanosec();
 		free(params);
 		free(task);
 	}
@@ -406,6 +413,7 @@
 	Channel **taskc;
 	ulong Δx, nproc;
 	int i, nt;
+	uvlong t0;
 
 	threadsetname("tilerdurden");
 
@@ -416,6 +424,10 @@
 	wr = emalloc(nproc*sizeof(Rectangle));
 
 	while((params = recvp(tp->paramsc)) != nil){
+		t0 = nanosec();
+		if(params->job->times.Tn.t0 == 0)
+			params->job->times.Tn.t0 = t0;
+
 		/* end of job */
 		if(params->entity == nil){
 			if(decref(params->job) < 1){
@@ -543,6 +555,7 @@
 				delvattrs(&t[nt][2]);
 			}
 		}
+		params->job->times.Tn.t1 = nanosec();
 		free(params);
 	}
 }
@@ -557,6 +570,7 @@
 	char *nprocs;
 	ulong stride, nelems, nproc, nworkers;
 	int i;
+	uvlong t0;
 
 	threadsetname("entityproc");
 
@@ -584,6 +598,10 @@
 	}
 
 	while((params = recvp(paramsin)) != nil){
+		t0 = nanosec();
+		if(params->job->times.E.t0 == 0)
+			params->job->times.E.t0 = t0;
+
 		/* end of job */
 		if(params->entity == nil){
 			params->job->ref = nproc;
@@ -611,6 +629,7 @@
 			newparams->ee = i == nworkers-1? ee: newparams->eb + stride;
 			sendp(paramsout[i], newparams);
 		}
+		params->job->times.E.t1 = nanosec();
 		free(params);
 	}
 }
@@ -634,9 +653,9 @@
 	proccreate(entityproc, paramsc, mainstacksize);
 
 	while((job = recvp(jobc)) != nil){
-		sc = job->scene;
 		time = nanosec();
-
+		job->times.R.t0 = time;
+		sc = job->scene;
 		if(sc->nents < 1){
 			nbsend(job->donec, nil);
 			continue;
@@ -658,6 +677,8 @@
 		memset(params, 0, sizeof *params);
 		params->job = job;
 		sendp(paramsc, params);
+
+		job->times.R.t1 = nanosec();
 	}
 }