1 #ifndef EL__UTIL_PROFILE_H
2 #define EL__UTIL_PROFILE_H
8 /* Process' CPU time utilities */
12 /* CLK_DECL(n) declares an array of @n clock_t to be used by CLK_* macros.
13 * Must occur before any CLK_* macros call. */
14 #define CLK_DECL(n) clock_t clk_start[n], clk_end[n], clk_diff[n]; int clk_start_line[n], clk_stop_line[n]
16 /* CLK_START(n) starts clock @n.
17 * Must occur after CLK_DECL() and before CLK_STOP(). */
18 #define CLK_START(n) do { clk_start_line[n] = __LINE__; clk_start[n] = clock(); } while (0)
20 /* CLK_STOP(n) stops clock @n.
21 * Must occur after CLK_START() and before CLK_DUMP(). */
22 #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)
24 /* CLK_DUMP(n) echoes cpu time spent between CLK_START(@n) and CLK_STOP(@n).
25 * Must occur after CLK_START() and CLK_STOP(). */
26 #define CLK_DUMP(n) do { \
27 fprintf(stderr, "%s:%d->%d CLK[%d]= %.16f sec.\n", \
28 __FILE__, clk_start_line[n], clk_stop_line[n], \
29 n, (double) clk_diff[n] / (double) CLOCKS_PER_SEC);\
32 /* Shortcuts for function profiling.
33 * CLK_STA() must be at end of local declarations.
34 * CLK_STO() must be just before end of function. */
35 #define CLK_STA() CLK_DECL(1); CLK_START(0)
36 #define CLK_STO() CLK_STOP(0); CLK_DUMP(0)
41 #define CLK_START(n) do {} while (0)
42 #define CLK_STOP(n) do {} while (0)
43 #define CLK_DUMP(n) do {} while (0)