[medusa] Re: tweaks to asyn{core,chat}.py

Sam Rushing rushing@n...
Sat, 20 Nov 1999 05:52:51 -0800 (PST)


Skip Montanaro writes:
> Have you sent this to Guido? A statistical profiler would be a
> nice complement to the regular (machine-eating) profiler. If you
> have a patch, I'd like to take a look at it. (I'd probably change
> the simple counter to a time accumulator the way gprof works.)

Warning: This code ignores reference-counting. (not that there's
anything wrong with that)... I've only used it once. I think it
could be very useful for long-running servers, where 'real' profiling
is tricky and expensive. This seems to me to have very low overhead;
especially if I "sys.setcheckinterval(1000)" rather than 10.

Python-1.5.2/Python/ceval.c:

379a380,384
> #ifdef STATISTICAL_PROFILING
> static PyObject * profiling = NULL;
> #endif
> 
> 
620a626,644
> #ifdef STATISTICAL_PROFILING
> if (!profiling) {
> profiling = PyDict_New();
> {
> PyObject * sys_module = PyDict_GetItemString (PyImport_GetModuleDict(), "sys");
> PyObject * sys_dict = PyModule_GetDict (sys_module);
> PyDict_SetItemString (sys_dict, "statistical_profiling_data", profiling);
> }
> }
> {
> PyObject * val = PyDict_GetItem (profiling, (PyObject *) co);
> if (!val) {
> PyDict_SetItem (profiling, (PyObject *) co, PyInt_FromLong (1));
> } else {
> PyDict_SetItem (profiling, (PyObject *) co, PyInt_FromLong (PyInt_AsLong (val) + 1));
> }
> }
> #endif
> 

> I've experienced cases where is sits for the timeout period
> (typically 30 seconds), then adds a fd that was in the read set to
> the write set as well (or was it the other way 'round?), after
> which the next select returns immediately.

You're saying there are two trips through poll() when there should be
one? Or did a socket not 'fire' when it should have?

-Sam