-
Notifications
You must be signed in to change notification settings - Fork 3
/
scout_file_wrapper.c
114 lines (89 loc) · 3.42 KB
/
scout_file_wrapper.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
/*
* Scout APM extension for PHP
*
* Copyright (C) 2019-
* For license information, please see the LICENSE file.
*/
#include "zend_scoutapm.h"
#include "scout_extern.h"
ZEND_NAMED_FUNCTION(scoutapm_fopen_handler)
{
zend_string *filename, *mode;
zval argv[2];
const char *passthru_function_name, *resource_id;
SCOUT_PASSTHRU_IF_ALREADY_INSTRUMENTING(passthru_function_name)
ZEND_PARSE_PARAMETERS_START(2, 4)
Z_PARAM_STR(filename)
Z_PARAM_STR(mode)
SCOUT_ZEND_PARSE_PARAMETERS_END();
ZVAL_STR(&argv[0], filename);
ZVAL_STR(&argv[1], mode);
SCOUT_INTERNAL_FUNCTION_PASSTHRU(passthru_function_name);
if (Z_TYPE_P(return_value) == IS_RESOURCE) {
resource_id = unique_resource_id(SCOUT_WRAPPER_TYPE_FILE, return_value);
record_arguments_for_call(resource_id, 2, argv);
free((void*) resource_id);
}
}
ZEND_NAMED_FUNCTION(scoutapm_fread_handler)
{
int handler_index;
double entered = scoutapm_microtime();
zval *resource_id;
const char *called_function, *str_resource_id;
zend_long recorded_arguments_index;
SCOUT_PASSTHRU_IF_ALREADY_INSTRUMENTING(called_function)
called_function = determine_function_name(execute_data);
ZEND_PARSE_PARAMETERS_START(1, 10)
Z_PARAM_RESOURCE(resource_id)
SCOUT_ZEND_PARSE_PARAMETERS_END();
handler_index = handler_index_for_function(called_function);
str_resource_id = unique_resource_id(SCOUT_WRAPPER_TYPE_FILE, resource_id);
recorded_arguments_index = find_index_for_recorded_arguments(str_resource_id);
free((void*) str_resource_id);
if (recorded_arguments_index < 0) {
free((void*) called_function);
scoutapm_default_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
return;
}
original_handlers[handler_index](INTERNAL_FUNCTION_PARAM_PASSTHRU);
record_observed_stack_frame(
called_function,
entered,
scoutapm_microtime(),
SCOUTAPM_G(disconnected_call_argument_store)[recorded_arguments_index].argc,
SCOUTAPM_G(disconnected_call_argument_store)[recorded_arguments_index].argv
);
free((void*) called_function);
}
ZEND_NAMED_FUNCTION(scoutapm_fwrite_handler)
{
int handler_index;
double entered = scoutapm_microtime();
zval *resource_id;
const char *called_function, *str_resource_id;
zend_long recorded_arguments_index;
SCOUT_PASSTHRU_IF_ALREADY_INSTRUMENTING(called_function)
called_function = determine_function_name(execute_data);
ZEND_PARSE_PARAMETERS_START(1, 10)
Z_PARAM_RESOURCE(resource_id)
SCOUT_ZEND_PARSE_PARAMETERS_END();
handler_index = handler_index_for_function(called_function);
str_resource_id = unique_resource_id(SCOUT_WRAPPER_TYPE_FILE, resource_id);
recorded_arguments_index = find_index_for_recorded_arguments(str_resource_id);
free((void*) str_resource_id);
if (recorded_arguments_index < 0) {
free((void*) called_function);
scoutapm_default_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
return;
}
original_handlers[handler_index](INTERNAL_FUNCTION_PARAM_PASSTHRU);
record_observed_stack_frame(
called_function,
entered,
scoutapm_microtime(),
SCOUTAPM_G(disconnected_call_argument_store)[recorded_arguments_index].argc,
SCOUTAPM_G(disconnected_call_argument_store)[recorded_arguments_index].argv
);
free((void*) called_function);
}