Posted to tcl by miguel at Fri Oct 26 02:07:27 GMT 2007view raw

  1. Index: tclExecute.c
  2. ===================================================================
  3. RCS file: /cvsroot/tcl/tcl/generic/tclExecute.c,v
  4. retrieving revision 1.339
  5. diff -u -r1.339 tclExecute.c
  6. --- tclExecute.c 20 Oct 2007 02:15:05 -0000 1.339
  7. +++ tclExecute.c 26 Oct 2007 02:05:59 -0000
  8. @@ -9,6 +9,7 @@
  9. * Copyright (c) 2002-2005 by Miguel Sofer.
  10. * Copyright (c) 2005-2007 by Donal K. Fellows.
  11. * Copyright (c) 2007 Daniel A. Steffen <das@users.sourceforge.net>
  12. + * Copyright (c) 2007 George Peter Staplin.
  13. *
  14. * See the file "license.terms" for information on usage and redistribution of
  15. * this file, and for a DISCLAIMER OF ALL WARRANTIES.
  16. @@ -23,6 +24,8 @@
  17. #include <math.h>
  18. #include <float.h>
  19.  
  20. +#define TCL_VM_TIME_TABLE 1
  21. +
  22. /*
  23. * Hack to determine whether we may expect IEEE floating point. The hack is
  24. * formally incorrect in that non-IEEE platforms might have the same precision
  25. @@ -1498,6 +1501,37 @@
  26. Tcl_SetBignumObj(valuePtr, &value);
  27. return TCL_OK;
  28. }
  29. +
  30. +#ifdef TCL_VM_TIME_TABLE
  31. +
  32. +static int timeTableReady = 0;
  33. +static Tcl_WideInt childClicks = 0;
  34. +static struct {
  35. + Tcl_WideInt instCount;
  36. + Tcl_WideInt instTotalTime;
  37. +} timeTable[LAST_INST_OPCODE + 1];
  38. +
  39. +static void
  40. +DumpTimeTable(void) {
  41. + int i;
  42. + FILE *fp;
  43. +
  44. + fp = fopen("time.log", "a");
  45. + if (NULL == fp) {
  46. + perror("fopen");
  47. + return;
  48. + }
  49. +
  50. + for (i = 0; i <= LAST_INST_OPCODE; ++i) {
  51. + if (timeTable[i].instTotalTime) {
  52. + fprintf(fp, "%d %lld %lld\n", i, timeTable[i].instTotalTime,
  53. + timeTable[i].instCount);
  54. + }
  55. + }
  56. + fprintf(fp, "- -\n");
  57. +}
  58. +#endif
  59. +
  60.  
  61. /*
  62. *----------------------------------------------------------------------
  63. @@ -1529,6 +1563,10 @@
  64. */
  65. #define iPtr ((Interp *) interp)
  66.  
  67. +#ifdef TCL_VM_TIME_TABLE
  68. + int lastInstruction = -1;
  69. + Tcl_WideInt before = 0, clicks, startClicks = 0;
  70. +#endif
  71. /*
  72. * Constants: variables that do not change during the execution, used
  73. * sporadically.
  74. @@ -1634,6 +1672,20 @@
  75. namespacePtr = iPtr->varFramePtr->nsPtr;
  76. compiledLocals = iPtr->varFramePtr->compiledLocals;
  77.  
  78. +
  79. +#if TCL_VM_TIME_TABLE
  80. + if (!timeTableReady) {
  81. + int i;
  82. + for (i = 0; i <= LAST_INST_OPCODE; ++i) {
  83. + timeTable[i].instCount = timeTable[i].instTotalTime = 0;
  84. + }
  85. + timeTableReady = 1;
  86. + if (atexit(DumpTimeTable))
  87. + perror("atexit");
  88. + }
  89. +#endif
  90. +
  91. +
  92. /*
  93. * Loop executing instructions until a "done" instruction, a TCL_RETURN,
  94. * or some error.
  95. @@ -1758,6 +1810,20 @@
  96. }
  97. }
  98.  
  99. +
  100. +#ifdef TCL_VM_TIME_TABLE
  101. + clicks = TclpGetClicks();
  102. + if (before && (-1 != lastInstruction)) {
  103. + timeTable[lastInstruction].instTotalTime += clicks - before - childClicks;
  104. + timeTable[lastInstruction].instCount++;
  105. + } else {
  106. + startClicks = clicks;
  107. + }
  108. + childClicks = 0;
  109. + before = clicks;
  110. + lastInstruction = *pc;
  111. +#endif
  112. +
  113. /*
  114. * These two instructions account for 26% of all instructions (according
  115. * to measurements on tclbench by Ben Vitale
  116. @@ -1772,7 +1838,7 @@
  117. } else if (*pc == INST_PUSH1) {
  118. goto instPush1Peephole;
  119. }
  120. -
  121. +
  122. switch (*pc) {
  123. case INST_SYNTAX:
  124. case INST_RETURN_IMM: {
  125. @@ -7069,6 +7135,15 @@
  126. }
  127. }
  128.  
  129. +#ifdef TCL_VM_TIME_TABLE
  130. + clicks = TclpGetClicks();
  131. + if (before && (-1 != lastInstruction)) {
  132. + timeTable[lastInstruction].instTotalTime += clicks - before - childClicks;
  133. + timeTable[lastInstruction].instCount++;
  134. + }
  135. + childClicks = TclpGetClicks() - startClicks;
  136. +#endif
  137. +
  138. /*
  139. * Restore the stack to the state it had previous to this bytecode.
  140. */