File: profiling.h

package info (click to toggle)
squid3 3.0.PRE5-5%2Betch2
  • links: PTS
  • area: main
  • in suites: etch
  • size: 21,188 kB
  • ctags: 20,388
  • sloc: cpp: 119,851; ansic: 30,259; sh: 10,465; makefile: 3,289; perl: 1,267; awk: 84; xml: 58
file content (209 lines) | stat: -rw-r--r-- 4,736 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209

#ifndef _PROFILING_H_
#define _PROFILING_H_

#include "config.h"

/* forward decls (C++ only) */
#if __cplusplus

class CacheManager;
#endif

#ifdef USE_XPROF_STATS

#if !defined(_SQUID_SOLARIS_)
typedef int64_t  hrtime_t;
#else
#include <sys/time.h>
#endif

#if defined(__i386) || defined(__i386__)
static inline hrtime_t
get_tick(void)
{
    hrtime_t regs;

asm volatile ("rdtsc":"=A" (regs));
    return regs;
    /* We need return value, we rely on CC to optimise out needless subf calls */
    /* Note that "rdtsc" is relatively slow OP and stalls the CPU pipes, so use it wisely */
}

#elif defined(__alpha)
static inline hrtime_t
get_tick(void)
{
    hrtime_t regs;

asm volatile ("rpcc %0" : "=r" (regs));
    return regs;
}

#elif defined(_M_IX86) && defined(_MSC_VER) /* x86 platform on Microsoft C Compiler ONLY */
static __inline hrtime_t
get_tick(void)
{
    hrtime_t regs;

    __asm {
        cpuid
        rdtsc
        mov eax,DWORD PTR regs[0]
        mov edx,DWORD PTR regs[4]
    }
    return regs;
}

#else
#warning Unsupported CPU. Define function get_tick(). Disabling USE_XPROF_STATS...
#undef USE_XPROF_STATS
#endif

#endif /* USE_XPROF_STATS - maybe disabled above */

#ifdef USE_XPROF_STATS

typedef enum {
    XPROF_PROF_UNACCOUNTED,
    XPROF_PROF_OVERHEAD,
    XPROF_hash_lookup,
    XPROF_splay_splay,
    XPROF_xmalloc,
    XPROF_malloc,
    XPROF_xfree,
    XPROF_xxfree,
    XPROF_xrealloc,
    XPROF_xcalloc,
    XPROF_calloc,
    XPROF_xstrdup,
    XPROF_xstrndup,
    XPROF_xstrncpy,
    XPROF_xcountws,
    XPROF_memPoolChunkNew,
    XPROF_memPoolAlloc,
    XPROF_memPoolFree,
    XPROF_memPoolClean,
    XPROF_aclMatchAclList,
    XPROF_aclCheckFast,
    XPROF_comm_open,
    XPROF_comm_connect_addr,
    XPROF_comm_accept,
    XPROF_comm_close,
    XPROF_comm_udp_sendto,
    XPROF_commHandleWrite,
    XPROF_comm_check_incoming,
    XPROF_comm_poll_prep_pfds,
    XPROF_comm_poll_normal,
    XPROF_comm_handle_ready_fd,
    XPROF_comm_read_handler,
    XPROF_comm_write_handler,
    XPROF_storeGet,
    XPROF_storeMaintainSwapSpace,
    XPROF_storeRelease,
    XPROF_diskHandleWrite,
    XPROF_diskHandleRead,
    XPROF_file_open,
    XPROF_file_read,
    XPROF_file_write,
    XPROF_file_close,
#ifdef ESI
    XPROF_esiExpressionEval,
    XPROF_esiProcessing,
    XPROF_esiParsing,
#endif
    XPROF_storeClient_kickReads,
    XPROF_eventRun,
    XPROF_storeDirCallback,
    XPROF_comm_calliocallback,
    XPROF_CommReadCallbackData_callCallback,
    XPROF_CommAcceptCallbackData_callCallback,
    XPROF_CommWriteCallbackData_callCallback,
    XPROF_CommFillCallbackData_callCallback,
    XPROF_HttpStateData_readReply,
    XPROF_HttpStateData_processReplyBody,
    XPROF_StoreEntry_write,
    XPROF_storeGetMemSpace,
    XPROF_MemObject_write,
    XPROF_storeWriteComplete,
    XPROF_mem_hdr_write,
    XPROF_headersEnd,
    XPROF_parseHttpRequest,
    XPROF_HttpStateData_processReplyHeader,
    XPROF_MemBuf_consume,
    XPROF_MemBuf_append,
    XPROF_MemBuf_grow,
    XPROF_InvokeHandlers,
    XPROF_HttpMsg_httpMsgParseStep,
    XPROF_EventDispatcher_dispatch,
    XPROF_SignalDispatcher_dispatch,
    XPROF_Temp1,
    XPROF_Temp2,
    XPROF_Temp3,
    XPROF_clientSocketRecipient,
    XPROF_httpStart,
    XPROF_HttpParserParseReqLine,
    XPROF_httpRequestFree,
    XPROF_HttpHeaderParse,
    XPROF_HttpHeaderClean,
    XPROF_StringInitBuf,
    XPROF_StringInit,
    XPROF_StringLimitInit,
    XPROF_StringClean,
    XPROF_StringReset,
    XPROF_StringAppend,
    XPROF_HttpHeader_findEntry,
    XPROF_HttpHeader_getCc,
    XPROF_HttpHeader_getRange,
    XPROF_LAST
} xprof_type;

#define XP_NOBEST (hrtime_t)-1

typedef struct _xprof_stats_node xprof_stats_node;

typedef struct _xprof_stats_data xprof_stats_data;

struct _xprof_stats_data
{
    hrtime_t start;
    hrtime_t stop;
    hrtime_t delta;
    hrtime_t best;
    hrtime_t worst;
    hrtime_t count;
    int64_t summ;
};

struct _xprof_stats_node
{
    const char *name;
    xprof_stats_data accu;
    xprof_stats_data hist;
};

typedef xprof_stats_node TimersArray[1];

/* public Data */
SQUIDCEXTERN TimersArray *xprof_Timers;
SQUIDCEXTERN int xprof_nesting;

/* Exported functions */
SQUIDCEXTERN void xprof_start(xprof_type type, const char *timer);
SQUIDCEXTERN void xprof_stop(xprof_type type, const char *timer);
SQUIDCEXTERN void xprof_event(void *data);
#if __cplusplus
extern void xprofRegisterWithCacheManager(CacheManager & manager);
#endif

#define PROF_start(type) xprof_start(XPROF_##type, #type)
#define PROF_stop(type) xprof_stop(XPROF_##type, #type)

#else /* USE_XPROF_STATS */

#define PROF_start(ARGS) ((void)0)
#define PROF_stop(ARGS) ((void)0)

#endif /* USE_XPROF_STATS */

#endif /* _PROFILING_H_ */