]> git.ipfire.org Git - thirdparty/squid.git/blob - include/profiling.h
Merged from trunk.
[thirdparty/squid.git] / include / profiling.h
1
2 #ifndef _PROFILING_H_
3 #define _PROFILING_H_
4
5 #include "config.h"
6
7 /* forward decls (C++ only) */
8 #if __cplusplus
9
10 class CacheManager;
11 #endif
12
13 #ifdef USE_XPROF_STATS
14
15 #if !defined(_SQUID_SOLARIS_)
16 typedef int64_t hrtime_t;
17 #else
18 #include <sys/time.h>
19 #endif
20
21 #if defined(__i386) || defined(__i386__)
22 static inline hrtime_t
23 get_tick(void)
24 {
25 hrtime_t regs;
26
27 asm volatile ("rdtsc":"=A" (regs));
28 return regs;
29 /* We need return value, we rely on CC to optimise out needless subf calls */
30 /* Note that "rdtsc" is relatively slow OP and stalls the CPU pipes, so use it wisely */
31 }
32
33 #elif defined(__x86_64) || defined(__x86_64__)
34 static inline hrtime_t
35 get_tick(void)
36 {
37 uint32_t lo, hi;
38 // Based on an example in Wikipedia
39 /* We cannot use "=A", since this would use %rax on x86_64 */
40 asm volatile ("rdtsc" : "=a" (lo), "=d" (hi));
41 return (hrtime_t)hi << 32 | lo;
42 }
43
44 #elif defined(__alpha)
45 static inline hrtime_t
46 get_tick(void)
47 {
48 hrtime_t regs;
49
50 asm volatile ("rpcc %0" : "=r" (regs));
51 return regs;
52 }
53
54 #elif defined(_M_IX86) && defined(_MSC_VER) /* x86 platform on Microsoft C Compiler ONLY */
55 static __inline hrtime_t
56 get_tick(void)
57 {
58 hrtime_t regs;
59
60 __asm {
61 cpuid
62 rdtsc
63 mov eax,DWORD PTR regs[0]
64 mov edx,DWORD PTR regs[4]
65 }
66 return regs;
67 }
68
69 #else
70 #warning Unsupported CPU. Define function get_tick(). Disabling USE_XPROF_STATS...
71 #undef USE_XPROF_STATS
72 #endif
73
74 #endif /* USE_XPROF_STATS - maybe disabled above */
75
76 #ifdef USE_XPROF_STATS
77
78 typedef enum {
79 XPROF_PROF_UNACCOUNTED,
80 XPROF_PROF_OVERHEAD,
81 XPROF_hash_lookup,
82 XPROF_splay_splay,
83 XPROF_xmalloc,
84 XPROF_malloc,
85 XPROF_xfree,
86 XPROF_xxfree,
87 XPROF_xrealloc,
88 XPROF_xcalloc,
89 XPROF_calloc,
90 XPROF_xstrdup,
91 XPROF_xstrndup,
92 XPROF_xstrncpy,
93 XPROF_xcountws,
94 XPROF_socket,
95 XPROF_read,
96 XPROF_write,
97 XPROF_send,
98 XPROF_recv,
99 XPROF_sendto,
100 XPROF_recvfrom,
101 XPROF_accept,
102 XPROF_connect,
103 XPROF_memPoolChunkNew,
104 XPROF_memPoolAlloc,
105 XPROF_memPoolFree,
106 XPROF_memPoolClean,
107 XPROF_aclMatchAclList,
108 XPROF_aclCheckFast,
109 XPROF_comm_open,
110 XPROF_comm_connect_addr,
111 XPROF_comm_accept,
112 XPROF_comm_close,
113 XPROF_comm_udp_sendto,
114 XPROF_commHandleWrite,
115 XPROF_comm_check_incoming,
116 XPROF_comm_poll_prep_pfds,
117 XPROF_comm_poll_normal,
118 XPROF_comm_handle_ready_fd,
119 XPROF_comm_read_handler,
120 XPROF_comm_write_handler,
121 XPROF_storeGet,
122 XPROF_storeMaintainSwapSpace,
123 XPROF_storeRelease,
124 XPROF_diskHandleWrite,
125 XPROF_diskHandleRead,
126 XPROF_file_open,
127 XPROF_file_read,
128 XPROF_file_write,
129 XPROF_file_close,
130 #if USE_SQUID_ESI
131 XPROF_esiExpressionEval,
132 XPROF_esiProcessing,
133 XPROF_esiParsing,
134 #endif
135 XPROF_storeClient_kickReads,
136 XPROF_eventRun,
137 XPROF_storeDirCallback,
138 XPROF_comm_calliocallback,
139 XPROF_CommReadCallbackData_callCallback,
140 XPROF_CommAcceptCallbackData_callCallback,
141 XPROF_CommWriteCallbackData_callCallback,
142 XPROF_CommFillCallbackData_callCallback,
143 XPROF_HttpStateData_readReply,
144 XPROF_HttpStateData_processReplyBody,
145 XPROF_StoreEntry_write,
146 XPROF_storeGetMemSpace,
147 XPROF_MemObject_write,
148 XPROF_storeWriteComplete,
149 XPROF_mem_hdr_write,
150 XPROF_headersEnd,
151 XPROF_parseHttpRequest,
152 XPROF_HttpStateData_processReplyHeader,
153 XPROF_MemBuf_consume,
154 XPROF_MemBuf_append,
155 XPROF_MemBuf_grow,
156 XPROF_InvokeHandlers,
157 XPROF_HttpMsg_httpMsgParseStep,
158 XPROF_EventDispatcher_dispatch,
159 XPROF_SignalEngine_checkEvents,
160 XPROF_Temp1,
161 XPROF_Temp2,
162 XPROF_Temp3,
163 XPROF_clientSocketRecipient,
164 XPROF_httpStart,
165 XPROF_HttpParserParseReqLine,
166 XPROF_httpRequestFree,
167 XPROF_HttpHeaderParse,
168 XPROF_HttpHeaderClean,
169 XPROF_StringInitBuf,
170 XPROF_StringAllocAndFill,
171 XPROF_StringClean,
172 XPROF_StringReset,
173 XPROF_StringAppend,
174 XPROF_HttpHeader_findEntry,
175 XPROF_HttpHeader_getCc,
176 XPROF_HttpHeader_getRange,
177 XPROF_checkTimeouts,
178 XPROF_CommSelect,
179 XPROF_LAST
180 } xprof_type;
181
182 #define XP_NOBEST (hrtime_t)-1
183
184 typedef struct _xprof_stats_node xprof_stats_node;
185
186 typedef struct _xprof_stats_data xprof_stats_data;
187
188 struct _xprof_stats_data
189 {
190 hrtime_t start;
191 hrtime_t stop;
192 hrtime_t delta;
193 hrtime_t best;
194 hrtime_t worst;
195 hrtime_t count;
196 hrtime_t accum;
197 int64_t summ;
198 };
199
200 struct _xprof_stats_node
201 {
202 const char *name;
203 xprof_stats_data accu;
204 xprof_stats_data hist;
205 };
206
207 typedef xprof_stats_node TimersArray[1];
208
209 /* public Data */
210 SQUIDCEXTERN TimersArray *xprof_Timers;
211
212 /* Exported functions */
213 SQUIDCEXTERN void xprof_start(xprof_type type, const char *timer);
214 SQUIDCEXTERN void xprof_stop(xprof_type type, const char *timer);
215 SQUIDCEXTERN void xprof_event(void *data);
216
217 #define PROF_start(type) xprof_start(XPROF_##type, #type)
218 #define PROF_stop(type) xprof_stop(XPROF_##type, #type)
219
220 #else /* USE_XPROF_STATS */
221
222 #define PROF_start(ARGS) ((void)0)
223 #define PROF_stop(ARGS) ((void)0)
224
225 #endif /* USE_XPROF_STATS */
226
227 #endif /* _PROFILING_H_ */