git: 9front

Download patch

ref: 05f4fb831c30b6d9511dabb41004ac60f65532c7
parent: 246079a5755b7af4bfb0e6b0a3a5b11ebb15055b
author: Jacob Moody <moody@posixcafe.org>
date: Sun Dec 7 20:13:58 EST 2025

libc: mark exits as profile-able

Exits had been marked as noprof, this was likely done because
there would be some noise added by _profdump itself (added as an onexit handler).
However, knowing if your atexit handlers are taking up a lot of time is useful,
and its possible to all but remove the impact by stopping the clock before we call things
like create and print.

--- a/sys/src/libc/port/exits.c
+++ b/sys/src/libc/port/exits.c
@@ -3,8 +3,6 @@
 
 void (*_onexit)(void);
 
-#pragma profile off
-
 _Noreturn void
 exits(char *s)
 {
--- a/sys/src/libc/port/profile.c
+++ b/sys/src/libc/port/profile.c
@@ -123,6 +123,7 @@
 	Plink *p;
 	char *vp;
 	char filename[64];
+	long pid;
 	uchar hdr[3+1+8] = {'p', 'r', 0x0f, 0x2};
 
 	if (_tos->prof.what == 0)
@@ -129,19 +130,11 @@
 		return;	/* No profiling */
 	if (_tos->prof.pid != 0 && _tos->pid != _tos->prof.pid)
 		return;	/* Not our process */
-	if(perr)
-		fprint(2, "%lud Prof errors\n", perr);
+	/* make sure data gets dumped once */
 	_tos->prof.pp = nil;
-	if (_tos->prof.pid)
-		snprint(filename, sizeof filename - 1, "prof.%ld", _tos->prof.pid);
-	else
-		snprint(filename, sizeof filename - 1, "prof.out");
-	f = create(filename, OWRITE|OCEXEC, 0666);
-	if(f < 0) {
-		perror("create prof.out");
-		return;
-	}
-	_tos->prof.pid = ~0;	/* make sure data gets dumped once */
+	pid = _tos->prof.pid;
+	_tos->prof.pid = ~0;
+	
 	switch(_tos->prof.what){
 	case Profkernel:
 		cycles((uvlong*)&_tos->prof.first->time);
@@ -158,6 +151,19 @@
 		_tos->prof.first->time = _tos->clock;
 		break;
 	}
+
+	if(perr)
+		fprint(2, "%lud Prof errors\n", perr);
+	if (pid)
+		snprint(filename, sizeof filename - 1, "prof.%ld", pid);
+	else
+		snprint(filename, sizeof filename - 1, "prof.out");
+	f = create(filename, OWRITE|OCEXEC, 0666);
+	if(f < 0) {
+		perror("create prof.out");
+		return;
+	}
+
 	hdr[4+0] = _tos->cyclefreq>>56;
 	hdr[4+1] = _tos->cyclefreq>>48;
 	hdr[4+2] = _tos->cyclefreq>>40;
--