Why doesn't JUMP_IF_FALSE do POP_TOP ?

Bengt Richter bokr at oz.net
Mon Jan 13 14:05:54 EST 2003


On Mon, 13 Jan 2003 11:15:50 -0600, Skip Montanaro <skip at pobox.com> wrote:

>
>    Bengt> I.e., it should be simple to instrument ceval.c to extern link to
>    Bengt> a temp module with an integer array indexed by byte code value to
>    Bengt> increment for statistics.  
>
>You can already do this.  Simply define DYNAMIC_EXECUTION_PROFILES (and
>optionally DXPAIRS) when building Python.  I believe only ceval.c and
>sysmodule.c need to be rebuilt.  Once built, you can call sys.getdxp() at
>any time during program execution to retrieve the byte code execution
>frequency array.  If you define DXPAIRS as well as
>DYNAMIC_EXECUTION_PROFILES you get a 2-D list (list of lists) instead of a
>simple list identifying adjoining pairs of byte code instructions.  This is
>probably what you want for this task, as it will tell you how often a
>conditional jump is followed by a POP_TOP, not just how many POP_TOP
>instructions are executed.
I assume DXPAIRS would increment in a flat array int counts[256*256] (or maybe
[max_byte_code**2]). The list of lists would just be slices of that IWT. But
that's a detail. I kind of thought someone must have done it, but I didn't
realize it was a compile option. I guess I would have found it if I'd started
on doing it myself ;-)

Any old statistics on codes and pairs?

Oh BTW, has anyone instrumented tracking ref count patterns? I.e., how often
does an object just get +- vs ++-- or ++-+-- etc? My first idea on instrumenting
that was to have an open binary log file and doctor the Py_INCREF(op) and Py_DECREF(op)
macros to write the 4-byte id with an lsb of 1 or'ed in for incref, and then analyze afterwards.
Does that sound workable? Or has it been done some other way?

Regards,
Bengt Richter




More information about the Python-list mailing list