diff options
author | Guido van Rossum <guido@python.org> | 1997-01-24 13:49:28 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-01-24 13:49:28 (GMT) |
commit | 950361c6cad55cb452233cbfd3d224952b6e18f2 (patch) | |
tree | 7bb9c870558880df5c5d9ca2cc1887e5c2b59793 /Python | |
parent | 8c5df06ec7f11e5a219cc1457de2a962ec6925c7 (diff) | |
download | cpython-950361c6cad55cb452233cbfd3d224952b6e18f2.zip cpython-950361c6cad55cb452233cbfd3d224952b6e18f2.tar.gz cpython-950361c6cad55cb452233cbfd3d224952b6e18f2.tar.bz2 |
Patches for (two forms of) optional dynamic execution profiling --
i.e., counting opcode frequencies, or (with DXPAIRS defined) opcode
pair frequencies. Define DYNAMIC_EXECUTION_PROFILE on the command
line (for this file and for sysmodule.c) to enable.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 5b97244..246b9a4 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -103,6 +103,17 @@ static int exec_statement PROTO((object *, object *, object *)); static object *find_from_args PROTO((frameobject *, int)); +/* Dynamic execution profile */ +#ifdef DYNAMIC_EXECUTION_PROFILE +#ifdef DXPAIRS +static long dxpairs[257][256]; +#define dxp dxpairs[256] +#else +static long dxp[256]; +#endif +#endif + + /* Pointer to current frame, used to link new frames to */ static frameobject *current_frame; @@ -315,6 +326,9 @@ eval_code2(co, globals, locals, int defcount; object *owner; { +#ifdef DXPAIRS + int lastopcode = 0; +#endif register unsigned char *next_instr; register int opcode = 0; /* Current opcode */ register int oparg = 0; /* Current opcode argument, if any */ @@ -592,6 +606,13 @@ eval_code2(co, globals, locals, opcode = NEXTOP(); if (HAS_ARG(opcode)) oparg = NEXTARG(); +#ifdef DYNAMIC_EXECUTION_PROFILE +#ifdef DXPAIRS + dxpairs[lastopcode][opcode]++; + lastopcode = opcode; +#endif + dxp[opcode]++; +#endif #ifdef LLTRACE /* Instruction tracing */ @@ -2961,3 +2982,50 @@ find_from_args(f, nexti) return list; } + + +#ifdef DYNAMIC_EXECUTION_PROFILE + +PyObject * +getarray(a) + long a[256]; +{ + int i; + PyObject *l = PyList_New(256); + if (l == NULL) return NULL; + for (i = 0; i < 256; i++) { + PyObject *x = PyInt_FromLong(a[i]); + if (x == NULL) { + Py_DECREF(l); + return NULL; + } + PyList_SetItem(l, i, x); + } + for (i = 0; i < 256; i++) + a[i] = 0; + return l; +} + +PyObject * +_Py_GetDXProfile(self, args) + PyObject *self, *args; +{ +#ifndef DXPAIRS + return getarray(dxp); +#else + int i; + PyObject *l = PyList_New(257); + if (l == NULL) return NULL; + for (i = 0; i < 257; i++) { + PyObject *x = getarray(dxpairs[i]); + if (x == NULL) { + Py_DECREF(l); + return NULL; + } + PyList_SetItem(l, i, x); + } + return l; +#endif +} + +#endif |