Skip to content

Commit

Permalink
Determine unique names for resources used for stored argument lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
asgrim committed Oct 31, 2019
1 parent 65c414d commit ca92326
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
6 changes: 2 additions & 4 deletions scout_curl_wrapper.c
Expand Up @@ -21,8 +21,7 @@ ZEND_NAMED_FUNCTION(scoutapm_curl_setopt_handler)
ZEND_PARSE_PARAMETERS_END();

if (options == CURLOPT_URL) {
// @todo make call reference actually unique
record_arguments_for_call("curl_exec", 1, zvalue);
record_arguments_for_call(unique_resource_id(SCOUT_WRAPPER_TYPE_CURL, zid), 1, zvalue);
}

SCOUT_INTERNAL_FUNCTION_PASSTHRU();
Expand Down Expand Up @@ -50,8 +49,7 @@ ZEND_NAMED_FUNCTION(scoutapm_curl_exec_handler)
return;
}

// @todo make call reference actually unique
recorded_arguments_index = find_index_for_recorded_arguments("curl_exec");
recorded_arguments_index = find_index_for_recorded_arguments(unique_resource_id(SCOUT_WRAPPER_TYPE_CURL, resource_id));

if (recorded_arguments_index < 0) {
// @todo maybe log a warning? happens if we call curl_exec without setting the URL...
Expand Down
1 change: 1 addition & 0 deletions scout_extern.h
Expand Up @@ -15,6 +15,7 @@ extern zend_long find_index_for_recorded_arguments(const char *call_reference);
extern void record_observed_stack_frame(const char *function_name, double microtime_entered, double microtime_exited, int argc, zval *argv);
extern int handler_index_for_function(const char *function_to_lookup);
extern const char* determine_function_name(zend_execute_data *execute_data);
extern const char *unique_resource_id(const char *scout_wrapper_type, zval *resource_id);

ZEND_EXTERN_MODULE_GLOBALS(scoutapm);
extern indexed_handler_lookup handler_lookup[];
Expand Down
7 changes: 3 additions & 4 deletions scout_file_wrapper.c
Expand Up @@ -22,10 +22,10 @@ ZEND_NAMED_FUNCTION(scoutapm_fopen_handler)
ZVAL_STR(&argv[0], filename);
ZVAL_STR(&argv[1], mode);

// @todo make call reference actually unique
record_arguments_for_call("file", 2, argv);

SCOUT_INTERNAL_FUNCTION_PASSTHRU();

record_arguments_for_call(unique_resource_id(SCOUT_WRAPPER_TYPE_FILE, return_value), 2, argv);
}

ZEND_NAMED_FUNCTION(scoutapm_fread_handler)
Expand All @@ -51,8 +51,7 @@ ZEND_NAMED_FUNCTION(scoutapm_fread_handler)
return;
}

// @todo make call reference actually unique
recorded_arguments_index = find_index_for_recorded_arguments("file");
recorded_arguments_index = find_index_for_recorded_arguments(unique_resource_id(SCOUT_WRAPPER_TYPE_FILE, resource_id));

if (recorded_arguments_index < 0) {
// @todo maybe log a warning? happens if we call fread without calling fopen...
Expand Down
19 changes: 19 additions & 0 deletions zend_scoutapm.c
Expand Up @@ -313,6 +313,25 @@ zend_long find_index_for_recorded_arguments(const char *call_reference)
return -1;
}

const char *unique_resource_id(const char *scout_wrapper_type, zval *resource_id)
{
int len;
char *ret;

if (Z_TYPE_P(resource_id) != IS_RESOURCE) {
zend_throw_exception(NULL, "ScoutAPM extension was passed a zval that was not a resource", 0);
return "";
}

DYNAMIC_MALLOC_SPRINTF(ret, len,
"%s_handle(%d)_type(%d)",
scout_wrapper_type,
Z_RES_HANDLE_P(resource_id),
Z_RES_TYPE_P(resource_id)
);
return ret;
}

/*
* Helper function to handle memory allocation for recorded stack frames. Called each time a function has completed
* that we're interested in.
Expand Down
4 changes: 4 additions & 0 deletions zend_scoutapm.h
Expand Up @@ -129,4 +129,8 @@ typedef void (*zif_handler)(INTERNAL_FUNCTION_PARAMETERS);
#define SCOUT_GET_CALLS_KEY_TIME_TAKEN "time_taken"
#define SCOUT_GET_CALLS_KEY_ARGV "argv"

/* stored argument wrapper constants */
#define SCOUT_WRAPPER_TYPE_CURL "curl_exec"
#define SCOUT_WRAPPER_TYPE_FILE "file"

#endif /* ZEND_SCOUTAPM_H */

0 comments on commit ca92326

Please sign in to comment.