1 #ifndef CADO_UTILS_TIMING_H_
2 #define CADO_UTILS_TIMING_H_
3
4 #include "cado_config.h" // for HAVE_GETRUSAGE, HAVE_GCC_STYLE_AMD64_INLINE...
5
6 #include <stdio.h> // FILE
7 #include <stdint.h> /* for uint64_t */
8
9 #ifdef HAVE_GETRUSAGE
10 #include <sys/resource.h> // IWYU pragma: keep
11 #else
12 #include "macros.h" /* MAYBE_UNUSED */ // IWYU pragma: keep
13 #endif
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 #ifdef HAVE_GCC_STYLE_AMD64_INLINE_ASM
cputicks()20 static inline uint64_t cputicks()
21 {
22 uint64_t r;
23 __asm__ __volatile__(
24 "rdtsc\n\t"
25 "shlq $32, %%rdx\n\t"
26 "orq %%rdx, %%rax\n\t"
27 : "=a"(r)
28 :
29 : "rdx");
30 return r;
31 }
32 #endif
33
34 extern uint64_t microseconds (void);
35 extern uint64_t microseconds_thread (void);
36 extern unsigned long milliseconds (void);
37 extern unsigned long milliseconds_thread (void);
38 extern double seconds (void);
39 extern double seconds_thread (void);
40 extern void seconds_user_sys (double *);
41 extern double wct_seconds (void);
42 extern void print_timing_and_memory (FILE*, double, double);
43 extern void thread_seconds_user_sys(double *);
44
45 /* we provide an interface to collect the timings of the subprocesses.
46 * Each subprocess is identified in the filter_io layer by some key, and
47 * the caller has to call the proper function to display the tally of the
48 * timings.
49 *
50 * This could be expanded to collect more versatile timing kinds.
51 */
52
53 typedef void * timingstats_dict_t[1];
54 typedef void ** timingstats_dict_ptr;
55 #ifdef HAVE_GETRUSAGE /* since this is only rusage-oriented... */
56 void timingstats_dict_init(timingstats_dict_ptr);
57 void timingstats_dict_clear(timingstats_dict_ptr);
58 /* display the tally */
59 void timingstats_dict_disp(timingstats_dict_ptr);
60 void timingstats_dict_add(timingstats_dict_ptr, const char * key, struct rusage * r);
61 void timingstats_dict_add_mythread(timingstats_dict_ptr, const char * key);
62 void timingstats_dict_add_myprocess(timingstats_dict_ptr, const char * key);
63 #else /* provide all of these as no-ops */
timingstats_dict_init(timingstats_dict_ptr x MAYBE_UNUSED)64 static inline void timingstats_dict_init(timingstats_dict_ptr x MAYBE_UNUSED) {}
timingstats_dict_clear(timingstats_dict_ptr x MAYBE_UNUSED)65 static inline void timingstats_dict_clear(timingstats_dict_ptr x MAYBE_UNUSED) {}
timingstats_dict_disp(timingstats_dict_ptr x MAYBE_UNUSED)66 static inline void timingstats_dict_disp(timingstats_dict_ptr x MAYBE_UNUSED) {}
67 // sta inline ic void timingstats_dict_add(timingstats_dict_ptr x MAYBE_UNUSED, const char * key MAYBE_UNUSED, void * r MAYBE_UNUSED) {}
timingstats_dict_add_mythread(timingstats_dict_ptr x MAYBE_UNUSED,const char * key MAYBE_UNUSED)68 static inline void timingstats_dict_add_mythread(timingstats_dict_ptr x MAYBE_UNUSED, const char * key MAYBE_UNUSED) {}
timingstats_dict_add_myprocess(timingstats_dict_ptr x MAYBE_UNUSED,const char * key MAYBE_UNUSED)69 static inline void timingstats_dict_add_myprocess(timingstats_dict_ptr x MAYBE_UNUSED, const char * key MAYBE_UNUSED) {}
70 #endif
71
72 #ifdef __cplusplus
73 }
74
75 struct weighted_double {
76 unsigned int n;
77 double t;
78 };
79 #endif
80
81 #endif /* CADO_UTILS_TIMING_H_ */
82