mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 12:39:01 -04:00
make coro tracing available at runtime, always.
call kore.corotrace(True) to enable it and kore.corotrace(False) to disable.
This commit is contained in:
parent
95506204e8
commit
868b0a71a2
3
Makefile
3
Makefile
@ -96,9 +96,6 @@ ifneq ("$(JSONRPC)", "")
|
||||
endif
|
||||
|
||||
ifneq ("$(PYTHON)", "")
|
||||
ifneq ("$(DEBUG)", "")
|
||||
CFLAGS+=-DPYTHON_CORO_TRACE
|
||||
endif
|
||||
S_SRC+=src/python.c
|
||||
KORE_PYTHON_LIB?=$(shell python3-config --ldflags)
|
||||
KORE_PYTHON_INC?=$(shell python3-config --includes)
|
||||
|
@ -22,9 +22,7 @@ struct python_coro {
|
||||
int state;
|
||||
int killed;
|
||||
PyObject *obj;
|
||||
#if defined(PYTHON_CORO_TRACE)
|
||||
char *name;
|
||||
#endif
|
||||
PyObject *result;
|
||||
struct pysocket_op *sockop;
|
||||
struct pygather_op *gatherop;
|
||||
@ -51,6 +49,7 @@ static PyObject *python_kore_setname(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_suspend(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_shutdown(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_coroname(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_corotrace(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_bind_unix(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_task_kill(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_prerequest(PyObject *, PyObject *);
|
||||
@ -93,6 +92,7 @@ static struct PyMethodDef pykore_methods[] = {
|
||||
METHOD("suspend", python_kore_suspend, METH_VARARGS),
|
||||
METHOD("shutdown", python_kore_shutdown, METH_NOARGS),
|
||||
METHOD("coroname", python_kore_coroname, METH_VARARGS),
|
||||
METHOD("corotrace", python_kore_corotrace, METH_VARARGS),
|
||||
METHOD("task_kill", python_kore_task_kill, METH_VARARGS),
|
||||
METHOD("bind_unix", python_kore_bind_unix, METH_VARARGS),
|
||||
METHOD("prerequest", python_kore_prerequest, METH_VARARGS),
|
||||
|
40
src/python.c
40
src/python.c
@ -40,9 +40,7 @@
|
||||
#include "python_api.h"
|
||||
#include "python_methods.h"
|
||||
|
||||
#if defined(PYTHON_CORO_TRACE)
|
||||
#include <frameobject.h>
|
||||
#endif
|
||||
|
||||
struct reqcall {
|
||||
PyObject *f;
|
||||
@ -67,10 +65,7 @@ static struct python_coro *python_coro_create(PyObject *,
|
||||
static int python_coro_run(struct python_coro *);
|
||||
static void python_coro_wakeup(struct python_coro *);
|
||||
static void python_coro_suspend(struct python_coro *);
|
||||
|
||||
#if defined(PYTHON_CORO_TRACE)
|
||||
static void python_coro_trace(const char *, struct python_coro *);
|
||||
#endif
|
||||
|
||||
static void pysocket_evt_handle(void *, int);
|
||||
static void pysocket_op_timeout(void *, u_int64_t);
|
||||
@ -206,6 +201,7 @@ static struct kore_pool gather_result_pool;
|
||||
|
||||
static u_int64_t coro_id;
|
||||
static int coro_count;
|
||||
static int coro_tracing;
|
||||
static struct coro_list coro_runnable;
|
||||
static struct coro_list coro_suspended;
|
||||
|
||||
@ -226,6 +222,7 @@ kore_python_init(void)
|
||||
|
||||
coro_id = 0;
|
||||
coro_count = 0;
|
||||
coro_tracing = 0;
|
||||
|
||||
TAILQ_INIT(&prereq);
|
||||
|
||||
@ -320,9 +317,7 @@ kore_python_coro_delete(void *obj)
|
||||
coro = obj;
|
||||
coro_count--;
|
||||
|
||||
#if defined(PYTHON_CORO_TRACE)
|
||||
python_coro_trace(coro->killed ? "killed" : "deleted", coro);
|
||||
#endif
|
||||
|
||||
coro_running = coro;
|
||||
Py_DECREF(coro->obj);
|
||||
@ -333,9 +328,7 @@ kore_python_coro_delete(void *obj)
|
||||
else
|
||||
TAILQ_REMOVE(&coro_suspended, coro, list);
|
||||
|
||||
#if defined(PYTHON_CORO_TRACE)
|
||||
kore_free(coro->name);
|
||||
#endif
|
||||
Py_XDECREF(coro->result);
|
||||
|
||||
kore_pool_put(&coro_pool, coro);
|
||||
@ -557,9 +550,7 @@ python_coro_create(PyObject *obj, struct http_request *req)
|
||||
coro = kore_pool_get(&coro_pool);
|
||||
coro_count++;
|
||||
|
||||
#if defined(PYTHON_CORO_TRACE)
|
||||
coro->name = NULL;
|
||||
#endif
|
||||
coro->result = NULL;
|
||||
coro->sockop = NULL;
|
||||
coro->gatherop = NULL;
|
||||
@ -577,9 +568,7 @@ python_coro_create(PyObject *obj, struct http_request *req)
|
||||
if (coro->request != NULL)
|
||||
http_request_sleep(coro->request);
|
||||
|
||||
#if defined(PYTHON_CORO_TRACE)
|
||||
python_coro_trace("created", coro);
|
||||
#endif
|
||||
|
||||
return (coro);
|
||||
}
|
||||
@ -596,9 +585,7 @@ python_coro_run(struct python_coro *coro)
|
||||
coro_running = coro;
|
||||
|
||||
for (;;) {
|
||||
#if defined(PYTHON_CORO_TRACE)
|
||||
python_coro_trace("running", coro);
|
||||
#endif
|
||||
|
||||
PyErr_Clear();
|
||||
item = _PyGen_Send((PyGenObject *)coro->obj, NULL);
|
||||
@ -643,9 +630,7 @@ python_coro_wakeup(struct python_coro *coro)
|
||||
TAILQ_REMOVE(&coro_suspended, coro, list);
|
||||
TAILQ_INSERT_TAIL(&coro_runnable, coro, list);
|
||||
|
||||
#if defined(PYTHON_CORO_TRACE)
|
||||
python_coro_trace("wokeup", coro);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
@ -658,12 +643,9 @@ python_coro_suspend(struct python_coro *coro)
|
||||
TAILQ_REMOVE(&coro_runnable, coro, list);
|
||||
TAILQ_INSERT_TAIL(&coro_suspended, coro, list);
|
||||
|
||||
#if defined(PYTHON_CORO_TRACE)
|
||||
python_coro_trace("suspended", coro);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(PYTHON_CORO_TRACE)
|
||||
static void
|
||||
python_coro_trace(const char *label, struct python_coro *coro)
|
||||
{
|
||||
@ -672,6 +654,9 @@ python_coro_trace(const char *label, struct python_coro *coro)
|
||||
PyCodeObject *code;
|
||||
const char *func, *fname, *file;
|
||||
|
||||
if (coro_tracing == 0)
|
||||
return;
|
||||
|
||||
gen = (PyGenObject *)coro->obj;
|
||||
|
||||
if (gen->gi_frame != NULL && gen->gi_frame->f_code != NULL) {
|
||||
@ -701,7 +686,6 @@ python_coro_trace(const char *label, struct python_coro *coro)
|
||||
coro->id, label, func, fname, line);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
pyconnection_dealloc(struct pyconnection *pyc)
|
||||
@ -1567,7 +1551,6 @@ python_kore_shutdown(PyObject *self, PyObject *args)
|
||||
static PyObject *
|
||||
python_kore_coroname(PyObject *self, PyObject *args)
|
||||
{
|
||||
#if defined(PYTHON_CORO_TRACE)
|
||||
const char *name;
|
||||
|
||||
if (coro_running == NULL) {
|
||||
@ -1581,7 +1564,18 @@ python_kore_coroname(PyObject *self, PyObject *args)
|
||||
|
||||
kore_free(coro_running->name);
|
||||
coro_running->name = kore_strdup(name);
|
||||
#endif
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
python_kore_corotrace(PyObject *self, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "b", &coro_tracing))
|
||||
return (NULL);
|
||||
|
||||
printf("coro tracing is now %d\n", coro_tracing);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user