Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 44822:424cccfd2baa legacy-trunk
#1648: add sys.gettrace() and sys.getprofile().
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Sun, 20 Jan 2008 13:59:46 +0000 |
| parents | 5dfded9ad8a0 |
| children | ea3fe302d392 |
comparison
equal
deleted
inserted
replaced
| 44821:b28fdef2f0d7 | 44822:424cccfd2baa |
|---|---|
| 396 Set the global debug tracing function. It will be called on each\n\ | 396 Set the global debug tracing function. It will be called on each\n\ |
| 397 function call. See the debugger chapter in the library manual." | 397 function call. See the debugger chapter in the library manual." |
| 398 ); | 398 ); |
| 399 | 399 |
| 400 static PyObject * | 400 static PyObject * |
| 401 sys_gettrace(PyObject *self, PyObject *args) | |
| 402 { | |
| 403 PyThreadState *tstate = PyThreadState_GET(); | |
| 404 PyObject *temp = tstate->c_traceobj; | |
| 405 | |
| 406 if (temp == NULL) | |
| 407 temp = Py_None; | |
| 408 Py_INCREF(temp); | |
| 409 return temp; | |
| 410 } | |
| 411 | |
| 412 PyDoc_STRVAR(gettrace_doc, | |
| 413 "gettrace()\n\ | |
| 414 \n\ | |
| 415 Return the global debug tracing function set with sys.settrace.\n\ | |
| 416 See the debugger chapter in the library manual." | |
| 417 ); | |
| 418 | |
| 419 static PyObject * | |
| 401 sys_setprofile(PyObject *self, PyObject *args) | 420 sys_setprofile(PyObject *self, PyObject *args) |
| 402 { | 421 { |
| 403 if (trace_init() == -1) | 422 if (trace_init() == -1) |
| 404 return NULL; | 423 return NULL; |
| 405 if (args == Py_None) | 424 if (args == Py_None) |
| 413 PyDoc_STRVAR(setprofile_doc, | 432 PyDoc_STRVAR(setprofile_doc, |
| 414 "setprofile(function)\n\ | 433 "setprofile(function)\n\ |
| 415 \n\ | 434 \n\ |
| 416 Set the profiling function. It will be called on each function call\n\ | 435 Set the profiling function. It will be called on each function call\n\ |
| 417 and return. See the profiler chapter in the library manual." | 436 and return. See the profiler chapter in the library manual." |
| 437 ); | |
| 438 | |
| 439 static PyObject * | |
| 440 sys_getprofile(PyObject *self, PyObject *args) | |
| 441 { | |
| 442 PyThreadState *tstate = PyThreadState_GET(); | |
| 443 PyObject *temp = tstate->c_profileobj; | |
| 444 | |
| 445 if (temp == NULL) | |
| 446 temp = Py_None; | |
| 447 Py_INCREF(temp); | |
| 448 return temp; | |
| 449 } | |
| 450 | |
| 451 PyDoc_STRVAR(getprofile_doc, | |
| 452 "getprofile()\n\ | |
| 453 \n\ | |
| 454 Return the profiling function set with sys.setprofile.\n\ | |
| 455 See the profiler chapter in the library manual." | |
| 418 ); | 456 ); |
| 419 | 457 |
| 420 static PyObject * | 458 static PyObject * |
| 421 sys_setcheckinterval(PyObject *self, PyObject *args) | 459 sys_setcheckinterval(PyObject *self, PyObject *args) |
| 422 { | 460 { |
| 791 #ifdef HAVE_DLOPEN | 829 #ifdef HAVE_DLOPEN |
| 792 {"setdlopenflags", sys_setdlopenflags, METH_VARARGS, | 830 {"setdlopenflags", sys_setdlopenflags, METH_VARARGS, |
| 793 setdlopenflags_doc}, | 831 setdlopenflags_doc}, |
| 794 #endif | 832 #endif |
| 795 {"setprofile", sys_setprofile, METH_O, setprofile_doc}, | 833 {"setprofile", sys_setprofile, METH_O, setprofile_doc}, |
| 834 {"getprofile", sys_getprofile, METH_NOARGS, getprofile_doc}, | |
| 796 {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS, | 835 {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS, |
| 797 setrecursionlimit_doc}, | 836 setrecursionlimit_doc}, |
| 798 #ifdef WITH_TSC | 837 #ifdef WITH_TSC |
| 799 {"settscdump", sys_settscdump, METH_VARARGS, settscdump_doc}, | 838 {"settscdump", sys_settscdump, METH_VARARGS, settscdump_doc}, |
| 800 #endif | 839 #endif |
| 801 {"settrace", sys_settrace, METH_O, settrace_doc}, | 840 {"settrace", sys_settrace, METH_O, settrace_doc}, |
| 841 {"gettrace", sys_gettrace, METH_NOARGS, gettrace_doc}, | |
| 802 {"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc}, | 842 {"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc}, |
| 803 {NULL, NULL} /* sentinel */ | 843 {NULL, NULL} /* sentinel */ |
| 804 }; | 844 }; |
| 805 | 845 |
| 806 static PyObject * | 846 static PyObject * |
| 939 excepthook() -- print an exception and its traceback to sys.stderr\n\ | 979 excepthook() -- print an exception and its traceback to sys.stderr\n\ |
| 940 exc_info() -- return thread-safe information about the current exception\n\ | 980 exc_info() -- return thread-safe information about the current exception\n\ |
| 941 exc_clear() -- clear the exception state for the current thread\n\ | 981 exc_clear() -- clear the exception state for the current thread\n\ |
| 942 exit() -- exit the interpreter by raising SystemExit\n\ | 982 exit() -- exit the interpreter by raising SystemExit\n\ |
| 943 getdlopenflags() -- returns flags to be used for dlopen() calls\n\ | 983 getdlopenflags() -- returns flags to be used for dlopen() calls\n\ |
| 984 getprofile() -- get the global profiling function\n\ | |
| 944 getrefcount() -- return the reference count for an object (plus one :-)\n\ | 985 getrefcount() -- return the reference count for an object (plus one :-)\n\ |
| 945 getrecursionlimit() -- return the max recursion depth for the interpreter\n\ | 986 getrecursionlimit() -- return the max recursion depth for the interpreter\n\ |
| 987 gettrace() -- get the global debug tracing function\n\ | |
| 946 setcheckinterval() -- control how often the interpreter checks for events\n\ | 988 setcheckinterval() -- control how often the interpreter checks for events\n\ |
| 947 setdlopenflags() -- set the flags to be used for dlopen() calls\n\ | 989 setdlopenflags() -- set the flags to be used for dlopen() calls\n\ |
| 948 setprofile() -- set the global profiling function\n\ | 990 setprofile() -- set the global profiling function\n\ |
| 949 setrecursionlimit() -- set the max recursion depth for the interpreter\n\ | 991 setrecursionlimit() -- set the max recursion depth for the interpreter\n\ |
| 950 settrace() -- set the global debug tracing function\n\ | 992 settrace() -- set the global debug tracing function\n\ |
