Debian Codegraph @

rpython/translator/c/src/debug_print.h

raw symbols SCIP
1 /************************************************************/
2 /*** C header subsection: debug_print & related tools ***/
3
4 #include <stdio.h>
5
6 /* values of the PYPYLOG environment variable:
7 ("top-level" debug_prints means not between debug_start and debug_stop)
8
9 (empty) logging is turned off, apart from top-level debug_prints
10 that go to stderr
11 fname or +fname logging for profiling: includes all debug_start/debug_stop
12 but not any nested debug_print, use +fname if there is a
13 colon : in fname
14 :fname full logging
15 prefix:fname conditional logging
16 prefix1,prefix2:fname conditional logging with multiple selections
17
18 Conditional logging means that it only includes the debug_start/debug_stop
19 sections whose name match 'prefix'. Other sections are ignored, including
20 all debug_prints that occur while this section is running and all nested
21 subsections.
22
23 Note that 'fname' can be '-' to send the logging data to stderr.
24 If 'fname' includes the substring '%d' it is replaced with the
25 current process id and you get the log for all subprocesses (and
26 forks) in different files. If 'fname' does not include '%d', it is
27 removed from the environment and not passed to subprocesses.
28 */
29
30 /* macros used by the generated code */
31 #define PYPY_HAVE_DEBUG_PRINTS (pypy_have_debug_prints & 1 ? \
32 (pypy_debug_ensure_opened(), 1) : 0)
33 #define PYPY_DEBUG_FILE pypy_debug_file
34 #define PYPY_DEBUG_START(cat, ts) pypy_debug_start(cat, ts)
35 #define PYPY_DEBUG_STOP(cat, ts) pypy_debug_stop(cat, ts)
36 #define OP_DEBUG_OFFSET(res) res = pypy_debug_offset()
37 #define OP_DEBUG_FORKED(ofs, _) pypy_debug_forked(ofs)
38 #define OP_HAVE_DEBUG_PRINTS(r) r = (pypy_have_debug_prints & 1)
39
40 #ifdef RPY_REVERSE_DEBUGGER
41 RPY_EXTERN void rpy_reverse_db_teardown(void);
42 # define OP_DEBUG_FLUSH() fflush(pypy_debug_file); rpy_reverse_db_teardown()
43 #else
44 # define OP_DEBUG_FLUSH() fflush(pypy_debug_file)
45 #endif
46
47 /************************************************************/
48
49 /* prototypes (internal use only) */
50 RPY_EXTERN void pypy_debug_ensure_opened(void);
51 RPY_EXTERN long long pypy_debug_start(const char *category, Signed timestamp);
52 RPY_EXTERN long long pypy_debug_stop(const char *category, Signed timestamp);
53 RPY_EXTERN long pypy_debug_offset(void);
54 RPY_EXTERN void pypy_debug_forked(Signed original_offset);
55 RPY_EXTERN long pypy_have_debug_prints_for(const char *category_prefix);
56
57 RPY_EXTERN long pypy_have_debug_prints;
58 RPY_EXPORTED FILE *pypy_debug_file;
59
60 /* these should be in sync with the values defined in rlib/rtimer.py */
61 #define TIMESTAMP_UNIT_TSC 0
62 #define TIMESTAMP_UNIT_NS 1
63 #define TIMESTAMP_UNIT_QUERY_PERFORMANCE_COUNTER 2
64
65 #define OP_LL_READ_TIMESTAMP(val) READ_TIMESTAMP(val)
66
67 #include "src/asm.h"
68
69 /* asm_xxx.h may contain a specific implementation of READ_TIMESTAMP.
70 * This is the default generic timestamp implementation.
71 */
72 #ifndef READ_TIMESTAMP
73
74 # ifdef _WIN32
75 # define READ_TIMESTAMP(val) QueryPerformanceCounter((LARGE_INTEGER*)&(val))
76 # define READ_TIMESTAMP_UNIT TIMESTAMP_UNIT_QUERY_PERFORMANCE_COUNTER
77 # else
78
79 RPY_EXTERN long long pypy_read_timestamp(void);
80
81 # define READ_TIMESTAMP(val) (val) = pypy_read_timestamp()
82 # define READ_TIMESTAMP_UNIT TIMESTAMP_UNIT_NS
83
84 # endif
85 #endif
86
87 #define OP_LL_GET_TIMESTAMP_UNIT(res) res = READ_TIMESTAMP_UNIT