1 /*
2  * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef _PROFILER_H_
10 #define _PROFILER_H_
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 // NP: CPU support for get_tick() determines whether we can profile.
17 //     always include get_tick.h first since it may undefine USE_XPROF_STATS
18 
19 #include "profiler/get_tick.h"
20 #include "profiler/xprof_type.h"
21 
22 #if !USE_XPROF_STATS
23 
24 #define PROF_start(probename) ((void)0)
25 #define PROF_stop(probename) ((void)0)
26 
27 #else /* USE_XPROF_STATS */
28 
29 #define XP_NOBEST (hrtime_t)-1
30 
31 typedef struct _xprof_stats_node xprof_stats_node;
32 
33 typedef struct _xprof_stats_data xprof_stats_data;
34 
35 struct _xprof_stats_data {
36     hrtime_t start;
37     hrtime_t stop;
38     hrtime_t delta;
39     hrtime_t best;
40     hrtime_t worst;
41     hrtime_t count;
42     hrtime_t accum;
43     int64_t summ;
44 };
45 
46 struct _xprof_stats_node {
47     const char *name;
48     xprof_stats_data accu;
49     xprof_stats_data hist;
50 };
51 
52 typedef xprof_stats_node TimersArray[1];
53 
54 /* public Data */
55 extern TimersArray *xprof_Timers;
56 
57 /* Exported functions */
58 extern void xprof_start(xprof_type type, const char *timer);
59 extern void xprof_stop(xprof_type type, const char *timer);
60 extern void xprof_event(void *data);
61 
62 #define PROF_start(probename) xprof_start(XPROF_##probename, #probename)
63 #define PROF_stop(probename) xprof_stop(XPROF_##probename, #probename)
64 
65 #endif /* USE_XPROF_STATS */
66 
67 #ifdef __cplusplus
68 }
69 #endif
70 #endif /* _PROFILING_H_ */
71 
72