reports microseconds in python profilers

This commit is contained in:
roberto@precise64
2012-03-31 15:48:22 +02:00
parent 3612ea2186
commit 878e9cb9ba
5 changed files with 49 additions and 2 deletions
+37 -2
View File
@@ -15,16 +15,28 @@ int PyFrame_GetLineNumber(PyFrameObject *frame) {
int uwsgi_python_profiler_call(PyObject *obj, PyFrameObject *frame, int what, PyObject *arg) {
static uint64_t last_ts = 0;
uint64_t now = uwsgi_micros();
uint64_t delta = 0;
#ifndef UWSGI_PYPY
switch(what) {
case PyTrace_CALL:
uwsgi_log("[uWSGI Python profiler] CALL: %s (line %d) -> %s %d args, stacksize %d\n",
if (last_ts == 0) delta = 0;
else delta = now - last_ts;
last_ts = now;
uwsgi_log("[uWSGI Python profiler %llu] CALL: %s (line %d) -> %s %d args, stacksize %d\n",
(unsigned long long) delta,
PyString_AsString(frame->f_code->co_filename),
PyFrame_GetLineNumber(frame),
PyString_AsString(frame->f_code->co_name), frame->f_code->co_argcount, frame->f_code->co_stacksize);
break;
case PyTrace_C_CALL:
uwsgi_log("[uWSGI Python profiler] C CALL: %s (line %d) -> %s %d args, stacksize %d\n",
if (last_ts == 0) delta = 0;
else delta = now - last_ts;
last_ts = now;
uwsgi_log("[uWSGI Python profiler %llu] C CALL: %s (line %d) -> %s %d args, stacksize %d\n",
(unsigned long long) delta,
PyString_AsString(frame->f_code->co_filename),
PyFrame_GetLineNumber(frame),
PyEval_GetFuncName(arg), frame->f_code->co_argcount, frame->f_code->co_stacksize);
@@ -34,3 +46,26 @@ int uwsgi_python_profiler_call(PyObject *obj, PyFrameObject *frame, int what, Py
return 0;
}
int uwsgi_python_tracer(PyObject *obj, PyFrameObject *frame, int what, PyObject *arg) {
static uint64_t last_ts = 0;
uint64_t now = uwsgi_micros();
uint64_t delta = 0;
#ifndef UWSGI_PYPY
if (what == PyTrace_LINE) {
if (last_ts == 0) {
delta = 0;
}
else {
delta = now - last_ts;
}
last_ts = now;
uwsgi_log("[uWSGI Python profiler %llu] file %s line %d: %s argc:%d\n", (unsigned long long)delta, PyString_AsString(frame->f_code->co_filename), PyFrame_GetLineNumber(frame), PyString_AsString(frame->f_code->co_name), frame->f_code->co_argcount);
}
#endif
return 0;
}
+3
View File
@@ -1081,6 +1081,9 @@ next:
if (!strcmp(uwsgi.profiler, "pycall")) {
PyEval_SetProfile(uwsgi_python_profiler_call, NULL);
}
else if (!strcmp(uwsgi.profiler, "pyline")) {
PyEval_SetTrace(uwsgi_python_tracer, NULL);
}
}
#endif
+1
View File
@@ -248,6 +248,7 @@ void simple_reset_ts(struct wsgi_request *, struct uwsgi_app *);
void simple_threaded_reset_ts(struct wsgi_request *, struct uwsgi_app *);
int uwsgi_python_profiler_call(PyObject *, PyFrameObject *, int, PyObject *);
int uwsgi_python_tracer(PyObject *, PyFrameObject *, int, PyObject *);
void uwsgi_python_reset_random_seed(void);