~ubuntu-branches/ubuntu/saucy/uwsgi/saucy

« back to all changes in this revision

Viewing changes to plugins/python/profiler.c

  • Committer: Package Import Robot
  • Author(s): Janos Guljas
  • Date: 2012-04-30 17:35:22 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20120430173522-qucwu1au3s9bflhb
Tags: 1.2+dfsg-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
int uwsgi_python_profiler_call(PyObject *obj, PyFrameObject *frame, int what, PyObject *arg) {
17
17
 
18
18
#ifndef UWSGI_PYPY
 
19
        static uint64_t last_ts = 0;
 
20
        uint64_t now = uwsgi_micros();
 
21
        uint64_t delta = 0;
 
22
 
19
23
        switch(what) {
20
24
                case PyTrace_CALL:
21
 
                        uwsgi_log("[uWSGI Python profiler] CALL: %s (line %d) -> %s %d args, stacksize %d\n",
 
25
                        if (last_ts == 0) delta = 0;
 
26
                        else delta = now - last_ts;
 
27
                        last_ts = now;
 
28
                        uwsgi_log("[uWSGI Python profiler %llu] CALL: %s (line %d) -> %s %d args, stacksize %d\n",
 
29
                                (unsigned long long) delta,
22
30
                                PyString_AsString(frame->f_code->co_filename),
23
31
                                PyFrame_GetLineNumber(frame),
24
32
                                PyString_AsString(frame->f_code->co_name), frame->f_code->co_argcount, frame->f_code->co_stacksize);
25
33
                        break;
26
34
                case PyTrace_C_CALL:
27
 
                        uwsgi_log("[uWSGI Python profiler] C CALL: %s (line %d) -> %s %d args, stacksize %d\n",
 
35
                        if (last_ts == 0) delta = 0;
 
36
                        else delta = now - last_ts;
 
37
                        last_ts = now;
 
38
                        uwsgi_log("[uWSGI Python profiler %llu] C CALL: %s (line %d) -> %s %d args, stacksize %d\n",
 
39
                                (unsigned long long) delta,
28
40
                                PyString_AsString(frame->f_code->co_filename),
29
41
                                PyFrame_GetLineNumber(frame),
30
42
                                PyEval_GetFuncName(arg), frame->f_code->co_argcount, frame->f_code->co_stacksize);
34
46
 
35
47
        return 0;
36
48
}
 
49
 
 
50
int uwsgi_python_tracer(PyObject *obj, PyFrameObject *frame, int what, PyObject *arg) {
 
51
 
 
52
#ifndef UWSGI_PYPY
 
53
        static uint64_t last_ts = 0;
 
54
        uint64_t now = uwsgi_micros();
 
55
        uint64_t delta = 0;
 
56
 
 
57
        if (what == PyTrace_LINE) {
 
58
                if (last_ts == 0) {
 
59
                        delta = 0;
 
60
                }
 
61
                else {
 
62
                        delta = now - last_ts;
 
63
                }
 
64
                last_ts = now;
 
65
                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);
 
66
        }
 
67
#endif
 
68
 
 
69
        return 0;
 
70
}
 
71