diff --git a/byterun/Makefile b/byterun/Makefile index 68aa02e7c..1f99d9c87 100644 --- a/byterun/Makefile +++ b/byterun/Makefile @@ -1,7 +1,7 @@ include ../config/Makefile CC=$(BYTECC) -CFLAGS=-O $(BYTECCCOMPOPTS) +CFLAGS=-O $(BYTECCCOMPOPTS) -DBC_PROFILE DFLAGS=-g -DDEBUG $(BYTECCCOMPOPTS) OBJS=interp.o misc.o stacks.o fix_code.o startup.o main.o \ diff --git a/byterun/config.h b/byterun/config.h index f93f2f444..a212b296b 100644 --- a/byterun/config.h +++ b/byterun/config.h @@ -36,7 +36,7 @@ /* We use threaded code interpretation if the compiler provides labels as first-class values (GCC 2.x). */ -#if defined(__GNUC__) && __GNUC__ >= 2 && !defined(DEBUG) +#if defined(__GNUC__) && __GNUC__ >= 2 && !defined(DEBUG) && !defined(BC_PROFILE) #define THREADED_CODE #endif diff --git a/byterun/interp.c b/byterun/interp.c index 487f849d1..0b60954bd 100644 --- a/byterun/interp.c +++ b/byterun/interp.c @@ -173,6 +173,12 @@ value interprete(prog, prog_size) Assert(sp >= stack_low); Assert(sp <= stack_high); #endif +#if BC_PROFILE + { + extern unsigned long bc_counts []; + ++ bc_counts [*pc]; + } +#endif /* BC_PROFILE */ switch(*pc++) { #endif diff --git a/byterun/startup.c b/byterun/startup.c index 1388c4a48..599eb784e 100644 --- a/byterun/startup.c +++ b/byterun/startup.c @@ -129,6 +129,21 @@ Algorithm: extern void init_ieee_floats(); +#ifdef BC_PROFILE +unsigned long bc_counts [128]; +void savecounts () +{ + char *countfilename = getenv ("CAML_BC_COUNTFILE"); + + if (countfilename != NULL){ + FILE *countfile = fopen (countfilename, "w"); + if (countfile != NULL){ + fwrite (bc_counts, sizeof (unsigned long), 128, countfile); + } + } +} +#endif /* BC_PROFILE */ + void caml_main(argc, argv) int argc; char ** argv; @@ -150,6 +165,22 @@ void caml_main(argc, argv) verbose_init = 1; #endif +#ifdef BC_PROFILE + { + char *countfilename = getenv ("CAML_BC_COUNTFILE"); + int i; + + if (countfilename != NULL){ + FILE *countfile = fopen (countfilename, "r"); + for (i = 0; i < 128; i++) bc_counts [i] = 0; + if (countfile != NULL){ + fread (bc_counts, sizeof (unsigned long), 128, countfile); + } + } + atexit (savecounts); + } +#endif /* BC_PROFILE */ + i = 0; fd = attempt_open(&argv[0], &trail, 0);