-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathngx_trace.c
104 lines (74 loc) · 2.71 KB
/
ngx_trace.c
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
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
static ngx_http_module_t ngx_http_ptrace_ctx = {
NULL, /* preconfiguration */
NULL, /* postconfiguration */
NULL, /* create main configuration */
NULL, /* init main configuration */
NULL, /* create server configuration */
NULL, /* merge server configuration */
NULL, /* create location configuration */
NULL /* merge location configuration */
};
ngx_module_t ngx_http_ptrace = {
NGX_MODULE_V1,
&ngx_http_ptrace_ctx, /* module context */
NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init master */
NULL, /* init module */
NULL, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
NULL, /* exit process */
NULL, /* exit master */
NGX_MODULE_V1_PADDING
};
static int notrace;
static struct timeval curtv;
void __cyg_profile_func_enter(void *this_fn, void *call_site)
__attribute__ ((no_instrument_function));
void __cyg_profile_func_exit(void *this_fn, void *call_site)
__attribute__ ((no_instrument_function));
void ngx_cdecl
ngx_trace(const char *fmt, ...)
__attribute__ ((no_instrument_function));
void ngx_cdecl
ngx_trace(const char *fmt, ...)
{
u_char *p, *last;
va_list args;
u_char errstr[NGX_MAX_ERROR_STR];
last = errstr + NGX_MAX_ERROR_STR;
p = errstr + 7;
ngx_memcpy(errstr, "nginx: ", 7);
va_start(args, fmt);
p = ngx_vslprintf(p, last, fmt, args);
va_end(args);
if (p > last - NGX_LINEFEED_SIZE) {
p = last - NGX_LINEFEED_SIZE;
}
ngx_linefeed(p);
(void) ngx_write_console(1, errstr, p - errstr);
}
void
__cyg_profile_func_enter(void *this_fn, void *call_site)
{
if (notrace) return;
notrace = 1;
ngx_gettimeofday(&curtv);
ngx_trace("enter %p %i %i", this_fn, curtv.tv_sec, curtv.tv_usec);
notrace = 0;
(void)call_site;
}
void
__cyg_profile_func_exit(void *this_fn, void *call_site)
{
if (notrace) return;
notrace = 1;
ngx_gettimeofday(&curtv);
ngx_trace("exit %p %i %i", this_fn, curtv.tv_sec, curtv.tv_usec);
notrace = 0;
(void)call_site;
}