Skip to content

Commit

Permalink
Feat join cut get caller (#64)
Browse files Browse the repository at this point in the history
* feat(php): pinpoint_get_caller_arg
* pinpoint_get_caller_arg and phpt
* update pinpoint_php module version 0.5.2
* - remove `fastapi==0.109.1` , it crashes CI
* simple_php for curl/redis/memcache/mysql
  • Loading branch information
eeliu committed Jul 1, 2024
1 parent 32135bb commit 2032bdf
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 146 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on: [pull_request, workflow_dispatch,push]
on: [pull_request, workflow_dispatch, push]

jobs:
cpp:
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
./build/bin/Debug/TestCommon.exe
memory-leak:
needs: [ cpp , cpp-windows]
needs: [cpp, cpp-windows]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -73,10 +73,10 @@ jobs:

PHP:
runs-on: ubuntu-latest
needs: cpp
needs: cpp
strategy:
matrix:
php-version: ["7.2", "7.3", "7.4","8.0","8.1","8.2","8.3"]
php-version: ["7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3"]
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -100,7 +100,7 @@ jobs:
os: [ubuntu-latest, macos-13]
python-version: ["3.8", "3.9", "3.10", "3.11"]
runs-on: ${{ matrix.os }}
needs: [ cpp , cpp-windows]
needs: [cpp, cpp-windows]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand Down
3 changes: 2 additions & 1 deletion plugins/PY/pinpointPy/libs/_psycopg2/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ def test_case(self):
conn = psycopg2.connect(
dbname="test", user="test", password="pinpoint", host="postgres", port=5432)
cur = conn.cursor()
cur.execute("DROP TABLE IF EXISTS test")
cur.execute(
"CREATE TABLE test (id serial PRIMARY KEY, num integer, data varchar);")
cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)",
(100, "abc'def"))
cur.execute("SELECT * FROM test;")
resp = cur.fetchone()
cur.fetchone()
conn.commit()
cur.close()
conn.close()
Expand Down
3 changes: 3 additions & 0 deletions src/PHP/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.5.2 2024-05-30
- add pinpoint_get_caller_arg

## 0.5.1 2024-05-29
- add _pinpoint_join_cut and test case
- rename api naming
Expand Down
1 change: 1 addition & 0 deletions src/PHP/php_pinpoint_php.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ PHP_FUNCTION(_pinpoint_add_clue);
PHP_FUNCTION(_pinpoint_add_clues);
PHP_FUNCTION(_pinpoint_unique_id);
PHP_FUNCTION(pinpoint_get_this);
PHP_FUNCTION(pinpoint_get_caller_arg);
PHP_FUNCTION(_pinpoint_trace_limit);
PHP_FUNCTION(_pinpoint_drop_trace);
PHP_FUNCTION(_pinpoint_start_time);
Expand Down
71 changes: 71 additions & 0 deletions src/PHP/pinpoint_php.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_add_timestamp, 0, 0, 0)
ZEND_ARG_INFO(0, timestamp)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_add_arg_index, 0, 0, 0)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_add_id, 0, 0, 0)
ZEND_ARG_INFO(0, nodeid)
ZEND_END_ARG_INFO()
Expand All @@ -146,6 +150,7 @@ const zend_function_entry pinpoint_php_functions[] = {
PHP_FE(_pinpoint_end_trace, arginfo_add_id)
PHP_FE(_pinpoint_unique_id, arginfo_none)
PHP_FE(pinpoint_get_this, arginfo_none)
PHP_FE(pinpoint_get_caller_arg,arginfo_add_arg_index)
PHP_FE(pinpoint_status, arginfo_none)
// PHP__FE(pinpoint_get_func_ref_args, arginfo_none)
PHP_FE(_pinpoint_drop_trace, arginfo_add_id)
Expand Down Expand Up @@ -271,6 +276,72 @@ PHP_FUNCTION(_pinpoint_set_context) {
RETURN_TRUE;
}

// ref from ZEND_FUNCTION(func_get_arg)
PHP_FUNCTION(pinpoint_get_caller_arg) {
uint32_t arg_count, first_extra_arg;
zval *arg;
zend_long requested_offset;
zend_execute_data *ex;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &requested_offset) ==
FAILURE) {
return;
}

if (requested_offset < 0) {
zend_error(
E_WARNING,
"pinpoint_get_caller_arg(): The argument number should be >= 0");
RETURN_FALSE;
}

// changes
// ex = EX(prev_execute_data)
ex = EX(prev_execute_data)->prev_execute_data;
if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
zend_error(E_WARNING, "pinpoint_get_caller_arg(): Called from the global "
"scope - no function context");
RETURN_FALSE;
}
#if PHP_MAJOR_VERSION == 8 && PHP_MINOR_VERSION >= 2
if (zend_forbid_dynamic_call() == FAILURE) {
RETURN_THROWS();
}
#else
if (zend_forbid_dynamic_call("pinpoint_get_caller_arg()") == FAILURE) {
RETURN_FALSE;
}
#endif
arg_count = ZEND_CALL_NUM_ARGS(ex);

if ((zend_ulong)requested_offset >= arg_count) {
zend_error(E_WARNING,
"pinpoint_get_caller_arg(): Argument " ZEND_LONG_FMT
" not passed to function",
requested_offset);
RETURN_FALSE;
}

first_extra_arg = ex->func->op_array.num_args;
if ((zend_ulong)requested_offset >= first_extra_arg &&
(ZEND_CALL_NUM_ARGS(ex) > first_extra_arg)) {
arg = ZEND_CALL_VAR_NUM(ex, ex->func->op_array.last_var +
ex->func->op_array.T) +
(requested_offset - first_extra_arg);
} else {
arg = ZEND_CALL_ARG(ex, requested_offset + 1);
}
if (EXPECTED(!Z_ISUNDEF_P(arg))) {

#if PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION <= 2
ZVAL_DEREF(arg);
ZVAL_COPY(return_value, arg);
#else
ZVAL_COPY_DEREF(return_value, arg);
#endif
}
}

PHP_FUNCTION(_pinpoint_get_context) {
long _id = -1;
std::string key;
Expand Down
122 changes: 0 additions & 122 deletions src/PHP/pinpoint_php_api.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
}
},
"require": {
"pinpoint-apm/pinpoint-php-aop": "@dev",
"pinpoint-apm/pinpoint-php-aop": "dev-feat-join-cut-api",
"mongodb/mongodb": "^1.18"
},
"repositories": [
{
"type": "path",
"url": "/home/pinpoint/pinpoint-php-aop"
}
]
}
}
10 changes: 8 additions & 2 deletions testapps/SimplePHP/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
}
},
"require": {
"pinpoint-apm/pinpoint-php-aop": "dev-feat-join-cut-api",
"pinpoint-apm/pinpoint-php-aop": "@dev",
"mongodb/mongodb": "^1.18"
}
},
"repositories": [
{
"type": "path",
"url": "/home/pinpoint/pinpoint-php-aop"
}
]
}
5 changes: 4 additions & 1 deletion testapps/SimplePHP/php.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
extension=mongodb.so
extension=redis.so
extension=memcached.so

[pinpoint_php]
extension=pinpoint_php
Expand All @@ -8,4 +10,5 @@ pinpoint_php.DebugReport=true

[error_log]
error_reporting = E_ALL | E_STRICT
log_errors= On
log_errors= On

Loading

0 comments on commit 2032bdf

Please sign in to comment.