Skip to content

Commit d12eda5

Browse files
committed
re-use nr_php_show_exec in fcall_init
1 parent 083bf39 commit d12eda5

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

agent/php_execute.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ static inline nruserfn_t* nr_php_get_wraprec_from_op_array_extension(const char*
107107

108108
static void nr_php_show_exec_return(NR_EXECUTE_PROTO TSRMLS_DC);
109109
static int nr_php_show_exec_indentation(TSRMLS_D);
110-
static void nr_php_show_exec(NR_EXECUTE_PROTO TSRMLS_DC);
111110

112111
/*
113112
* Purpose: Enable monitoring on specific functions in the framework.
@@ -606,10 +605,11 @@ static int nr_php_show_exec_indentation(TSRMLS_D) {
606605
* Note that this function doesn't handle internal functions, and will crash if
607606
* you give it one.
608607
*/
609-
static void nr_php_show_exec(NR_EXECUTE_PROTO TSRMLS_DC) {
608+
void nr_php_show_exec(const char* context, NR_EXECUTE_PROTO TSRMLS_DC) {
610609
char argstr[NR_EXECUTE_DEBUG_STRBUFSZ];
611610
const char* filename = nr_php_op_array_file_name(NR_OP_ARRAY);
612611
const char* function_name = nr_php_op_array_function_name(NR_OP_ARRAY);
612+
const char* ctx = context ? context : "execute";
613613
#if ZEND_MODULE_API_NO >= ZEND_7_4_X_API_NO
614614
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO
615615
nruserfn_t* wr = nr_php_get_wraprec_from_op_array_extension(__func__, execute_data->func);
@@ -626,12 +626,13 @@ static void nr_php_show_exec(NR_EXECUTE_PROTO TSRMLS_DC) {
626626
nr_show_execute_params(NR_EXECUTE_ORIG_ARGS, argstr TSRMLS_CC);
627627
nrl_verbosedebug(
628628
NRL_AGENT,
629-
"execute: %.*s scope={%.*s} function={" NRP_FMT_UQ
629+
NRP_FMT_UQ ": %.*s scope={%.*s} function={" NRP_FMT_UQ
630630
"}"
631631
" params={" NRP_FMT_UQ
632632
"}"
633633
" %.5s"
634634
"@ " NRP_FMT_UQ ":%d",
635+
NRP_SHOW_EXEC_CONTEXT(ctx),
635636
nr_php_show_exec_indentation(TSRMLS_C), nr_php_indentation_spaces,
636637
NRSAFELEN(nr_php_class_entry_name_length(NR_OP_ARRAY->scope)),
637638
nr_php_class_entry_name(NR_OP_ARRAY->scope),
@@ -649,12 +650,13 @@ static void nr_php_show_exec(NR_EXECUTE_PROTO TSRMLS_DC) {
649650
nr_show_execute_params(NR_EXECUTE_ORIG_ARGS, argstr TSRMLS_CC);
650651
nrl_verbosedebug(
651652
NRL_AGENT,
652-
"execute: %.*s function={" NRP_FMT_UQ
653+
NRP_FMT_UQ ": %.*s function={" NRP_FMT_UQ
653654
"}"
654655
" params={" NRP_FMT_UQ
655656
"}"
656657
" %.5s"
657658
"@ " NRP_FMT_UQ ":%d",
659+
NRP_SHOW_EXEC_CONTEXT(ctx),
658660
nr_php_show_exec_indentation(TSRMLS_C), nr_php_indentation_spaces,
659661
NRP_PHP(function_name), NRP_ARGSTR(argstr),
660662
#if ZEND_MODULE_API_NO < ZEND_7_4_X_API_NO
@@ -667,16 +669,17 @@ static void nr_php_show_exec(NR_EXECUTE_PROTO TSRMLS_DC) {
667669
/*
668670
* file
669671
*/
670-
nrl_verbosedebug(NRL_AGENT, "execute: %.*s file={" NRP_FMT "}",
672+
nrl_verbosedebug(NRL_AGENT, NRP_FMT_UQ ": %.*s file={" NRP_FMT "}",
673+
NRP_SHOW_EXEC_CONTEXT(ctx),
671674
nr_php_show_exec_indentation(TSRMLS_C),
672675
nr_php_indentation_spaces, NRP_FILENAME(filename));
673676
} else {
674677
/*
675678
* unknown
676679
*/
677-
nrl_verbosedebug(NRL_AGENT, "execute: %.*s ?",
678-
nr_php_show_exec_indentation(TSRMLS_C),
679-
nr_php_indentation_spaces);
680+
nrl_verbosedebug(NRL_AGENT, NRP_FMT_UQ ": %.*s ?",
681+
NRP_SHOW_EXEC_CONTEXT(ctx),
682+
nr_php_show_exec_indentation(TSRMLS_C), nr_php_indentation_spaces);
680683
}
681684
}
682685

@@ -1537,7 +1540,7 @@ static void nr_php_execute_enabled(NR_EXECUTE_PROTO TSRMLS_DC) {
15371540

15381541
static void nr_php_execute_show(NR_EXECUTE_PROTO TSRMLS_DC) {
15391542
if (nrunlikely(NR_PHP_PROCESS_GLOBALS(special_flags).show_executes)) {
1540-
nr_php_show_exec(NR_EXECUTE_ORIG_ARGS TSRMLS_CC);
1543+
nr_php_show_exec("execute", NR_EXECUTE_ORIG_ARGS TSRMLS_CC);
15411544
}
15421545

15431546
nr_php_execute_enabled(NR_EXECUTE_ORIG_ARGS TSRMLS_CC);
@@ -2175,7 +2178,7 @@ void nr_php_observer_fcall_begin(zend_execute_data* execute_data) {
21752178
int show_executes = NR_PHP_PROCESS_GLOBALS(special_flags).show_executes;
21762179

21772180
if (nrunlikely(show_executes)) {
2178-
nr_php_show_exec(NR_EXECUTE_ORIG_ARGS);
2181+
nr_php_show_exec("execute", NR_EXECUTE_ORIG_ARGS);
21792182
}
21802183
nr_php_instrument_func_begin(NR_EXECUTE_ORIG_ARGS);
21812184

agent/php_execute.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
#define OP_ARRAY_IS_METHOD(OP, FNAME) \
2828
(0 == nr_strcmp(nr_php_op_array_function_name(OP), (FNAME)))
2929

30+
/*
31+
* Purpose: Log information about the execute data in a given execution
32+
* context - either 'execute' (zend_execute) or 'observe' (fcall_init).
33+
* Only first 8 characters of the context are printed.
34+
*
35+
* Caveat: This function doesn't handle internal functions, and will crash if
36+
* you give it one.
37+
*/
38+
extern void nr_php_show_exec(const char*, NR_EXECUTE_PROTO TSRMLS_DC);
39+
/* Limit length of execution context printed in the log file to 8 characters */
40+
#define NRP_SHOW_EXEC_CONTEXT(C) 8, NRSAFESTR(C)
41+
3042
/*
3143
* Purpose: Look through the PHP symbol table for special names or symbols
3244
* that provide additional hints that a specific framework has been loaded.

agent/php_observer.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,8 @@ static zend_observer_fcall_handlers nr_php_fcall_register_handlers(
8484
return handlers;
8585
}
8686

87-
if (!OP_ARRAY_IS_A_FILE(NR_OP_ARRAY)) {
88-
nrl_verbosedebug(NRL_AGENT, "Registering Observer API handlers for user function %s",
89-
NRSAFESTR(nr_php_op_array_function_name(NR_OP_ARRAY)));
90-
} else {
91-
nrl_verbosedebug(NRL_AGENT, "Registering Observer API handlers for file %s",
92-
NRSAFESTR(nr_php_op_array_file_name(NR_OP_ARRAY)));
87+
if (nrunlikely(NR_PHP_PROCESS_GLOBALS(special_flags).show_executes)) {
88+
nr_php_show_exec("observe", execute_data, NULL);
9389
}
9490

9591
wr = nr_php_get_wraprec(execute_data->func);

0 commit comments

Comments
 (0)