Skip to content

Commit 97b3c90

Browse files
committed
refactor wraprec storage and lookup [wip]
Implement wraprec lookup by scope and function name. The implementation uses two specialized hashmaps: one for global functions and another one for scopes. The scopes hashmap's values are hashmaps for scoped methods. The hashmaps use keys composed of not only the string and its length but also zend string's hash. This hash is used to find the bucket index. The decision to include zend string's hash was deliberate because the agent gets it for free when it needs to lookup the wraprec based on scope and function name that are available in execute_data's op array as zend_strings.
1 parent d12eda5 commit 97b3c90

7 files changed

+597
-3
lines changed

agent/Makefile.frag

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ TEST_BINARIES = \
117117
tests/test_txn_private \
118118
tests/test_user_instrument \
119119
tests/test_user_instrument_hashmap \
120+
tests/test_user_instrument_wraprec_hashmap \
120121
tests/test_zval
121122

122123
.PHONY: unit-tests

agent/config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ if test "$PHP_NEWRELIC" = "yes"; then
220220
php_pdo_mysql.c php_pdo_pgsql.c php_pgsql.c php_psr7.c php_redis.c \
221221
php_rinit.c php_rshutdown.c php_samplers.c php_stack.c \
222222
php_stacked_segment.c php_txn.c php_user_instrument.c \
223+
php_user_instrument_wraprec_hashmap.c \
223224
php_user_instrument_hashmap.c php_vm.c php_wrapper.c"
224225
FRAMEWORKS="fw_cakephp.c fw_codeigniter.c fw_drupal8.c \
225226
fw_drupal.c fw_drupal_common.c fw_joomla.c fw_kohana.c \

agent/php_user_instrument.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ void nr_php_init_user_instrumentation(void) {
175175
* wrapped). This happens because with new request/transaction php is loading
176176
* all new user code.
177177
*/
178-
static void nr_php_user_wraprec_destroy(nruserfn_t** wraprec_ptr);
179178
static void reset_wraprec(nruserfn_t* wraprec) {
180179
nruserfn_t* p = wraprec;
181180
nr_php_wraprec_hashmap_key_release(&p->key);
@@ -301,7 +300,7 @@ static void nr_php_wrap_user_function_internal(nruserfn_t* wraprec TSRMLS_DC) {
301300
nr_php_wrap_zend_function(orig_func, wraprec TSRMLS_CC);
302301
}
303302

304-
static nruserfn_t* nr_php_user_wraprec_create(void) {
303+
nruserfn_t* nr_php_user_wraprec_create(void) {
305304
nruserfn_t* wr = (nruserfn_t*)nr_zalloc(sizeof(nruserfn_t));
306305
wr->pid = NRPRG(pid);
307306
return wr;
@@ -357,7 +356,7 @@ static nruserfn_t* nr_php_user_wraprec_create_named(const char* full_name,
357356
return wraprec;
358357
}
359358

360-
static void nr_php_user_wraprec_destroy(nruserfn_t** wraprec_ptr) {
359+
void nr_php_user_wraprec_destroy(nruserfn_t** wraprec_ptr) {
361360
nruserfn_t* wraprec;
362361

363362
if (0 == wraprec_ptr) {

agent/php_user_instrument.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ extern int nr_zend_call_oapi_special_clean(nruserfn_t* wraprec,
218218
nr_segment_t* segment,
219219
NR_EXECUTE_PROTO);
220220
#endif
221+
extern nruserfn_t* nr_php_user_wraprec_create(void);
222+
extern void nr_php_user_wraprec_destroy(nruserfn_t** wraprec_ptr);
221223
/*
222224
* Purpose : Destroy all user instrumentation records, freeing
223225
* associated memory.

0 commit comments

Comments
 (0)