Title: Tiny profiling info (Psyco #2)
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: mwh Nosy List: arigo, gvanrossum, mwh
Priority: normal Keywords: patch

Created on 2002-10-01 23:20 by arigo, last changed 2002-11-08 12:56 by mwh. This issue is now closed.

File name Uploaded Description Edit
diff-2.2 arigo, 2002-10-01 23:20 context diff against the 2.2 branch
diff-2.3 arigo, 2002-10-07 14:17 context diff for the cvs trunk
diff arigo, 2002-10-09 13:20 updated context diff for 2.3
Messages (8)
msg41287 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2002-10-01 23:20
Psyco-friendly patch #2.

A very very small statistic-collecting patch.

pystate.h: added a field at the end of the

    int tick_counter;

ceval.c: eval_frame():

    tstate->tick_counter is incremented whenever the
    check_interval ticker reaches zero.

The purpose is to give a useful measure of the number
of interpreted
bytecode instructions in a given thread.  This
extremely lightweight
statistic collector can be of interest to profilers
(like psyco.jit()).

We can safely guess that a single integer increment
every 100
interpreted bytecode instructions will go entierely
in any performance measure. [This is true for]
msg41288 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2002-10-04 10:42
Logged In: YES 

I see no harm in this.

Are you sure it's actually going to be useful, though?
msg41289 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2002-10-04 14:36
Logged In: YES 

It is the only way I could work out so far that can
"predict" how much a function will be accelerated when run
under Psyco.  This is a very precious indication for an
automatic Psyco-binder.  The following table shows the
results with the various test functions of the
distribution's "" file:

(fn name)     (speed-up)  (bytecode insns per second)
f1              106.00         
f4              11.33          
f5              12.08          
f6              1.35           
f7              2.24           
f7bis           10.29          

The third column is '(tick_counter * check_interval) /
execution_time'.  The correlation between the two columns is
admittedly not perfect, but still we can see that it was not
worthy to try and accelerate f6 because it didn't spend a
lot of time actually interpreting bytecodes.

Note that similar information could be obtained by setting a
line-tracing hook, counting not instructions but lines
(which is less precise but still a good approximation). 
However, line tracing is *much* too slow for anything but
debugging usage.
msg41290 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-10-06 20:45
Logged In: YES 

I'd like to get this into 2.2.2. MWH, can you check it in?
msg41291 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2002-10-07 09:42
Logged In: YES 

Done in

Include/pystate.h revision
Python/ceval.c revision 2.301.4.7

Armin, I don't know how you generated this patch, but it
would have been easier to apply if it had been rooted in the
"src" directory, like e.g.:

$ cvs diff Include/pystate.h Python/ceval.c > ~/diff

msg41292 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2002-10-07 14:17
Logged In: YES 

Uploaded the 2.3 patch (this one cleanly generated -- for the 
other one I just cat'ed two patches in one).
msg41293 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2002-10-09 13:20
Logged In: YES 

Attached an updated diff for 2.3.  This one doesn't have
Windows line endings and includes the initialization of
tick_counter to 0 that was added by Guido in the latest
2.2.2.  (I thought it was unnecessary to initialize it to
anything because profilers would only be interested in
msg41294 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2002-11-08 12:56
Logged In: YES 

I got lazy and checked in all the psyco patches at once:

Include/pystate.h revision 2.21
Modules/pyexpat.c revision 2.76
Python/ceval.c revision 2.340
Python/pystate.c revision 2.22
Date User Action Args
2002-10-01 23:20:54arigocreate