Skip to content

Commit

Permalink
cufa performance
Browse files Browse the repository at this point in the history
  • Loading branch information
ZNeumann committed Sep 11, 2023
1 parent fae2aed commit b94d074
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
4 changes: 4 additions & 0 deletions agent/fw_drupal_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ void nr_drupal_invoke_all_hook_stacks_push(zval* hook_copy) {
if (nr_php_is_zval_non_empty_string(hook_copy)) {
nr_stack_push(&NRPRG(drupal_invoke_all_hooks), hook_copy);
nr_stack_push(&NRPRG(drupal_invoke_all_states), (void*)!NULL);
NRPRG(check_cufa) = true;
} else {
nr_stack_push(&NRPRG(drupal_invoke_all_states), NULL);
}
Expand All @@ -311,5 +312,8 @@ void nr_drupal_invoke_all_hook_stacks_pop() {
zval* hook_copy = nr_stack_pop(&NRPRG(drupal_invoke_all_hooks));
nr_php_arg_release(&hook_copy);
}
if (nr_stack_is_empty(&NRPRG(drupal_invoke_all_hooks))) {
NRPRG(check_cufa) = false;
}
}
#endif
11 changes: 9 additions & 2 deletions agent/fw_wordpress.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ NR_PHP_WRAPPER(nr_wordpress_exec_handle_tag) {
* the call_user_func_array instrumentation take care of actually timing
* the hooks by checking if it's set.
*/
NRPRG(check_cufa) = true;
nr_stack_push(&NRPRG(wordpress_tags),
nr_wordpress_clean_tag(tag TSRMLS_CC));
nr_stack_push(&NRPRG(wordpress_tag_states), (void*)!NULL);
Expand Down Expand Up @@ -624,6 +625,7 @@ NR_PHP_WRAPPER(nr_wordpress_apply_filters) {
* the call_user_func_array instrumentation take care of actually timing
* the hooks by checking if it's set.
*/
NRPRG(check_cufa) = true;
nr_stack_push(&NRPRG(wordpress_tags),
nr_wordpress_clean_tag(tag TSRMLS_CC));
nr_stack_push(&NRPRG(wordpress_tag_states), (void*)!NULL);
Expand Down Expand Up @@ -668,6 +670,9 @@ static void clean_wordpress_tag_stack() {
char* cleaned_tag = nr_stack_pop(&NRPRG(wordpress_tags));
nr_free(cleaned_tag);
}
if (nr_stack_is_empty(&NRPRG(wordpress_tags))) {
NRPRG(check_cufa) = false;
}
}

NR_PHP_WRAPPER(nr_wordpress_handle_tag_stack_after) {
Expand Down Expand Up @@ -740,6 +745,8 @@ void nr_wordpress_enable(TSRMLS_D) {
nr_wordpress_exec_handle_tag TSRMLS_CC);
#endif /* OAPI */

nr_php_add_call_user_func_array_pre_callback(
nr_wordpress_call_user_func_array TSRMLS_CC);
if (0 != NRINI(wordpress_hooks)) {
nr_php_add_call_user_func_array_pre_callback(
nr_wordpress_call_user_func_array TSRMLS_CC);
}
}
12 changes: 6 additions & 6 deletions agent/php_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1930,11 +1930,6 @@ static void nr_php_observer_attempt_call_cufa_handler(NR_EXECUTE_PROTO) {
return;
}

if (NULL == execute_data->prev_execute_data->opline) {
nrl_verbosedebug(NRL_AGENT, "%s: cannot get previous opline", __func__);
return;
}

/*
* COPIED Comment from php_vm.c:
* To actually determine whether this is a call_user_func_array() call we
Expand Down Expand Up @@ -1979,6 +1974,11 @@ static void nr_php_observer_attempt_call_cufa_handler(NR_EXECUTE_PROTO) {
return;
}

if (UNEXPECTED(NULL == execute_data->prev_execute_data->opline)) {
nrl_verbosedebug(NRL_AGENT, "%s: cannot get previous opline", __func__);
return;
}

const zend_op* prev_opline = execute_data->prev_execute_data->opline;

/*
Expand Down Expand Up @@ -2031,7 +2031,7 @@ static void nr_php_instrument_func_begin(NR_EXECUTE_PROTO) {
filename TSRMLS_CC);
return;
}
if (UNEXPECTED(NULL != NRPRG(cufa_callback))) {
if (NULL != NRPRG(cufa_callback) && NRPRG(check_cufa)) {
/*
* For PHP 7+, call_user_func_array() is flattened into an inline by default. Because
* of this, we must check the opcodes set to see whether we are calling it flattened.
Expand Down
1 change: 1 addition & 0 deletions agent/php_newrelic.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ int symfony1_in_error404; /* Whether we are currently within a

#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO \
&& !defined OVERWRITE_ZEND_EXECUTE_DATA
bool check_cufa;
/* Without OAPI, we are able to utilize the call stack to keep track
* of the previous tags. With OAPI, we can no longer do this so
* we track the stack manually */
Expand Down
1 change: 1 addition & 0 deletions agent/php_rinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ PHP_RINIT_FUNCTION(newrelic) {
*/
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO \
&& !defined OVERWRITE_ZEND_EXECUTE_DATA
NRPRG(check_cufa) = false;
nr_stack_init(&NRPRG(predis_ctxs), NR_STACK_DEFAULT_CAPACITY);
nr_stack_init(&NRPRG(wordpress_tags), NR_STACK_DEFAULT_CAPACITY);
nr_stack_init(&NRPRG(wordpress_tag_states), NR_STACK_DEFAULT_CAPACITY);
Expand Down

0 comments on commit b94d074

Please sign in to comment.