예제 #1
0
DEFINEFN
void psyco_stats_collect(void)
{
	/* collect statistics for all registered threads */
	PyInterpreterState* istate = PyThreadState_Get()->interp;
	PyThreadState* tstate;
	for (tstate=istate->tstate_head; tstate; tstate=tstate->next) {
		psyco_stats_append(tstate, tstate->frame);
	}
}
예제 #2
0
파일: profile.c 프로젝트: tonysimpson/ni
static PyObject* profile_call(PyFrameObject* frame, PyObject* arg)
{
	PyCodeStats* cs;
	psyco_stats_append(frame->f_tstate, frame->f_back);

	cs = PyCodeStats_Get(frame->f_code);
	if (cs->st_globals != NULL) {
		/* we want to accelerate this code object */
		if (cs->st_codebuf == NULL) {
			/* not already compiled, compile it now */
			PyObject* codebuf;
			PyObject* g = frame->f_globals;
			int rec, module;
			stats_printf(("stats: compile code:  %s\n",
				      PyCodeObject_NAME(frame->f_code)));
			if (PyInt_Check(cs->st_globals))
				rec = PyInt_AS_LONG(cs->st_globals);
			else
				rec = DEFAULT_RECURSION;
			module = frame->f_globals == frame->f_locals;
			codebuf = PsycoCode_CompileCode(frame->f_code,
							g, rec, module);
			/* rare race condition: 'cs' might have been mutated
			   during the call to PsycoCode_CompileCode(), so
			   cs->st_codebuf might no longer be NULL, or
			   cs->st_globals might be NULL again */
			Py_XDECREF(cs->st_codebuf);
			cs->st_codebuf = codebuf;
			if (cs->st_codebuf == Py_None)
				g = NULL;  /* failed */
			else {
				Py_INCREF(g);
				extra_assert
					(CodeBuffer_Check(cs->st_codebuf));
			}
			Py_XDECREF(cs->st_globals);
			cs->st_globals = g;
		}
		/* already compiled a Psyco version, run it
		   if the globals match */
		extra_assert(frame->f_globals != NULL);
		if (cs->st_globals == frame->f_globals) {
			Py_INCREF(cs->st_codebuf);
			return cs->st_codebuf;
		}
	}
	return NULL;
}
예제 #3
0
파일: profile.c 프로젝트: tonysimpson/ni
static PyObject* profile_return(PyFrameObject* frame, PyObject* arg)
{
	psyco_stats_append(frame->f_tstate, frame);
	return NULL;
}