ref: 4791763ce783395609a7594d51c293b53404b636
dir: /ape-prof/
diff 14d4c7d7ba8b347739e7b1fbf2eb4b5eeec85762 uncommitted
--- a/sys/src/ape/lib/ap/plan9/_envsetup.c
+++ b/sys/src/ape/lib/ap/plan9/_envsetup.c
@@ -27,6 +27,8 @@
Envhunk=7000,
};
+#pragma profile off
+
void
_envsetup(void)
{
@@ -134,3 +136,5 @@
_sighdlr[sig] = SIG_IGN;
}
}
+
+#pragma profile on
--- a/sys/src/ape/lib/ap/plan9/profile.c
+++ b/sys/src/ape/lib/ap/plan9/profile.c
@@ -18,6 +18,7 @@
typedef long long vlong;
typedef unsigned long ulong;
typedef unsigned long long uvlong;
+typedef unsigned char uchar;
#include "/sys/include/tos.h"
@@ -26,7 +27,10 @@
extern void* _saveret(void);
extern void* _savearg(void);
extern void _cycles(uvlong*); /* 64-bit value of the cycle counter if there is one, 0 if there isn't */
+extern void _envsetup(void);
+extern char **environ;
+
static ulong khz;
static ulong perr;
static int havecycles;
@@ -164,10 +168,11 @@
_profdump(void)
{
int f;
- long n;
+ vlong n;
Plink *p;
char *vp;
char filename[64];
+ uchar hdr[3+1+8] = {'p', 'r', 0x0f, 0x2};
if (_tos->prof.what == 0)
return; /* No profiling */
@@ -202,8 +207,17 @@
_tos->prof.first->time = _tos->clock;
break;
}
+ hdr[4+0] = _tos->cyclefreq>>56;
+ hdr[4+1] = _tos->cyclefreq>>48;
+ hdr[4+2] = _tos->cyclefreq>>40;
+ hdr[4+3] = _tos->cyclefreq>>32;
+ hdr[4+4] = _tos->cyclefreq>>24;
+ hdr[4+5] = _tos->cyclefreq>>16;
+ hdr[4+6] = _tos->cyclefreq>>8;
+ hdr[4+7] = _tos->cyclefreq;
+ write(f, hdr, sizeof hdr);
+
vp = (char*)_tos->prof.first;
-
for(p = _tos->prof.first; p <= _tos->prof.next; p++) {
/*
@@ -248,16 +262,16 @@
/*
* vlong time
*/
- if (havecycles){
- n = (vlong)(p->time / (vlong)khz);
- }else
- n = p->time;
-
- vp[0] = n>>24;
- vp[1] = n>>16;
- vp[2] = n>>8;
- vp[3] = n;
- vp += 4;
+ n = p->time;
+ vp[0] = n>>56;
+ vp[1] = n>>48;
+ vp[2] = n>>40;
+ vp[3] = n>>32;
+ vp[4] = n>>24;
+ vp[5] = n>>16;
+ vp[6] = n>>8;
+ vp[7] = n;
+ vp += 8;
}
write(f, (char*)_tos->prof.first, vp - (char*)_tos->prof.first);
close(f);
@@ -283,11 +297,7 @@
char ename[50];
int n, f;
- n = 2000;
- if (_tos->cyclefreq != 0LL){
- khz = _tos->cyclefreq / 1000; /* Report times in milliseconds */
- havecycles = 1;
- }
+ n = 256*1024;
f = open("/env/profsize", OREAD|OCEXEC);
if(f >= 0) {
memset(ename, 0, sizeof(ename));
@@ -310,6 +320,7 @@
else if (strcmp(ename, "sample") == 0)
_tos->prof.what = Profsample;
}
+ _envsetup();
_tos->prof.first = sbrk(n*sizeof(Plink));
_tos->prof.last = sbrk(0);
_tos->prof.next = _tos->prof.first;
@@ -318,8 +329,8 @@
atexit(_profdump);
_tos->clock = 1;
_tos->prof.pp = _tos->prof.next;
- extern int _apemain(int, char**);
- return _apemain(argc, argv);
+ extern int main(int, char**, char**);
+ return main(argc, argv, environ);
}
void prof(void (*fn)(void*), void *arg, int entries, int what)
--- a/sys/src/ape/lib/ap/stdio/_IO_putc.c
+++ b/sys/src/ape/lib/ap/stdio/_IO_putc.c
@@ -3,9 +3,11 @@
*/
#include "iolib.h"
+#pragma profile off
void _IO_cleanup(void){
fflush(NULL);
}
+#pragma profile on
/*
* Look this over for simplification
*/
--- a/sys/src/ape/lib/ap/stdio/exit.c
+++ b/sys/src/ape/lib/ap/stdio/exit.c
@@ -1,4 +1,7 @@
#include <unistd.h>
+
+#pragma profile off
+
#define NONEXIT 34
int (*_atexitfns[NONEXIT])(void);
void _doatexits(void){
@@ -15,3 +18,5 @@
_doatexits();
_exit(status);
}
+
+#pragma profile on