提交 2d572800 编写于 作者: H heyanlong

fix predis

上级 10172501
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "main/SAPI.h" /* for sapi_module */ #include "main/SAPI.h" /* for sapi_module */
#include "zend_smart_str.h" /* for smart_str */ #include "zend_smart_str.h" /* for smart_str */
#include <zend_interfaces.h>
#include "php.h" #include "php.h"
#include "php_ini.h" #include "php_ini.h"
#include "ext/standard/info.h" #include "ext/standard/info.h"
...@@ -102,7 +103,6 @@ PHP_FUNCTION(skywalking_get_trace_info) ...@@ -102,7 +103,6 @@ PHP_FUNCTION(skywalking_get_trace_info)
array_init(&empty); array_init(&empty);
RETURN_ZVAL(&empty, 0, 1); RETURN_ZVAL(&empty, 0, 1);
} }
// return array // return array
RETURN_ZVAL(&SKYWALKING_G(UpstreamSegment), 1, 0) RETURN_ZVAL(&SKYWALKING_G(UpstreamSegment), 1, 0)
} }
...@@ -168,18 +168,22 @@ ZEND_API void sky_execute_ex(zend_execute_data *execute_data) { ...@@ -168,18 +168,22 @@ ZEND_API void sky_execute_ex(zend_execute_data *execute_data) {
char *operationName = NULL; char *operationName = NULL;
if (class_name != NULL) { if (class_name != NULL) {
if (strcmp(class_name, "Predis\\Client") == 0 && strcmp(function_name, "__call") == 0) { if (strcmp(class_name, "Predis\\Client") == 0 && strcmp(function_name, "executeCommand") == 0) {
// params // params
uint32_t arg_count = ZEND_CALL_NUM_ARGS(execute_data); uint32_t arg_count = ZEND_CALL_NUM_ARGS(execute_data);
if (arg_count) { if (arg_count) {
zval *p = ZEND_CALL_ARG(execute_data, 1); zval *p = ZEND_CALL_ARG(execute_data, 1);
if (Z_TYPE_P(p) == IS_STRING) { zval *id = (zval *) emalloc(sizeof(zval));
operationName = (char *) emalloc(strlen(class_name) + strlen(Z_STRVAL_P(p)) + 3); zend_call_method(p, Z_OBJCE_P(p), NULL, ZEND_STRL("getid"), id, 0, NULL, NULL);
if (Z_TYPE_P(id) == IS_STRING) {
operationName = (char *) emalloc(strlen(class_name) + strlen(Z_STRVAL_P(id)) + 3);
strcpy(operationName, class_name); strcpy(operationName, class_name);
strcat(operationName, "->"); strcat(operationName, "->");
strcat(operationName, Z_STRVAL_P(p)); strcat(operationName, Z_STRVAL_P(id));
} }
efree(id);
} }
} }
} }
...@@ -188,77 +192,49 @@ ZEND_API void sky_execute_ex(zend_execute_data *execute_data) { ...@@ -188,77 +192,49 @@ ZEND_API void sky_execute_ex(zend_execute_data *execute_data) {
zval tags; zval tags;
array_init(&tags); array_init(&tags);
if (strcmp(class_name, "Predis\\Client") == 0 && strcmp(function_name, "__call") == 0) { if (strcmp(class_name, "Predis\\Client") == 0 && strcmp(function_name, "executeCommand") == 0) {
add_assoc_string(&tags, "db.type", "redis"); add_assoc_string(&tags, "db.type", "redis");
uint32_t arg_count = ZEND_CALL_NUM_ARGS(execute_data); zval *p = ZEND_CALL_ARG(execute_data, 1);
zval *fname = ZEND_CALL_ARG(execute_data, 1); zval *id = (zval *) emalloc(sizeof(zval));
int i; zval *arguments = (zval *) emalloc(sizeof(zval));
for (i = 1; i < arg_count + 1; ++i) { zend_call_method(p, Z_OBJCE_P(p), NULL, ZEND_STRL("getid"), id, 0, NULL, NULL);
if (i == 1) { zend_call_method(p, Z_OBJCE_P(p), NULL, ZEND_STRL("getarguments"), arguments, 0, NULL, NULL);
continue;
} if (Z_TYPE_P(arguments) == IS_ARRAY) {
zval *pam = ZEND_CALL_ARG(execute_data, i); zend_ulong num_key;
if (Z_TYPE_P(pam) == IS_ARRAY) { zval *entry;
zend_ulong num_key; smart_str command = {0};
zval *entry; smart_str_appends(&command, Z_STRVAL_P(id));
int is_string_command = 0; smart_str_appends(&command, " ");
smart_str command = {0}; ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(arguments), num_key, entry)
ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(pam), num_key, entry) {
{ switch (Z_TYPE_P(entry)) {
char *fnamewall = (char *) emalloc(strlen(Z_STRVAL_P(fname)) + 3); case IS_STRING:
sprintf(fnamewall, "|%s|", Z_STRVAL_P(fname));
// strtolower for matching redis key
fnamewall = php_strtolower(fnamewall, strlen(fnamewall));
// first params
if (num_key == 0) {
switch (Z_TYPE_P(entry)) {
case IS_STRING:
is_string_command = 1;
smart_str_appends(&command, php_strtolower(Z_STRVAL_P(fname), Z_STRLEN_P(fname)));
smart_str_appends(&command, " ");
// string
if (strstr(REDIS_KEY_STRING, fnamewall)
|| strstr(REDIS_KEY_KEY, fnamewall)
|| strstr(REDIS_KEY_HASH, fnamewall)
|| strstr(REDIS_KEY_LIST, fnamewall)
|| strstr(REDIS_KEY_SET, fnamewall)
|| strstr(REDIS_KEY_SORT, fnamewall)
|| strstr(REDIS_KEY_HLL, fnamewall)
|| strstr(REDIS_KEY_GEO, fnamewall)
) { // add tag key
add_assoc_string(&tags, "redis.key", Z_STRVAL_P(entry));
} else if (strstr(REDIS_OPERATION_STRING, fnamewall)) { // add tag operation
add_assoc_string(&tags, "redis.operation", Z_STRVAL_P(entry));
}
break;
case IS_ARRAY:
// @todo
break;
}
}
// collect command params for string command
if (is_string_command == 1) {
if (Z_TYPE_P(entry) != IS_STRING) {
convert_to_string(entry);
}
smart_str_appends(&command, Z_STRVAL_P(entry)); smart_str_appends(&command, Z_STRVAL_P(entry));
smart_str_appends(&command, " "); smart_str_appends(&command, " ");
} break;
efree(fnamewall); case IS_ARRAY:
break;
default:
convert_to_string(entry)
smart_str_appends(&command, Z_STRVAL_P(entry));
smart_str_appends(&command, " ");
break;
} }
ZEND_HASH_FOREACH_END(); }
ZEND_HASH_FOREACH_END();
// store command to tags
if (command.s) { // store command to tags
smart_str_0(&command); if (command.s) {
add_assoc_string(&tags, "redis.command", ZSTR_VAL(php_trim(command.s, NULL, 0, 3))); smart_str_0(&command);
smart_str_free(&command); add_assoc_string(&tags, "redis.command", ZSTR_VAL(command.s));
} smart_str_free(&command);
} }
} }
zval_ptr_dtor(id);
zval_ptr_dtor(arguments);
efree(id);
efree(arguments);
} }
zval temp; zval temp;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册