A more nuanced approach to Python warnings.
[elinks.git] / src / util / profile.h
blob4570e9b04c12e89d9d2feb704af3571c2de92726
1 /** Process' CPU time utilities
2 * @file*/
4 #ifndef EL__UTIL_PROFILE_H
5 #define EL__UTIL_PROFILE_H
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
11 #ifdef CONFIG_DEBUG
12 #include <time.h>
14 /** @c CLK_DECL(n) declares an array of @a n clock_t to be used by
15 * CLK_* macros. Must occur before any CLK_* macros call. */
16 #define CLK_DECL(n) clock_t clk_start[n], clk_end[n], clk_diff[n]; int clk_start_line[n], clk_stop_line[n]
18 /** @c CLK_START(n) starts clock @a n.
19 * Must occur after CLK_DECL() and before CLK_STOP(). */
20 #define CLK_START(n) do { clk_start_line[n] = __LINE__; clk_start[n] = clock(); } while (0)
22 /* @c CLK_STOP(n) stops clock @a n.
23 * Must occur after CLK_START() and before CLK_DUMP(). */
24 #define CLK_STOP(n) do { clk_end[n] = clock(); clk_diff[n] = clk_end[n] - clk_start[n]; clk_stop_line[n] = __LINE__; } while (0)
26 /* @c CLK_DUMP(n) echoes cpu time spent between CLK_START(@a n) and
27 * CLK_STOP(@a n). Must occur after CLK_START() and CLK_STOP(). */
28 #define CLK_DUMP(n) do { \
29 fprintf(stderr, "%s:%d->%d CLK[%d]= %.16f sec.\n", \
30 __FILE__, clk_start_line[n], clk_stop_line[n], \
31 n, (double) clk_diff[n] / (double) CLOCKS_PER_SEC);\
32 } while (0)
34 /** Shortcuts for function profiling.
35 * CLK_STA() must be at end of local declarations.
36 * CLK_STO() must be just before end of function. */
37 #define CLK_STA() CLK_DECL(1); CLK_START(0)
38 #define CLK_STO() CLK_STOP(0); CLK_DUMP(0)
40 #else
41 /* Dummy macros. */
42 #define CLK_DECL(n)
43 #define CLK_START(n) do {} while (0)
44 #define CLK_STOP(n) do {} while (0)
45 #define CLK_DUMP(n) do {} while (0)
46 #define CLK_STA()
47 #define CLK_STO()
48 #endif
50 #endif