diff --git a/auto_pinpointed.php b/auto_pinpointed.php index 955ff1b..a8e1483 100644 --- a/auto_pinpointed.php +++ b/auto_pinpointed.php @@ -1,13 +1,15 @@ start(); - if(defined('PP_REQ_PLUGINS') && class_exists(PP_REQ_PLUGINS)){ $plugins = PP_REQ_PLUGINS; $plugins::instance(); +}else{ + PerRequestPlugins::instance(); } diff --git a/composer.json b/composer.json index 6709e85..485f22b 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "autoload": { "psr-4": { - "pinpoint\\": "lib/pinpoint/" + "Pinpoint\\": "lib/Pinpoint/" } }, "minimum-stability": "dev", @@ -19,6 +19,7 @@ "phpunit/phpunit": "^7" }, "require": { + "php": ">=7", "nikic/php-parser": "^4.1" } } diff --git a/lib/pinpoint/Common/ClassFile.php b/lib/Pinpoint/Common/ClassFile.php similarity index 99% rename from lib/pinpoint/Common/ClassFile.php rename to lib/Pinpoint/Common/ClassFile.php index 371fe00..8051577 100644 --- a/lib/pinpoint/Common/ClassFile.php +++ b/lib/Pinpoint/Common/ClassFile.php @@ -21,7 +21,7 @@ * Time: 11:36 AM */ -namespace pinpoint\Common; +namespace Pinpoint\Common; use PhpParser\Node; use PhpParser\PrettyPrinter; diff --git a/lib/pinpoint/Common/CodeVisitor.php b/lib/Pinpoint/Common/CodeVisitor.php similarity index 98% rename from lib/pinpoint/Common/CodeVisitor.php rename to lib/Pinpoint/Common/CodeVisitor.php index 55d9cbf..e185195 100644 --- a/lib/pinpoint/Common/CodeVisitor.php +++ b/lib/Pinpoint/Common/CodeVisitor.php @@ -21,12 +21,12 @@ * Time: 10:33 AM */ -namespace pinpoint\Common; +namespace Pinpoint\Common; use PhpParser\NodeVisitorAbstract; use PhpParser\Node; use PhpParser\NodeTraverser; -//use pinpoint\Common\GenRequiredBIFileHelper; +//use Pinpoint\Common\GenRequiredBIFileHelper; class CodeVisitor extends NodeVisitorAbstract { diff --git a/lib/pinpoint/Common/GenOriginClassFileHelper.php b/lib/Pinpoint/Common/GenOriginClassFileHelper.php similarity index 99% rename from lib/pinpoint/Common/GenOriginClassFileHelper.php rename to lib/Pinpoint/Common/GenOriginClassFileHelper.php index 303465f..66cfd2e 100644 --- a/lib/pinpoint/Common/GenOriginClassFileHelper.php +++ b/lib/Pinpoint/Common/GenOriginClassFileHelper.php @@ -21,13 +21,13 @@ * Time: 4:41 PM */ -namespace pinpoint\Common; +namespace Pinpoint\Common; -use pinpoint\Common\ClassFile; +use Pinpoint\Common\ClassFile; use PhpParser\BuilderFactory; use PhpParser\PrettyPrinter; use PhpParser\Node; -use pinpoint\Common\PluginParser; +use Pinpoint\Common\PluginParser; class GenOriginClassFileHelper extends ClassFile { diff --git a/lib/pinpoint/Common/GenProxiedClassFileHelper.php b/lib/Pinpoint/Common/GenProxiedClassFileHelper.php similarity index 98% rename from lib/pinpoint/Common/GenProxiedClassFileHelper.php rename to lib/Pinpoint/Common/GenProxiedClassFileHelper.php index e8b90a1..a9547d1 100644 --- a/lib/pinpoint/Common/GenProxiedClassFileHelper.php +++ b/lib/Pinpoint/Common/GenProxiedClassFileHelper.php @@ -21,11 +21,11 @@ * Time: 10:28 AM */ -namespace pinpoint\Common; +namespace Pinpoint\Common; use PhpParser\NodeVisitorAbstract; use PhpParser\Node; -use pinpoint\Common\PluginParser; -use pinpoint\Common\ClassFile; +use Pinpoint\Common\PluginParser; +use Pinpoint\Common\ClassFile; class GenProxiedClassFileHelper extends ClassFile { @@ -58,8 +58,7 @@ private function getRealNp($node) return $node->toString(); }elseif ($node instanceof Node\Expr\Variable){ //#16 support new a variable return $node->name; - } - else{ // Use namespace suggestion + }elseif($node instanceof Node\Name){ // Use namespace suggestion $prefixNm = $node->getFirst(); if(isset($this->suffix_use[$prefixNm])){ $prefix = $this->suffix_use[$prefixNm]; diff --git a/lib/pinpoint/Common/NamingConf.php b/lib/Pinpoint/Common/NamingConf.php similarity index 98% rename from lib/pinpoint/Common/NamingConf.php rename to lib/Pinpoint/Common/NamingConf.php index a849c48..2aa0636 100644 --- a/lib/pinpoint/Common/NamingConf.php +++ b/lib/Pinpoint/Common/NamingConf.php @@ -15,7 +15,7 @@ * limitations under the License. */ -namespace pinpoint\Common; +namespace Pinpoint\Common; class NamingConf diff --git a/lib/pinpoint/Common/NpCoderVisitor.php b/lib/Pinpoint/Common/NpCoderVisitor.php similarity index 99% rename from lib/pinpoint/Common/NpCoderVisitor.php rename to lib/Pinpoint/Common/NpCoderVisitor.php index 8032862..e971526 100644 --- a/lib/pinpoint/Common/NpCoderVisitor.php +++ b/lib/Pinpoint/Common/NpCoderVisitor.php @@ -21,7 +21,7 @@ * Time: 10:33 AM */ -namespace pinpoint\Common; +namespace Pinpoint\Common; use PhpParser\NodeVisitorAbstract; use PhpParser\Node; diff --git a/lib/pinpoint/Common/OriginFileVisitor.php b/lib/Pinpoint/Common/OriginFileVisitor.php similarity index 98% rename from lib/pinpoint/Common/OriginFileVisitor.php rename to lib/Pinpoint/Common/OriginFileVisitor.php index e1236d4..5863d11 100644 --- a/lib/pinpoint/Common/OriginFileVisitor.php +++ b/lib/Pinpoint/Common/OriginFileVisitor.php @@ -15,7 +15,7 @@ * limitations under the License. */ -namespace pinpoint\Common; +namespace Pinpoint\Common; use PhpParser\ParserFactory; use PhpParser\NodeTraverser; diff --git a/lib/pinpoint/Common/PinpointDriver.php b/lib/Pinpoint/Common/PinpointDriver.php similarity index 81% rename from lib/pinpoint/Common/PinpointDriver.php rename to lib/Pinpoint/Common/PinpointDriver.php index 596bdc2..d2cdbac 100644 --- a/lib/pinpoint/Common/PinpointDriver.php +++ b/lib/Pinpoint/Common/PinpointDriver.php @@ -21,15 +21,16 @@ * Time: 5:14 PM */ -namespace pinpoint\Common; +namespace Pinpoint\Common; class PinpointDriver { protected static $instance; - protected $clAr; - private $iniFile=''; - protected static $pluginDir = [PLUGINS_DIR."/AutoGen/",PLUGINS_DIR."/"]; //*Plugin.php + protected $clAr = []; + private $settingIni=PLUGINS_DIR."/setting.ini"; + // user autoGen class and internal autoGen class + private static $autoGenDirs = [PLUGINS_DIR."/AutoGen/" , __DIR__."/../Plugins/AutoGen"]; //*Plugin.php public static function getInstance(){ @@ -42,29 +43,26 @@ public static function getInstance(){ final private function __construct() { - $this->clAr = []; - $this->iniFile = PLUGINS_DIR."/setting.ini"; } - public static function getAutoGenPlugins() + public static function getAutoGenFiles() { - $pluFiles = []; + $files = []; - foreach (static::$pluginDir as $dir) + foreach (static::$autoGenDirs as $dir) { if(is_dir($dir)) { - Util::scanDir($dir,"/Plugin.php$/",$pluFiles); - break; + Util::scanDir($dir,"/Plugin.php$/",$files); } } - return $pluFiles; + + return $files; } public function start() { - VendorAdaptorClassLoader::init(); RenderAopClass::getInstance(); /// checking the cached file exist, if exist load it if(Util::checkCacheReady()) @@ -73,8 +71,8 @@ public function start() RenderAopClassLoader::start(); return ; } - - $pluFiles = static::getAutoGenPlugins(); + VendorAdaptorClassLoader::enable(); + $pluFiles = static::getAutoGenFiles(); foreach ($pluFiles as $file) { new PluginParser($file,$this->clAr); @@ -82,9 +80,9 @@ public function start() /// there hidden a duplicated visit, class locates in @hook and appendFiles. /// while, it's safe to visit a class/file in appendfiles and @hook order $naming = []; - if(file_exists($this->iniFile)) + if(file_exists($this->settingIni)) { - $nConf = new NamingConf($this->iniFile); + $nConf = new NamingConf($this->settingIni); $naming = $nConf->getConf(); if(isset($naming['appendFiles'])) diff --git a/lib/pinpoint/Common/PluginParser.php b/lib/Pinpoint/Common/PluginParser.php similarity index 82% rename from lib/pinpoint/Common/PluginParser.php rename to lib/Pinpoint/Common/PluginParser.php index 3e3a4be..6966c99 100644 --- a/lib/pinpoint/Common/PluginParser.php +++ b/lib/Pinpoint/Common/PluginParser.php @@ -21,15 +21,10 @@ * Time: 10:29 AM */ -namespace pinpoint\Common; +namespace Pinpoint\Common; use PhpParser\ParserFactory; -use PhpParser\Node; -use PhpParser\Node\Name; -use PhpParser\Node\Stmt\ClassMethod; -use PhpParser\NodeVisitorAbstract; use PhpParser\NodeTraverser; -use pinpoint\Common\PluginVisitor; class PluginParser @@ -110,23 +105,23 @@ public function run() public function insertFunc($funcName, $mode) { $split = stripos ($funcName,'::'); - $uCl = substr($funcName,0,$split); - $uFunc = substr($funcName,$split+2); + $clsFullName = substr($funcName,0,$split); + $methodName = substr($funcName,$split+2); /// not Internal func - if(!array_key_exists($uCl,$this->clArray)) + if(!array_key_exists($clsFullName,$this->clArray)) { // Cl = APP\Foo // func = open - $this->clArray[$uCl] = array( $uFunc => + $this->clArray[$clsFullName] = array( $methodName => array($mode,$this->namespace,$this->className)); - }elseif (!array_key_exists($uFunc,$this->clArray[$uCl])) + }elseif (!array_key_exists($methodName,$this->clArray[$clsFullName])) { - $this->clArray[$uCl][$uFunc]= array($mode,$this->namespace,$this->className); + $this->clArray[$clsFullName][$methodName]= array($mode,$this->namespace,$this->className); } else { // when user tears the plugins, that only works on $mode - $this->clArray[$uCl][$uFunc][0] |= $mode; + $this->clArray[$clsFullName][$methodName][0] |= $mode; } } diff --git a/lib/pinpoint/Common/PluginVisitor.php b/lib/Pinpoint/Common/PluginVisitor.php similarity index 97% rename from lib/pinpoint/Common/PluginVisitor.php rename to lib/Pinpoint/Common/PluginVisitor.php index f44b440..bac553d 100644 --- a/lib/pinpoint/Common/PluginVisitor.php +++ b/lib/Pinpoint/Common/PluginVisitor.php @@ -21,10 +21,10 @@ * Time: 2:37 PM */ -namespace pinpoint\Common; +namespace Pinpoint\Common; use PhpParser\NodeVisitorAbstract; use PhpParser\Node; -use pinpoint\Common\PluginParser; +use Pinpoint\Common\PluginParser; class PluginVisitor extends NodeVisitorAbstract { diff --git a/lib/pinpoint/Common/RenderAopClass.php b/lib/Pinpoint/Common/RenderAopClass.php similarity index 98% rename from lib/pinpoint/Common/RenderAopClass.php rename to lib/Pinpoint/Common/RenderAopClass.php index 29776d1..2f27a8b 100644 --- a/lib/pinpoint/Common/RenderAopClass.php +++ b/lib/Pinpoint/Common/RenderAopClass.php @@ -16,7 +16,7 @@ */ -namespace pinpoint\Common; +namespace Pinpoint\Common; class RenderAopClass { diff --git a/lib/pinpoint/Common/RenderAopClassLoader.php b/lib/Pinpoint/Common/RenderAopClassLoader.php similarity index 94% rename from lib/pinpoint/Common/RenderAopClassLoader.php rename to lib/Pinpoint/Common/RenderAopClassLoader.php index 3f90ccd..1e97e34 100644 --- a/lib/pinpoint/Common/RenderAopClassLoader.php +++ b/lib/Pinpoint/Common/RenderAopClassLoader.php @@ -5,7 +5,7 @@ * Time: 2:53 PM */ -namespace pinpoint\Common; +namespace Pinpoint\Common; class RenderAopClassLoader { diff --git a/lib/pinpoint/Common/Util.php b/lib/Pinpoint/Common/Util.php similarity index 97% rename from lib/pinpoint/Common/Util.php rename to lib/Pinpoint/Common/Util.php index bb4f1c2..5c6ba15 100644 --- a/lib/pinpoint/Common/Util.php +++ b/lib/Pinpoint/Common/Util.php @@ -21,7 +21,7 @@ * Time: 4:21 PM */ -namespace pinpoint\Common; +namespace Pinpoint\Common; class Util { @@ -84,7 +84,7 @@ public static function scanDir($dir,$pattern,&$tree) if(is_dir($loc)){ static::scanDir($loc,$pattern,$tree); }elseif (preg_match($pattern,$loc)){ - $tree[]=$loc; + $tree[]=realpath($loc); } } } diff --git a/lib/pinpoint/Common/VendorAdaptorClassLoader.php b/lib/Pinpoint/Common/VendorAdaptorClassLoader.php similarity index 98% rename from lib/pinpoint/Common/VendorAdaptorClassLoader.php rename to lib/Pinpoint/Common/VendorAdaptorClassLoader.php index ac5366a..68ad424 100644 --- a/lib/pinpoint/Common/VendorAdaptorClassLoader.php +++ b/lib/Pinpoint/Common/VendorAdaptorClassLoader.php @@ -15,7 +15,7 @@ * limitations under the License. */ -namespace pinpoint\Common; +namespace Pinpoint\Common; use Composer\Autoload\ClassLoader; use Exception; @@ -106,7 +106,7 @@ public function loadClass($class) * @param $classIndex * @return bool */ - public static function init() + public static function enable() { $loaders = spl_autoload_functions(); foreach ($loaders as &$loader) { diff --git a/lib/Pinpoint/Plugins/AutoGen/GuzzleHttp/GuzzlePlugin.php b/lib/Pinpoint/Plugins/AutoGen/GuzzleHttp/GuzzlePlugin.php new file mode 100644 index 0000000..80f04e7 --- /dev/null +++ b/lib/Pinpoint/Plugins/AutoGen/GuzzleHttp/GuzzlePlugin.php @@ -0,0 +1,53 @@ +apId, "Request::__construct") !== false){ + pinpoint_add_clue(PP_DESTINATION,CurlUtil::getHostFromURL($this->args[1]->getHost())); + pinpoint_add_clues(PP_HTTP_URL,$this->args[1]); + pinpoint_add_clue(PP_SERVER_TYPE,PP_PHP_REMOTE); + + $n_headers =[] ; + if( is_array($this->args[2]) && array_key_exists('headers',$this->args[2])) + { + $n_headers = $this->args[2]; + } + $n_headers = array_merge($n_headers,CurlUtil::getPPHeader($this->args[1])); + $this->args[2] = $n_headers; + } + } + + function onEnd(&$ret) + { + pinpoint_add_clue(PP_NEXT_SPAN_ID,pinpoint_get_context(PP_NEXT_SPAN_ID)); + pinpoint_add_clues(PP_HTTP_STATUS_CODE,(string)($ret->getStatusCode())); + } + + function onException($e) + { + pinpoint_add_clue(PP_ADD_EXCEPTION,$e->getMessage()); + } +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/AutoGen/MongoPlugin/MongoPlugin.php b/lib/Pinpoint/Plugins/AutoGen/MongoPlugin/MongoPlugin.php new file mode 100644 index 0000000..930f6e8 --- /dev/null +++ b/lib/Pinpoint/Plugins/AutoGen/MongoPlugin/MongoPlugin.php @@ -0,0 +1,51 @@ +apId, "Client::__construct")) { + $url=$this->args[0]; + pinpoint_add_clue(SERVER_TYPE,MONGODB_EXE_QUERY); + pinpoint_add_clue(DESTINATION, $url); + return; + } + pinpoint_add_clue(SERVER_TYPE,MONGODB_EXE_QUERY); + pinpoint_add_clues(PHP_ARGS, print_r($this->args[0],true)); + } + + function onEnd(&$ret) + { // do nothing + } + + function onException($e) + {// do nothing + } +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Common/Candy.php b/lib/Pinpoint/Plugins/Common/Candy.php new file mode 100644 index 0000000..3125ea2 --- /dev/null +++ b/lib/Pinpoint/Plugins/Common/Candy.php @@ -0,0 +1,59 @@ +apId = $apId; + $this->who = $who; + $this->args = &$args; + pinpoint_start_trace(); + pinpoint_add_clue(PP_INTERCEPTOR_NAME,$apId); + } + + public function __destruct() + { + pinpoint_end_trace(); + } + + abstract function onBefore(); + + abstract function onEnd(&$ret); + + public function onException($e) + { + pinpoint_add_clue(PP_ADD_EXCEPTION,$e->getMessage()); + } +} diff --git a/lib/Pinpoint/Plugins/Common/CommonPlugin.php b/lib/Pinpoint/Plugins/Common/CommonPlugin.php new file mode 100644 index 0000000..1d79c14 --- /dev/null +++ b/lib/Pinpoint/Plugins/Common/CommonPlugin.php @@ -0,0 +1,37 @@ +getMessage()); + } +} diff --git a/lib/Pinpoint/Plugins/Common/PluginsDefines.php b/lib/Pinpoint/Plugins/Common/PluginsDefines.php new file mode 100644 index 0000000..fa7752b --- /dev/null +++ b/lib/Pinpoint/Plugins/Common/PluginsDefines.php @@ -0,0 +1,87 @@ +isLimit; + } + + public static function instance() + { + if (static::$_instance == null) { + static::$_instance = new static(); + } + return static::$_instance; + } + + protected function __construct() + { + if(defined('PP_REPORT_MEMORY_USAGE') && PP_REPORT_MEMORY_USAGE === '1') { + $this->mem_start = memory_get_usage(); + } + + pinpoint_start_trace(); + pinpoint_add_clue(PP_SERVER_TYPE, PP_PHP); + // Handle web request and CLI request + pinpoint_add_clue(PP_INTERCEPTOR_NAME, "PHP Request: ". php_sapi_name()); + + if(isset($_SERVER['REQUEST_URI'])) { + pinpoint_add_clue(PP_REQ_URI, $_SERVER['REQUEST_URI']); + } elseif(isset($_SERVER['argv'])) { + pinpoint_add_clue(PP_REQ_URI, implode(" ", $_SERVER['argv'])); + } + + if(isset($_SERVER['REMOTE_ADDR'])) { + pinpoint_add_clue(PP_REQ_CLIENT, $_SERVER["REMOTE_ADDR"]); + } + + if(isset($_SERVER['HTTP_HOST'])) { + pinpoint_add_clue(PP_REQ_SERVER, $_SERVER["HTTP_HOST"]); + } elseif(($hostname = gethostname()) !== false) { + if(($pid = getmypid()) !== false) { + $hostname .= sprintf("[pid:%d]", $pid); + } + pinpoint_add_clue(PP_REQ_SERVER, $hostname); + } + + $this->app_name = APPLICATION_NAME; + pinpoint_add_clue(PP_APP_NAME, $this->app_name); + + $this->app_id = substr(APPLICATION_ID, 0, 24); + pinpoint_add_clue(PP_APP_ID, $this->app_id); + + if (isset($_SERVER[PP_HEADER_PSPANID]) || array_key_exists(PP_HEADER_PSPANID, $_SERVER)) { + $this->psid = $_SERVER[PP_HEADER_PSPANID]; + pinpoint_add_clue(PP_PARENT_SPAN_ID, $this->psid); + } + + if (isset($_SERVER[PP_HEADER_SPANID]) || array_key_exists(PP_HEADER_SPANID, $_SERVER)) { + $this->sid = $_SERVER[PP_HEADER_SPANID]; + } else { + $this->sid = $this->generateSpanID(); + } + + if (isset($_SERVER[PP_HEADER_TRACEID]) || array_key_exists(PP_HEADER_TRACEID, $_SERVER)) { + $this->tid = $_SERVER[PP_HEADER_TRACEID]; + } else { + $this->tid = $this->generateTransactionID(); + } + + if (isset($_SERVER[PP_HEADER_PAPPNAME]) || array_key_exists(PP_HEADER_PAPPNAME, $_SERVER)) { + $this->pname = $_SERVER[PP_HEADER_PAPPNAME]; + pinpoint_add_clue(PP_PARENT_NAME, $this->pname); + } + + if (isset($_SERVER[PP_HEADER_PAPPTYPE]) || array_key_exists(PP_HEADER_PAPPTYPE, $_SERVER)) { + $this->ptype = $_SERVER[PP_HEADER_PAPPTYPE]; + pinpoint_add_clue(PP_PARENT_TYPE, $this->ptype); + } + + if (isset($_SERVER[PP_HEADER_PINPOINT_HOST]) || array_key_exists(PP_HEADER_PINPOINT_HOST, $_SERVER)) { + $this->ah = $_SERVER[PP_HEADER_PINPOINT_HOST]; + pinpoint_add_clue(PP_PARENT_HOST, $this->ah); + } + + if (isset($_SERVER[PP_HEADER_NGINX_PROXY]) || array_key_exists(PP_HEADER_NGINX_PROXY, $_SERVER)) { + pinpoint_add_clue(PP_NGINX_PROXY, $_SERVER[PP_HEADER_NGINX_PROXY]); + } + + if (isset($_SERVER[PP_HEADER_APACHE_PROXY]) || array_key_exists(PP_HEADER_APACHE_PROXY, $_SERVER)) { + pinpoint_add_clue(PP_APACHE_PROXY, $_SERVER[PP_HEADER_APACHE_PROXY]); + } + + pinpoint_set_context("Pinpoint-Sampled", PP_SAMPLED); + if (((isset($_SERVER[PP_HEADER_SAMPLED]) || array_key_exists(PP_HEADER_SAMPLED, $_SERVER)) && ($_SERVER[PP_HEADER_SAMPLED] == PP_NOT_SAMPLED)) or pinpoint_tracelimit()) { + $this->isLimit = true; + //drop this request. collector could not receive any thing + pinpoint_set_context("Pinpoint-Sampled", PP_NOT_SAMPLED); + pinpoint_drop_trace(); + } + + pinpoint_add_clue(PP_TRANSCATION_ID, $this->tid); + pinpoint_add_clue(PP_SPAN_ID, $this->sid); + pinpoint_set_context(PP_TRANSCATION_ID, $this->tid); + pinpoint_set_context(PP_SPAN_ID, (string)$this->sid); + } + + public function __destruct() + { + // reset limit + $this->isLimit = false; + if(defined('PP_REPORT_MEMORY_USAGE') && PP_REPORT_MEMORY_USAGE === '1') { + $memory_usage = (memory_get_peak_usage() - $this->mem_start) / 1024; + pinpoint_add_clues(PP_MEMORY_USAGE, "$memory_usage KB"); + } + + if (($http_response_code = http_response_code()) != null) { + pinpoint_add_clues(PP_HTTP_STATUS_CODE, $http_response_code); + } + pinpoint_end_trace(); + } + + public function generateSpanID() + { + try { + $this->curNextSpanId = mt_rand(); //random_int(-99999999,99999999); + return $this->curNextSpanId; + } catch (\Exception $e) { + return rand(); + } + } + + public function getCurNextSpanId() + { + return $this->curNextSpanId; + } + + public function generateTransactionID() + { + return $this->app_id . '^' . strval(pinpoint_start_time()) . '^' . strval(pinpoint_unique_id()); + } +} diff --git a/lib/Pinpoint/Plugins/Sys/Memcached/MemAddPlugin.php b/lib/Pinpoint/Plugins/Sys/Memcached/MemAddPlugin.php new file mode 100644 index 0000000..48f23f2 --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/Memcached/MemAddPlugin.php @@ -0,0 +1,38 @@ +args[0]; + $value = $this->args[1]; + pinpoint_add_clues(PP_PHP_ARGS,"$key:$value"); + } + + function onEnd(&$ret) + { + + } +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/Memcached/MemAddServerPlugin.php b/lib/Pinpoint/Plugins/Sys/Memcached/MemAddServerPlugin.php new file mode 100644 index 0000000..e24b11c --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/Memcached/MemAddServerPlugin.php @@ -0,0 +1,29 @@ +args[0]; + $port = $this->args[1]; + pinpoint_add_clue(PP_SERVER_TYPE,PP_MEMCACHED); + pinpoint_add_clue(PP_DESTINATION,"$host:$port"); + } + + function onEnd(&$ret) + { + // TODO: Implement onEnd() method. + } +} diff --git a/lib/Pinpoint/Plugins/Sys/Memcached/MemAddServersPlugin.php b/lib/Pinpoint/Plugins/Sys/Memcached/MemAddServersPlugin.php new file mode 100644 index 0000000..529f52e --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/Memcached/MemAddServersPlugin.php @@ -0,0 +1,30 @@ +args[0]; + $url =''; + foreach ($servers as $server) + { + $url.= sprintf("%s:%d ",$server[0],$server[1]); + } + pinpoint_add_clue(PP_SERVER_TYPE,PP_MEMCACHED); + pinpoint_add_clue(PP_DESTINATION,$url); + } + + function onEnd(&$ret) + { + // TODO: Implement onEnd() method. + } +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/Memcached/MemGetPlugin.php b/lib/Pinpoint/Plugins/Sys/Memcached/MemGetPlugin.php new file mode 100644 index 0000000..9a4ea18 --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/Memcached/MemGetPlugin.php @@ -0,0 +1,36 @@ +args[0]; + pinpoint_add_clue(PP_SERVER_TYPE,PP_MEMCACHED); + pinpoint_add_clues(PP_PHP_ARGS,"$key"); + } + + function onEnd(&$ret) + { + + } +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/Memcached/Memcached.php b/lib/Pinpoint/Plugins/Sys/Memcached/Memcached.php new file mode 100644 index 0000000..b86b254 --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/Memcached/Memcached.php @@ -0,0 +1,84 @@ +onBefore(); + $r = parent::add($key, $value, $expiration); + $p->onEnd($r); + return $r; + }catch (\Exception $e) + { + $p->onException($e); + throw $e; + } + } + + public function addServer ($host, $port, $weight = 0) + { + $p = new MemAddServerPlugin("Memcached::".__FUNCTION__,$this,$host,$port,$weight); + try{ + $p->onBefore(); + $r = parent::addServer($host,$port,$weight); + $p->onEnd($r); + return $r; + }catch (\Exception $e) + { + $p->onException($e); + throw $e; + } + } + + + public function addServers ($servers) + { + $p = new MemAddServersPlugin("Memcached::".__FUNCTION__,$this,$servers); + try{ + $p->onBefore(); + $r = parent::addServers($servers); + $p->onEnd($r); + return $r; + }catch (\Exception $e) + { + $p->onException($e); + throw $e; + } + } + + public function get($key, $cache_cb = null, $flags = 0) + { + $p = new MemGetPlugin("Memcached::".__FUNCTION__,$this,$key,$cache_cb,$flags); + try{ + $p->onBefore(); + $r = parent::get($key,$cache_cb,$flags); + $p->onEnd($r); + return $r; + }catch (\Exception $e) + { + $p->onException($e); + throw $e; + } + } + + + +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/PDO/PDO.php b/lib/Pinpoint/Plugins/Sys/PDO/PDO.php new file mode 100644 index 0000000..97aa5b4 --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/PDO/PDO.php @@ -0,0 +1,80 @@ +dsn = $dsn; + parent::__construct($dsn, $username, $passwd, $options); + } + + private function doPDOQuery($statement, $mode = \PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = array()) + { + $args = \pinpoint_get_func_ref_args(); + $var = new PreparePlugin("PDO::query",$this,...$args); + try{ + $var->onBefore(); + $ret = parent::query(...$args); + $var->onEnd($ret); + return $ret; + }catch (\Exception $e){ + $var->onException($e); + throw new \Exception($e); + } + + } + + public function query() + { + return $this->doPDOQuery(...\pinpoint_get_func_ref_args()); + } + + + public function exec($statement) + { + $var = new PDOExec("PDO::exec",$this,$statement); + try{ + $var->onBefore(); + $ret = parent::exec($statement); + $var->onEnd($ret); + return $ret; + }catch (\Exception $e){ + $var->onException($e); + throw new \Exception($e); + } + } + + + public function prepare($statement, $driver_options = array()) + { + $var = new PreparePlugin("PDO::prepare",$this,$statement,$driver_options); + try{ + $var->onBefore(); + $ret = parent::prepare($statement,$driver_options); + $var->onEnd($ret); + return $ret; + }catch (\Exception $e){ + $var->onException($e); + throw new \Exception($e); + } + } + +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/PDO/PDOExec.php b/lib/Pinpoint/Plugins/Sys/PDO/PDOExec.php new file mode 100644 index 0000000..b08897b --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/PDO/PDOExec.php @@ -0,0 +1,38 @@ +args[0][0])); + } + + function onEnd(&$ret) + { + pinpoint_add_clues(PP_PHP_RETURN,"$ret"); + } + + function onException($e) + { + // TODO: Implement onException() method. + } +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/PDO/PDOGlueStatement.php b/lib/Pinpoint/Plugins/Sys/PDO/PDOGlueStatement.php new file mode 100644 index 0000000..f776073 --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/PDO/PDOGlueStatement.php @@ -0,0 +1,56 @@ +parseDb($this->who->dsn); + pinpoint_add_clue(PP_SERVER_TYPE,PP_MYSQL); + pinpoint_add_clue(PP_SQL_FORMAT, sprintf("%s",$this->args[0])); + pinpoint_add_clue(PP_DESTINATION,$dbInfo['host']); + } + function onEnd(&$ret) + { + $origin = $ret; + $ret = new ProfilerPDOStatement($origin); + } + + function onException($e) + { + pinpoint_add_clue(PP_ADD_EXCEPTION,$e->getMessage()); + } + + function parseDb($dsn){ + + $db_url = parse_url($dsn); + parse_str(str_replace(';','&',$db_url['path']),$dbInfo); + + if($db_url['scheme'] == 'sqlite'){ // treat sqllite as mysql + $dbInfo['host'] = 'localhost-sqlite'; + } + + $dbInfo['scheme']= $db_url['scheme']; + + return $dbInfo; + } +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/PDO/PreparePlugin.php b/lib/Pinpoint/Plugins/Sys/PDO/PreparePlugin.php new file mode 100644 index 0000000..6196a07 --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/PDO/PreparePlugin.php @@ -0,0 +1,56 @@ +parseDb($this->who->dsn); + pinpoint_add_clue(PP_SERVER_TYPE,PP_MYSQL); + pinpoint_add_clue(PP_SQL_FORMAT, $this->args[0]); + pinpoint_add_clue(PP_DESTINATION,$dbInfo['host']); + } + function onEnd(&$ret) + { + $origin = $ret; + $ret = new ProfilerPDOStatement($origin); + } + + function onException($e) + { + pinpoint_add_clue(PP_ADD_EXCEPTION,$e->getMessage()); + } + + function parseDb($dsn){ + + $db_url = parse_url($dsn); + parse_str(str_replace(';','&',$db_url['path']),$dbInfo); + + if($db_url['scheme'] == 'sqlite'){ // treat sqllite as mysql + $dbInfo['host'] = 'localhost-sqlite'; + } + + $dbInfo['scheme']= $db_url['scheme']; + + return $dbInfo; + } +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/PDO/ProfilerPDOStatement.php b/lib/Pinpoint/Plugins/Sys/PDO/ProfilerPDOStatement.php new file mode 100644 index 0000000..38b2d20 --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/PDO/ProfilerPDOStatement.php @@ -0,0 +1,192 @@ +_instance = &$instance; + $this->_name_list=[ + 'fetchAll','fetch','nextRowset','getColumnMeta','fetchObject','execute' + ]; + } + + protected function onBefore() + { + pinpoint_start_trace(); + pinpoint_add_clue(PP_INTERCEPTOR_NAME,$this->name); + } + + protected function onEnd(&$ret) + { + pinpoint_end_trace(); + } + + protected function onException($e) + { + pinpoint_add_clue(PP_ADD_EXCEPTION,$e->getMessage()); + } + + + public function bindValue($parameter, $value, $data_type = PDO::PARAM_STR) + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + public function closeCursor() + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + public function columnCount() + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + public function debugDumpParams() + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + public function errorCode() + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + public function errorInfo() + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + public function execute($input_parameters = null) + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + public function fetch($fetch_style = null, $cursor_orientation = PDO::FETCH_ORI_NEXT, $cursor_offset = 0) + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + public function fetchAll($how = PDO::FETCH_CLASS, $class_name = null, $ctor_args = null) + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + public function fetchColumn($column_number = 0) + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + public function fetchObject($class_name = "stdClass", $ctor_args = null) + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + public function getAttribute($attribute) + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + public function getColumnMeta($column) + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + public function nextRowset() + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + public function rowCount() + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + public function setAttribute($attribute, $value) + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + public function setFetchMode($mode,$parames=null) + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + + public function bindParam ($parameter, &$variable, $data_type = PDO::PARAM_STR, $length = null, $driver_options = null) + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + public function bindColumn ($column, &$param, $type = null, $maxlen = null, $driverdata = null) + { + $args = \pinpoint_get_func_ref_args(); + return $this->profiler(__FUNCTION__,$args); + } + + private function profiler($name,&$arguments) + { + if(!in_array($name ,$this->_name_list)) + { + return call_user_func_array([$this->_instance,$name],$arguments); + }else{ + try{ + $this->name = "PDOStatement::".$name; + $this->args = &$arguments; + $this->onBefore(); + $ret = call_user_func_array([$this->_instance,$name],$arguments); + $this->onEnd($ret); + return $ret; + }catch (\Exception $e){ + $this->onException($e); + $ret = null; + $this->onEnd($ret); + throw $e; + } + } + + } + +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/RdKafka/ProducePlugin.php b/lib/Pinpoint/Plugins/Sys/RdKafka/ProducePlugin.php new file mode 100644 index 0000000..72301cf --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/RdKafka/ProducePlugin.php @@ -0,0 +1,29 @@ +who->blocker_list; + $topic = $this->who->topic; + pinpoint_add_clue(PP_SERVER_TYPE,PP_KAFKA); + pinpoint_add_clues(PP_KAFKA_TOPIC,$topic); + pinpoint_add_clue(PP_DESTINATION,$blocker_list); + } + + function onEnd(&$ret) + { + // TODO: Implement onEnd() method. + } +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/RdKafka/Producer.php b/lib/Pinpoint/Plugins/Sys/RdKafka/Producer.php new file mode 100644 index 0000000..be7235a --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/RdKafka/Producer.php @@ -0,0 +1,24 @@ +blocker_list = $blocker_list; + return parent::addBrokers($blocker_list); + } + + public function newTopic($topic,$topic_conf=NULL) + { + return new ProfilerNewTopic(parent::newTopic($topic,$topic_conf),$this->blocker_list,$topic); + } + +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/RdKafka/ProfilerNewTopic.php b/lib/Pinpoint/Plugins/Sys/RdKafka/ProfilerNewTopic.php new file mode 100644 index 0000000..1310dc6 --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/RdKafka/ProfilerNewTopic.php @@ -0,0 +1,43 @@ +_instance = &$instance; + $this->blocker_list = $blocker_list; + $this->topic = $topic; + } + + public function __call($name, $arguments) + { + return call_user_func_array([$this->_instance,$name],$arguments); + } + + public function produce($partition,$msgflags,$payload,$key=null) + { + $param = \pinpoint_get_func_ref_args(); + + $plugin = new ProducePlugin("Topic::produce",$this,$param); + try{ + $plugin->onBefore(); + $ret = call_user_func_array([$this->_instance,'produce'],$param); + $plugin->onEnd($ret); + return $ret; + }catch (\Exception $e) + { + $plugin->onException($e); + } + } +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/curl/CurlExecPlugin.php b/lib/Pinpoint/Plugins/Sys/curl/CurlExecPlugin.php new file mode 100644 index 0000000..d9d58cc --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/curl/CurlExecPlugin.php @@ -0,0 +1,48 @@ +args[0],CURLINFO_HTTP_CODE); + if($code == 404){ + pinpoint_add_clue(PP_ADD_EXCEPTION," 404 file not found"); + } + pinpoint_add_clues(PP_HTTP_STATUS_CODE,$code); + + } + + function onException($e) + { + + } +} diff --git a/lib/Pinpoint/Plugins/Sys/curl/CurlUtil.php b/lib/Pinpoint/Plugins/Sys/curl/CurlUtil.php new file mode 100644 index 0000000..b1f2fa9 --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/curl/CurlUtil.php @@ -0,0 +1,121 @@ +"s0"]; + } + + $nsid = Trace::generateSpanID(); + $header = [ + 'Pinpoint-Sampled'=>'s1', + 'Pinpoint-Flags'=>'0', + 'Pinpoint-Papptype'=>'1500', + 'Pinpoint-Pappname'=>APPLICATION_NAME, + 'Pinpoint-Host'=>static::getHostFromURL($url), + 'Pinpoint-Traceid'=>pinpoint_get_context(PP_TRANSCATION_ID), + 'Pinpoint-Pspanid'=>pinpoint_get_context(PP_SPAN_ID), + 'Pinpoint-Spanid'=>$nsid + ]; + pinpoint_set_context(PP_NEXT_SPAN_ID, (string)$nsid); + return $header; + } + + /** + * + * url is very funny + * example.com + * www.example.com:8000 + * www.example.com + * http://www.example.com + * total must be accept + * + * @param string $url + * @return string + */ + public static function getHostFromURL(string $url) + { + $urlAr = parse_url($url); + $retUrl = ''; + + if(isset($urlAr['host'])) // got the host and return + { + $retUrl.=$urlAr['host']; + } + + if(isset($urlAr['path'])) + { + $retUrl.= $urlAr['path']; + } + + if(isset($urlAr['port'])) // an optional setting + { + $retUrl .= ":".$urlAr['port']; + } + + return $retUrl; + } + +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/curl/curl.php b/lib/Pinpoint/Plugins/Sys/curl/curl.php new file mode 100644 index 0000000..787e131 --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/curl/curl.php @@ -0,0 +1,106 @@ +$url,CH_HEADRR=>[]]; + }else{ + $curlChAr[strval($ch)] = [CH_URL=>"",CH_HEADRR=>[]]; + } + return $ch; +} + + +function curl_setopt($ch, $option, $value) +{ + if($option == CURLOPT_HTTPHEADER) + { + global $curlChAr; + $curlChAr[strval($ch)][CH_HEADRR] = $value; + + }elseif ($option == CURLOPT_URL ){ + global $curlChAr; + $curlChAr[strval($ch)][CH_URL]=$value; + } + + return \curl_setopt($ch, $option, $value); +} + +function curl_setopt_array($ch, array $options) +{ + global $curlChAr; + if(isset($options[CURLOPT_URL])) + { + + $curlChAr[strval($ch)][CH_URL] = $options[CURLOPT_URL]; + } + + if(isset($options[CURLOPT_HTTPHEADER])) + { + + $curlChAr[strval($ch)][CH_HEADRR] = $options[CURLOPT_HTTPHEADER]; + } + + return \curl_setopt_array($ch,$options); +} + + +function set_pinpoint_header($ch,$url,$userHeader) +{ + $ppHeader = CurlUtil::getPinpointHeader($url); + $header= array_merge($userHeader,$ppHeader); + \curl_setopt($ch,CURLOPT_HTTPHEADER,$header); +} + + +function curl_exec($ch) +{ + global $curlChAr; + $chAr= $curlChAr[strval($ch)]; + $plugin = new CurlExecPlugin('curl_exec', null, $ch); + try { + $plugin->onBefore(); + set_pinpoint_header($ch,$chAr[CH_URL],$chAr[CH_HEADRR]); + $ret= \curl_exec($ch); + $plugin->onEnd($chAr[CH_URL]); + return $ret; + } catch (\Exception $e) { + $plugin->onException($e); + throw $e; + } +} + +function curl_close($ch) +{ + global $curlChAr; + unset($curlChAr[strval($ch)] ); + \curl_close($ch); +} + +function curl_reset($ch) +{ + global $ch_arr; + $ch_arr[strval($ch)] = []; + \curl_reset($ch); +} diff --git a/lib/Pinpoint/Plugins/Sys/date/date.php b/lib/Pinpoint/Plugins/Sys/date/date.php new file mode 100644 index 0000000..eb20b44 --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/date/date.php @@ -0,0 +1,34 @@ +onBefore(); + $ret = call_user_func_array('date', $args); + $plugins->onEnd($ret); + return $ret; + } catch (\Exception $e) { + $plugins->onException($e); + throw $e; + } + +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/mysqli/Mysqli.php b/lib/Pinpoint/Plugins/Sys/mysqli/Mysqli.php new file mode 100644 index 0000000..e118319 --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/mysqli/Mysqli.php @@ -0,0 +1,54 @@ +onBefore(); + $ret = parent::prepare($query); + $plugin->onEnd($ret); + return $ret; + + }catch (\Exception $e) + { + $plugin->onException($e); + } + } + + public function query ($query, $resultmode = MYSQLI_STORE_RESULT) + { + $plugin = new MysqliQueryPlugin("Mysqli::query",$this,$query, $resultmode); + try{ + $plugin->onBefore(); + $ret = parent::query($query,$resultmode); + $plugin->onEnd($ret); + return $ret; + + }catch (\Exception $e) + { + $plugin->onException($e); + } + } +} + +function mysqli_init() { + return new Mysqli(); +} diff --git a/lib/Pinpoint/Plugins/Sys/mysqli/MysqliPreparePlugin.php b/lib/Pinpoint/Plugins/Sys/mysqli/MysqliPreparePlugin.php new file mode 100644 index 0000000..78d928e --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/mysqli/MysqliPreparePlugin.php @@ -0,0 +1,37 @@ +who; + pinpoint_add_clue(PP_SERVER_TYPE,PP_MYSQL); + pinpoint_add_clue(PP_SQL_FORMAT, $this->args[0]); + pinpoint_add_clue(PP_DESTINATION,$myqli->host_info); + } + + function onEnd(&$ret) + { + $origin = $ret; + $ret = new ProfilerMysqli_Stmt($origin); + } +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/mysqli/MysqliQueryPlugin.php b/lib/Pinpoint/Plugins/Sys/mysqli/MysqliQueryPlugin.php new file mode 100644 index 0000000..621f655 --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/mysqli/MysqliQueryPlugin.php @@ -0,0 +1,37 @@ +who; + pinpoint_add_clue(PP_SERVER_TYPE,PP_MYSQL); + pinpoint_add_clue(PP_SQL_FORMAT,$this->args[0]); + pinpoint_add_clue(PP_DESTINATION,$myqli->host_info); + } + + function onEnd(&$ret) + { + + } +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/mysqli/ProfilerMysqliResult.php b/lib/Pinpoint/Plugins/Sys/mysqli/ProfilerMysqliResult.php new file mode 100644 index 0000000..c7f4d67 --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/mysqli/ProfilerMysqliResult.php @@ -0,0 +1,32 @@ +_instance = &$instance; + } + + public function __call($name, $arguments) + { + return call_user_func_array([&$this->_instance,$name],$arguments); + } + +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/mysqli/ProfilerMysqli_Stmt.php b/lib/Pinpoint/Plugins/Sys/mysqli/ProfilerMysqli_Stmt.php new file mode 100644 index 0000000..c9b3344 --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/mysqli/ProfilerMysqli_Stmt.php @@ -0,0 +1,53 @@ +_instance = &$instance; + } + + public function __call($name, $arguments) + { + return call_user_func_array([&$this->_instance,$name],$arguments); + } + + public function bind_param ($types, &$var1, &...$_) + { + $param = \pinpoint_get_func_ref_args(); + return call_user_func_array([$this->_instance,'bind_param'],$param); + + } + + public function bind_result (&$var1, &...$_) + { + $param = \pinpoint_get_func_ref_args(); + return call_user_func_array([$this->_instance,'bind_result'],$param); + } + + public function execute() + { + $plugin = new StmtExecutePlugin("Stmt::execute",$this); + try{ + $plugin->onBefore(); + $ret = call_user_func_array([$this->_instance,'execute'],[]); + $plugin->onEnd($ret); + return $ret; + + }catch (\Exception $e) + { + $plugin->onException($e); + } + } + + +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/mysqli/StmtExecutePlugin.php b/lib/Pinpoint/Plugins/Sys/mysqli/StmtExecutePlugin.php new file mode 100644 index 0000000..5f40243 --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/mysqli/StmtExecutePlugin.php @@ -0,0 +1,30 @@ +args[0]; + $port = $this->args[1]; + pinpoint_add_clue(PP_SERVER_TYPE,PP_REDIS); + pinpoint_add_clue(PP_DESTINATION,"$host:$port"); + } + + function onEnd(&$ret) + { + // TODO: Implement onEnd() method. + } +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/phpredis/GetPlugin.php b/lib/Pinpoint/Plugins/Sys/phpredis/GetPlugin.php new file mode 100644 index 0000000..f88d66c --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/phpredis/GetPlugin.php @@ -0,0 +1,27 @@ +args[0]; + pinpoint_add_clue(PP_SERVER_TYPE,PP_REDIS); + pinpoint_add_clues(PP_PHP_ARGS,"$key"); + } + + function onEnd(&$ret) + { + // TODO: Implement onEnd() method. + } +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/phpredis/Redis.php b/lib/Pinpoint/Plugins/Sys/phpredis/Redis.php new file mode 100644 index 0000000..99ad58d --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/phpredis/Redis.php @@ -0,0 +1,61 @@ +onBefore(); + $r = parent::connect($host, $port, $timeout, $reserved, $retry_interval); + $p->onEnd($r); + return $r; + }catch (\Exception $e) + { + $p->onException($e); + throw $e; + } + + } + + public function get( $key ) + { + $p = new GetPlugin("Redis::".__FUNCTION__,$this,$key); + try{ + $p->onBefore(); + $r = parent::get($key); + $p->onEnd($r); + return $r; + }catch (\Exception $e) + { + $p->onException($e); + throw $e; + } + } + + public function set($key, $value, $timeout = null) + { + + $p = new SetPlugin("Redis::".__FUNCTION__,$this,$key, $value, $timeout); + try{ + $p->onBefore(); + $r = parent::set($key, $value, $timeout); + $p->onEnd($r); + return $r; + }catch (\Exception $e) + { + $p->onException($e); + throw $e; + } + + } + +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/Sys/phpredis/SetPlugin.php b/lib/Pinpoint/Plugins/Sys/phpredis/SetPlugin.php new file mode 100644 index 0000000..faef57d --- /dev/null +++ b/lib/Pinpoint/Plugins/Sys/phpredis/SetPlugin.php @@ -0,0 +1,28 @@ +args[0]; + $value = $this->args[1]; + pinpoint_add_clue(PP_SERVER_TYPE,PP_REDIS); + pinpoint_add_clues(PP_PHP_ARGS,"$key:$value"); + } + + function onEnd(&$ret) + { + // TODO: Implement onEnd() method. + } +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/__init__.php b/lib/Pinpoint/Plugins/__init__.php new file mode 100644 index 0000000..95e258c --- /dev/null +++ b/lib/Pinpoint/Plugins/__init__.php @@ -0,0 +1,31 @@ +query('SELECT name, color, calories FROM fruit ORDER BY name'); + } + protected function fooTestACPrivate() + { + echo "I'm a private function"; + return "OK"; + } + public function fooTestCompatible(class1 $a, class2 $b, FooClass $c, FooClass4 $d) + { + return null; + } + public function returnNothing() : void + { + return; + } + public function returnNothing_1() + { + return; + } +} \ No newline at end of file diff --git a/lib/Pinpoint/test/Comparison/pinpoint/test/Proxied_TestTrait.php b/lib/Pinpoint/test/Comparison/pinpoint/test/Proxied_TestTrait.php new file mode 100644 index 0000000..ab2b854 --- /dev/null +++ b/lib/Pinpoint/test/Comparison/pinpoint/test/Proxied_TestTrait.php @@ -0,0 +1,15 @@ +onBefore(); + parent::__construct($a, $b, $c); + $traitTestPlugin___construct_var->onEnd($traitTestPlugin___construct_ret); + } catch (\Exception $e) { + $traitTestPlugin___construct_var->onException($e); + throw $e; + } + } + public function foo($a, $b, $v, $d) : array + { + $traitTestPlugin_foo_var = new traitTestPlugin(__METHOD__, $this, $a, $b, $v, $d); + $traitTestPlugin_foo_ret = null; + try { + $traitTestPlugin_foo_var->onBefore(); + $traitTestPlugin_foo_ret = parent::foo($a, $b, $v, $d); + $traitTestPlugin_foo_var->onEnd($traitTestPlugin_foo_ret); + return $traitTestPlugin_foo_ret; + } catch (\Exception $e) { + $traitTestPlugin_foo_var->onException($e); + throw $e; + } + } + public function fooUseYield() + { + $traitTestPlugin_fooUseYield_var = new traitTestPlugin(__METHOD__, $this); + $traitTestPlugin_fooUseYield_ret = null; + try { + $traitTestPlugin_fooUseYield_var->onBefore(); + $traitTestPlugin_fooUseYield_ret = parent::fooUseYield(); + $traitTestPlugin_fooUseYield_var->onEnd($traitTestPlugin_fooUseYield_ret); + return $traitTestPlugin_fooUseYield_ret; + } catch (\Exception $e) { + throw $e; + } + } + public function fooNoReturn() + { + $traitTestPlugin_fooNoReturn_var = new traitTestPlugin(__METHOD__, $this); + $traitTestPlugin_fooNoReturn_ret = null; + try { + parent::fooNoReturn(); + } catch (\Exception $e) { + $traitTestPlugin_fooNoReturn_var->onException($e); + throw $e; + } + } + public function fooNoReturnButReturn() + { + $victim_fooNoReturnButReturn_var = new victim(__METHOD__, $this); + $victim_fooNoReturnButReturn_ret = null; + try { + $victim_fooNoReturnButReturn_ret = parent::fooNoReturnButReturn(); + return $victim_fooNoReturnButReturn_ret; + } catch (\Exception $e) { + $victim_fooNoReturnButReturn_var->onException($e); + throw $e; + } + } + public final function fooNaughtyFinal($a, $b, $c) + { + $over_fooNaughtyFinal_var = new over(__METHOD__, $this, $a, $b, $c); + $over_fooNaughtyFinal_ret = null; + try { + $over_fooNaughtyFinal_var->onBefore(); + $over_fooNaughtyFinal_ret = parent::fooNaughtyFinal($a, $b, $c); + $over_fooNaughtyFinal_var->onEnd($over_fooNaughtyFinal_ret); + return $over_fooNaughtyFinal_ret; + } catch (\Exception $e) { + $over_fooNaughtyFinal_var->onException($e); + throw $e; + } + } + protected function fooTestACPrivate() + { + $traitTestPlugin_fooTestACPrivate_var = new traitTestPlugin(__METHOD__, $this); + $traitTestPlugin_fooTestACPrivate_ret = null; + try { + $traitTestPlugin_fooTestACPrivate_ret = parent::fooTestACPrivate(); + return $traitTestPlugin_fooTestACPrivate_ret; + } catch (\Exception $e) { + $traitTestPlugin_fooTestACPrivate_var->onException($e); + throw $e; + } + } + public function fooTestCompatible(class1 $a, class2 $b, FooClass $c, FooClass4 $d) + { + $traitTestPlugin_fooTestCompatible_var = new traitTestPlugin(__METHOD__, $this, $a, $b, $c, $d); + $traitTestPlugin_fooTestCompatible_ret = null; + try { + $traitTestPlugin_fooTestCompatible_ret = parent::fooTestCompatible($a, $b, $c, $d); + return $traitTestPlugin_fooTestCompatible_ret; + } catch (\Exception $e) { + $traitTestPlugin_fooTestCompatible_var->onException($e); + throw $e; + } + } + public function returnNothing() : void + { + $traitTestPlugin_returnNothing_var = new traitTestPlugin(__METHOD__, $this); + $traitTestPlugin_returnNothing_ret = null; + try { + $traitTestPlugin_returnNothing_var->onBefore(); + parent::returnNothing(); + $traitTestPlugin_returnNothing_var->onEnd($traitTestPlugin_returnNothing_ret); + } catch (\Exception $e) { + $traitTestPlugin_returnNothing_var->onException($e); + throw $e; + } + } + public function returnNothing_1() + { + $traitTestPlugin_returnNothing_1_var = new traitTestPlugin(__METHOD__, $this); + $traitTestPlugin_returnNothing_1_ret = null; + try { + $traitTestPlugin_returnNothing_1_var->onBefore(); + parent::returnNothing_1(); + $traitTestPlugin_returnNothing_1_var->onEnd($traitTestPlugin_returnNothing_1_ret); + } catch (\Exception $e) { + $traitTestPlugin_returnNothing_1_var->onException($e); + throw $e; + } + } +} \ No newline at end of file diff --git a/lib/Pinpoint/test/Comparison/pinpoint/test/TestTrait.php b/lib/Pinpoint/test/Comparison/pinpoint/test/TestTrait.php new file mode 100644 index 0000000..3aefa1c --- /dev/null +++ b/lib/Pinpoint/test/Comparison/pinpoint/test/TestTrait.php @@ -0,0 +1,24 @@ +onBefore(); + $this->Proxied_TestTrait_getReturnType(); + $traitTestPlugin_getReturnType_var->onEnd($traitTestPlugin_getReturnType_ret); + } catch (\Exception $e) { + $traitTestPlugin_getReturnType_var->onException($e); + throw $e; + } + } +} \ No newline at end of file diff --git a/lib/pinpoint/test/Foo.php b/lib/Pinpoint/test/Foo.php similarity index 97% rename from lib/pinpoint/test/Foo.php rename to lib/Pinpoint/test/Foo.php index c01e751..5f6db2a 100644 --- a/lib/pinpoint/test/Foo.php +++ b/lib/Pinpoint/test/Foo.php @@ -1,5 +1,5 @@