Skip to content

Commit c8b0880

Browse files
committed
simplify everything
1 parent 330b5c6 commit c8b0880

File tree

1 file changed

+20
-41
lines changed

1 file changed

+20
-41
lines changed

agent/php_internal_instrument.c

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -800,35 +800,6 @@ static void nr_php_instrument_datastore_operation_call(
800800
}
801801
}
802802

803-
/*
804-
* Like nr_php_instrument_datastore_operation_call() but does not
805-
* call the underlying internal function. This allows multiple
806-
* datastore metrics to be creating during a single underlying
807-
* PHP call.
808-
*/
809-
static void nr_php_instrument_datastore_operation(
810-
nr_datastore_t datastore,
811-
const char* operation,
812-
nr_datastore_instance_t* instance,
813-
bool instance_only) {
814-
nr_segment_t* segment = NULL;
815-
nr_segment_datastore_params_t params = {
816-
.datastore = {
817-
.type = datastore,
818-
},
819-
.operation = nr_strdup(operation),
820-
.instance = instance,
821-
.instance_only = instance_only,
822-
.callbacks = {
823-
.backtrace = nr_php_backtrace_callback,
824-
},
825-
};
826-
827-
segment = nr_segment_start(NRPRG(txn), NULL, NULL);
828-
nr_segment_datastore_end(&segment, &params);
829-
nr_free(params.operation);
830-
}
831-
832803
/*
833804
* Handle
834805
* bool mysqli_commit ( object $link [, int $flags=0, string $name] )
@@ -1570,32 +1541,37 @@ NR_INNER_WRAPPER(memcached_add_server) {
15701541
zend_long port = 0;
15711542
zend_long weight = 0;
15721543
nr_datastore_instance_t* instance = NULL;
1544+
char* instance_metric = NULL;
15731545
int zcaught = 0;
1546+
nr_segment_t* segment = nr_segment_start(NRPRG(txn), NULL, NULL);
15741547

15751548
if (SUCCESS
15761549
== zend_parse_parameters_ex(
15771550
ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "s|ll", &host,
15781551
&host_len, &port, &weight) &&
15791552
NULL != host) {
15801553
instance = nr_php_memcached_create_datastore_instance(host, port);
1581-
nr_php_instrument_datastore_operation_call(nr_wrapper, NR_DATASTORE_MEMCACHE,
1582-
NULL, instance, true,
1583-
INTERNAL_FUNCTION_PARAM_PASSTHRU);
1584-
} else {
1585-
zcaught = nr_zend_call_old_handler(nr_wrapper->oldhandler,
1586-
INTERNAL_FUNCTION_PARAM_PASSTHRU);
1587-
if (zcaught) {
1588-
zend_bailout();
1589-
/* NOTREACHED */
1590-
}
1554+
instance_metric = nr_formatf("Datastore/instance/Memcached/%s/%s",
1555+
instance->host, instance->port_path_or_id);
1556+
nr_free(instance);
1557+
nr_segment_add_metric(segment, instance_metric, false);
1558+
}
1559+
zcaught = nr_zend_call_old_handler(nr_wrapper->oldhandler,
1560+
INTERNAL_FUNCTION_PARAM_PASSTHRU);
1561+
nr_segment_end(&segment);
1562+
if (zcaught) {
1563+
zend_bailout();
1564+
/* NOTREACHED */
15911565
}
15921566
}
15931567

15941568
NR_INNER_WRAPPER(memcached_add_servers) {
15951569
zval* servers = NULL;
15961570
zval* server = NULL;
15971571
nr_datastore_instance_t* instance = NULL;
1572+
char* instance_metric = NULL;
15981573
int zcaught = 0;
1574+
nr_segment_t* segment = nr_segment_start(NRPRG(txn), NULL, NULL);
15991575

16001576
if (SUCCESS
16011577
== zend_parse_parameters_ex(
@@ -1607,8 +1583,10 @@ NR_INNER_WRAPPER(memcached_add_servers) {
16071583
if (NULL != host && NULL != port &&
16081584
Z_TYPE_P(host) == IS_STRING && Z_TYPE_P(port) == IS_LONG) {
16091585
instance = nr_php_memcached_create_datastore_instance(Z_STRVAL_P(host), Z_LVAL_P(port));
1610-
nr_php_instrument_datastore_operation(NR_DATASTORE_MEMCACHE,
1611-
NULL, instance, true);
1586+
instance_metric = nr_formatf("Datastore/instance/Memcached/%s/%s",
1587+
instance->host, instance->port_path_or_id);
1588+
nr_segment_add_metric(segment, instance_metric, false);
1589+
nr_free(instance);
16121590
}
16131591
}
16141592
ZEND_HASH_FOREACH_END();
@@ -1617,6 +1595,7 @@ NR_INNER_WRAPPER(memcached_add_servers) {
16171595
zcaught = nr_zend_call_old_handler(nr_wrapper->oldhandler,
16181596
INTERNAL_FUNCTION_PARAM_PASSTHRU);
16191597

1598+
nr_segment_end(&segment);
16201599
if (zcaught) {
16211600
zend_bailout();
16221601
/* NOTREACHED */

0 commit comments

Comments
 (0)