-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprof.c
170 lines (142 loc) · 4.13 KB
/
prof.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
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
/* prof extension for PHP */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php_prof.h"
#include "helpers.h"
#include "sampling.h"
#include "func.h"
#include "opcode.h"
#include "ext/standard/info.h"
/* For compatibility with older PHP versions */
#ifndef ZEND_PARSE_PARAMETERS_NONE
#define ZEND_PARSE_PARAMETERS_NONE() \
ZEND_PARSE_PARAMETERS_START(0, 0) \
ZEND_PARSE_PARAMETERS_END()
#endif
ZEND_DECLARE_MODULE_GLOBALS(prof)
PHP_INI_BEGIN()
PHP_INI_ENTRY("prof.mode", "", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("prof.output_mode", "", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("prof.sampling_interval", "", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("prof.sampling_limit", "", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("prof.sampling_threshold", "", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("prof.func_limit", "", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("prof.func_threshold", "", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("prof.opcode_threshold", "", PHP_INI_SYSTEM, NULL)
PHP_INI_END()
PHP_MINIT_FUNCTION(prof) {
#if defined(COMPILE_DL_MY_EXTENSION) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
REGISTER_INI_ENTRIES();
if (build_config() == FAILURE) {
return FAILURE;
}
switch (PROF_G(config).mode) {
case PROF_MODE_SAMPLING:
return prof_sampling_init();
case PROF_MODE_FUNC:
return prof_func_init();
case PROF_MODE_OPCODE:
return prof_opcode_init();
}
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(prof) {
UNREGISTER_INI_ENTRIES();
return SUCCESS;
}
PHP_RINIT_FUNCTION(prof) {
#if defined(ZTS) && defined(COMPILE_DL_PROF)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
prof_init_errors();
PROF_G(start_time) = get_wall_time();
if (!PROF_G(start_time)) {
return FAILURE;
}
switch (PROF_G(config).mode) {
case PROF_MODE_SAMPLING:
return prof_sampling_setup();
case PROF_MODE_FUNC:
return prof_func_setup();
case PROF_MODE_OPCODE:
return prof_opcode_setup();
}
return SUCCESS;
}
PHP_RSHUTDOWN_FUNCTION(prof) {
if (prof_has_errors()) {
prof_print_errors();
} else {
if (PROF_G(config).mode != PROF_MODE_NONE && PROF_G(config).output_mode == PROF_OUTPUT_MODE_CONSOLE) {
prof_print_common_header();
}
switch (PROF_G(config).mode) {
case PROF_MODE_SAMPLING:
switch (PROF_G(config).output_mode) {
case PROF_OUTPUT_MODE_CONSOLE:
prof_sampling_print_result_console();
break;
case PROF_OUTPUT_MODE_CALLGRIND:
prof_sampling_print_result_callgrind();
break;
case PROF_OUTPUT_MODE_PPROF:
prof_sampling_print_result_pprof();
break;
}
break;
case PROF_MODE_FUNC:
prof_func_print_result();
break;
case PROF_MODE_OPCODE: {
prof_opcode_print_result();
break;
}
}
prof_print_errors();
}
prof_shutdown_errors();
switch (PROF_G(config).mode) {
case PROF_MODE_SAMPLING:
return prof_sampling_teardown();
case PROF_MODE_FUNC:
return prof_func_teardown();
case PROF_MODE_OPCODE: {
return prof_opcode_teardown();
}
}
return SUCCESS;
}
PHP_MINFO_FUNCTION(prof) {
php_info_print_table_start();
php_info_print_table_header(2, "prof support", "enabled");
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
static const zend_function_entry ext_functions[] = {
ZEND_FE_END
};
zend_module_entry prof_module_entry = {
STANDARD_MODULE_HEADER,
"prof",
ext_functions,
PHP_MINIT(prof),
PHP_MSHUTDOWN(prof),
PHP_RINIT(prof),
PHP_RSHUTDOWN(prof),
PHP_MINFO(prof),
PHP_PROF_VERSION,
PHP_MODULE_GLOBALS(prof),
NULL,
NULL,
NULL,
STANDARD_MODULE_PROPERTIES_EX
};
#ifdef COMPILE_DL_PROF
# ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
# endif
ZEND_GET_MODULE(prof)
#endif