Posted to tcl by miguel at Fri Oct 26 02:07:27 GMT 2007view raw
- Index: tclExecute.c
- ===================================================================
- RCS file: /cvsroot/tcl/tcl/generic/tclExecute.c,v
- retrieving revision 1.339
- diff -u -r1.339 tclExecute.c
- --- tclExecute.c 20 Oct 2007 02:15:05 -0000 1.339
- +++ tclExecute.c 26 Oct 2007 02:05:59 -0000
- @@ -9,6 +9,7 @@
- * Copyright (c) 2002-2005 by Miguel Sofer.
- * Copyright (c) 2005-2007 by Donal K. Fellows.
- * Copyright (c) 2007 Daniel A. Steffen <das@users.sourceforge.net>
- + * Copyright (c) 2007 George Peter Staplin.
- *
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
- @@ -23,6 +24,8 @@
- #include <math.h>
- #include <float.h>
- +#define TCL_VM_TIME_TABLE 1
- +
- /*
- * Hack to determine whether we may expect IEEE floating point. The hack is
- * formally incorrect in that non-IEEE platforms might have the same precision
- @@ -1498,6 +1501,37 @@
- Tcl_SetBignumObj(valuePtr, &value);
- return TCL_OK;
- }
- +
- +#ifdef TCL_VM_TIME_TABLE
- +
- +static int timeTableReady = 0;
- +static Tcl_WideInt childClicks = 0;
- +static struct {
- + Tcl_WideInt instCount;
- + Tcl_WideInt instTotalTime;
- +} timeTable[LAST_INST_OPCODE + 1];
- +
- +static void
- +DumpTimeTable(void) {
- + int i;
- + FILE *fp;
- +
- + fp = fopen("time.log", "a");
- + if (NULL == fp) {
- + perror("fopen");
- + return;
- + }
- +
- + for (i = 0; i <= LAST_INST_OPCODE; ++i) {
- + if (timeTable[i].instTotalTime) {
- + fprintf(fp, "%d %lld %lld\n", i, timeTable[i].instTotalTime,
- + timeTable[i].instCount);
- + }
- + }
- + fprintf(fp, "- -\n");
- +}
- +#endif
- +
- /*
- *----------------------------------------------------------------------
- @@ -1529,6 +1563,10 @@
- */
- #define iPtr ((Interp *) interp)
- +#ifdef TCL_VM_TIME_TABLE
- + int lastInstruction = -1;
- + Tcl_WideInt before = 0, clicks, startClicks = 0;
- +#endif
- /*
- * Constants: variables that do not change during the execution, used
- * sporadically.
- @@ -1634,6 +1672,20 @@
- namespacePtr = iPtr->varFramePtr->nsPtr;
- compiledLocals = iPtr->varFramePtr->compiledLocals;
- +
- +#if TCL_VM_TIME_TABLE
- + if (!timeTableReady) {
- + int i;
- + for (i = 0; i <= LAST_INST_OPCODE; ++i) {
- + timeTable[i].instCount = timeTable[i].instTotalTime = 0;
- + }
- + timeTableReady = 1;
- + if (atexit(DumpTimeTable))
- + perror("atexit");
- + }
- +#endif
- +
- +
- /*
- * Loop executing instructions until a "done" instruction, a TCL_RETURN,
- * or some error.
- @@ -1758,6 +1810,20 @@
- }
- }
- +
- +#ifdef TCL_VM_TIME_TABLE
- + clicks = TclpGetClicks();
- + if (before && (-1 != lastInstruction)) {
- + timeTable[lastInstruction].instTotalTime += clicks - before - childClicks;
- + timeTable[lastInstruction].instCount++;
- + } else {
- + startClicks = clicks;
- + }
- + childClicks = 0;
- + before = clicks;
- + lastInstruction = *pc;
- +#endif
- +
- /*
- * These two instructions account for 26% of all instructions (according
- * to measurements on tclbench by Ben Vitale
- @@ -1772,7 +1838,7 @@
- } else if (*pc == INST_PUSH1) {
- goto instPush1Peephole;
- }
- -
- +
- switch (*pc) {
- case INST_SYNTAX:
- case INST_RETURN_IMM: {
- @@ -7069,6 +7135,15 @@
- }
- }
- +#ifdef TCL_VM_TIME_TABLE
- + clicks = TclpGetClicks();
- + if (before && (-1 != lastInstruction)) {
- + timeTable[lastInstruction].instTotalTime += clicks - before - childClicks;
- + timeTable[lastInstruction].instCount++;
- + }
- + childClicks = TclpGetClicks() - startClicks;
- +#endif
- +
- /*
- * Restore the stack to the state it had previous to this bytecode.
- */