-
Notifications
You must be signed in to change notification settings - Fork 3
/
scout_execute_ex.c
159 lines (134 loc) · 5.8 KB
/
scout_execute_ex.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
/*
* Scout APM extension for PHP
*
* Copyright (C) 2021
* For license information, please see the LICENSE file.
*/
#include "zend_scoutapm.h"
#include "scout_extern.h"
#if SCOUTAPM_INSTRUMENT_USING_OBSERVER_API == 0
void (*original_zend_execute_ex) (zend_execute_data *execute_data);
void (*original_zend_execute_internal) (zend_execute_data *execute_data, zval *return_value);
void scoutapm_execute_internal(zend_execute_data *execute_data, zval *return_value);
void scoutapm_execute_ex(zend_execute_data *execute_data);
#endif
int setup_functions_for_zend_execute_ex()
{
#if SCOUTAPM_INSTRUMENT_USING_OBSERVER_API == 0
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->append");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->decr");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->decrBy");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->get");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->getBit");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->getRange");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->getSet");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->incr");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->incrBy");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->mGet");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->mSet");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->mSetNx");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->set");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->setBit");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->setEx");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->pSetEx");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->setNx");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->setRange");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->strlen");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Predis\\Client->del");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Elasticsearch\\Client->index");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Elasticsearch\\Client->get");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Elasticsearch\\Client->search");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Elasticsearch\\Client->delete");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Elastic\\Elasticsearch\\Client->index");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Elastic\\Elasticsearch\\Client->get");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Elastic\\Elasticsearch\\Client->search");
ADD_FUNCTION_TO_INSTRUMENTATION_SAFE_CATCH("Elastic\\Elasticsearch\\Client->delete");
#endif
return SUCCESS;
}
void register_scout_execute_ex()
{
#if SCOUTAPM_INSTRUMENT_USING_OBSERVER_API == 0
original_zend_execute_internal = zend_execute_internal;
zend_execute_internal = scoutapm_execute_internal;
original_zend_execute_ex = zend_execute_ex;
zend_execute_ex = scoutapm_execute_ex;
#endif
}
void deregister_scout_execute_ex()
{
#if SCOUTAPM_INSTRUMENT_USING_OBSERVER_API == 0
zend_execute_internal = original_zend_execute_internal;
zend_execute_ex = original_zend_execute_ex;
#endif
}
#if SCOUTAPM_INSTRUMENT_USING_OBSERVER_API == 0
void scoutapm_execute_internal(zend_execute_data *execute_data, zval *return_value)
{
const char *function_name;
double entered = scoutapm_microtime();
int argc;
zval *argv = NULL;
if (SCOUTAPM_G(all_instrumentation_enabled) != 1
|| SCOUTAPM_G(currently_instrumenting) == 1
|| execute_data->func->common.function_name == NULL
) {
if (original_zend_execute_internal) {
original_zend_execute_internal(execute_data, return_value);
} else {
execute_internal(execute_data, return_value);
}
return;
}
function_name = determine_function_name(execute_data);
if (should_be_instrumented(function_name, NULL) == 0) {
free((void*) function_name);
if (original_zend_execute_internal) {
original_zend_execute_internal(execute_data, return_value);
} else {
execute_internal(execute_data, return_value);
}
return;
}
SCOUTAPM_G(currently_instrumenting) = 1;
ZEND_PARSE_PARAMETERS_START(0, -1)
Z_PARAM_VARIADIC(' ', argv, argc)
ZEND_PARSE_PARAMETERS_END();
if (original_zend_execute_internal) {
original_zend_execute_internal(execute_data, return_value);
} else {
execute_internal(execute_data, return_value);
}
record_observed_stack_frame(function_name, entered, scoutapm_microtime(), argc, argv);
SCOUTAPM_G(currently_instrumenting) = 0;
free((void*) function_name);
}
void scoutapm_execute_ex(zend_execute_data *execute_data)
{
const char *function_name;
double entered = scoutapm_microtime();
int argc;
zval *argv = NULL;
if (SCOUTAPM_G(all_instrumentation_enabled) != 1
|| SCOUTAPM_G(currently_instrumenting) == 1
|| execute_data->func->common.function_name == NULL
) {
original_zend_execute_ex(execute_data);
return;
}
function_name = determine_function_name(execute_data);
if (should_be_instrumented(function_name, NULL) == 0) {
free((void*) function_name);
original_zend_execute_ex(execute_data);
return;
}
SCOUTAPM_G(currently_instrumenting) = 1;
ZEND_PARSE_PARAMETERS_START(0, -1)
Z_PARAM_VARIADIC(' ', argv, argc)
ZEND_PARSE_PARAMETERS_END();
original_zend_execute_ex(execute_data);
record_observed_stack_frame(function_name, entered, scoutapm_microtime(), argc, argv);
SCOUTAPM_G(currently_instrumenting) = 0;
free((void*) function_name);
}
#endif /* SCOUTAPM_INSTRUMENT_USING_OBSERVER_API */