Exemplo n.º 1
0
DEFINEFN
PyCodeStats* PyCodeStats_MaybeGet(PyCodeObject* co)
{
	PyCodeStats* cs;
	RECLIMIT_SAFE_ENTER();
	cs = (PyCodeStats*) PyCStruct_DictGet(codestats_dict, (PyObject*) co);
	RECLIMIT_SAFE_LEAVE();
	return cs;
}
Exemplo n.º 2
0
DEFINEFN
void psyco_stats_reset(void)
{
	/* reset all stats */
	int i = 0;
	PyObject *key, *value, *d;
	stats_printf(("stats: reset\n"));

	/* reset the charge of all PyCodeStats, keep only the used ones */
        RECLIMIT_SAFE_ENTER();
	d = PyDict_New();
	if (d == NULL)
		OUT_OF_MEMORY();
	while (PyDict_Next(codestats_dict, &i, &key, &value)) {
		PyCodeStats* cs = (PyCodeStats*) key;
		if (cs->st_mergepoints) {
			/* clear the charge and keep alive */
			cs->st_charge = 0.0f;
			if (PyDict_SetItem(d, key, value))
				OUT_OF_MEMORY();
		}
	}
        RECLIMIT_SAFE_LEAVE();
	Py_DECREF(codestats_dict);
	codestats_dict = d;
	charge_total = 0.0;
	charge_prelimit = 0.0f;

	/* reset the time measure in all threads */
	{
#if MEASURE_ALL_THREADS
		PyInterpreterState* istate = PyThreadState_Get()->interp;
		PyThreadState* tstate;
		for (tstate=istate->tstate_head; tstate; tstate=tstate->next) {
			(void) get_measure(tstate);
		}
#else
		(void) get_measure(NULL);
#endif
	}
}
Exemplo n.º 3
0
static ceval_events_t* new_cevents(PyThreadState* tstate)
{
	ceval_events_t* cev;
	PyObject* dict = tstate->dict;

        RECLIMIT_SAFE_ENTER();
	if (dict == NULL) {
		dict = tstate->dict = PyDict_New();
		if (dict == NULL)
			OUT_OF_MEMORY();
	}
	cev = PyCStruct_NEW(ceval_events_t, ceval_events_dealloc);
	/*cev->lock = PyThread_allocate_lock();*/
	memset(cev->events, 0, sizeof(cev->events));
	cev->tstate = tstate;
	cev->events_total = 0;
	cev->current_hook = 0;
	if (PyDict_SetItem(dict, ceval_events_key, (PyObject*) cev))
		OUT_OF_MEMORY();
        RECLIMIT_SAFE_LEAVE();
	Py_DECREF(cev);  /* one ref left in dict */
	return cev;
}
Exemplo n.º 4
0
DEFINEFN
PyCodeStats* PyCodeStats_Get(PyCodeObject* co)
{
	PyCodeStats* cs;
	RECLIMIT_SAFE_ENTER();
	cs = (PyCodeStats*) PyCStruct_DictGet(codestats_dict, (PyObject*) co);
	if (cs == NULL) {
		cs = PyCStruct_NEW(PyCodeStats, PyCodeStats_dealloc);

		Py_INCREF(co);
		cs->cs_key = (PyObject*) co;
		cs->st_charge = 0.0f;
		cs->st_mergepoints = NULL;
                cs->st_codebuf = NULL;
                cs->st_globals = NULL;

		if (PyDict_SetItem(codestats_dict, (PyObject*) cs,
				   (PyObject*) cs) < 0)
			OUT_OF_MEMORY();
		Py_DECREF(cs);  /* two references left in codestats_dict */
	}
	RECLIMIT_SAFE_LEAVE();
	return cs;
}