Skip to content

Commit f786f08

Browse files
authored
Feat ci for autoloader class (#57)
* support pinpoint-php v0.5.0 * SysV2 version plugins * add lib/Pinpoint/Plugins/functions.php * CI * add curl plugins * add redis plugins * add redis * add pinpoint_tracelimit support * add memcached plugin * add DefaultRequestPlugin * enhance mysqli * update naming style * check extension load * feat(aop): remove serialization - replace serialization with include * add naming garble * fix bug in _pdo * ci(autoloader): autoloader class test - test case and env - fix curl bug
1 parent dcebf0a commit f786f08

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2074
-161
lines changed

.github/workflows/main.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Build
33
on: [push, pull_request, workflow_dispatch]
44

55
jobs:
6-
php7:
6+
PHPUnit:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
@@ -15,6 +15,30 @@ jobs:
1515
with:
1616
php-version: ${{ matrix.php-versions }}
1717
tools: composer:v2
18+
extensions: pinpoint_php-https://github.com/eeliu/pinpoint-c-agent@feat-join-cut-5-11
1819
- run: |
1920
composer install --prefer-dist
20-
vendor/bin/phpunit --configuration PHPUnit.xml --testsuit pinpoint --testdox
21+
vendor/bin/phpunit --configuration PHPUnit.xml --testsuit pinpoint --testdox
22+
23+
PHPUnit-AOP:
24+
strategy:
25+
matrix:
26+
php-versions: [ '7.4','8.0','8.1','8.2']
27+
runs-on: ubuntu-latest
28+
services:
29+
redis:
30+
# Docker Hub image
31+
image: redis
32+
ports:
33+
- 6379:6379
34+
steps:
35+
- uses: actions/checkout@v2
36+
- name: Setup PHP
37+
uses: shivammathur/setup-php@v2
38+
with:
39+
php-version: ${{ matrix.php-versions }}
40+
tools: composer:v2
41+
extensions: pinpoint_php-https://github.com/eeliu/pinpoint-c-agent@feat-join-cut, mongodb-mongodb/[email protected]
42+
- run: |
43+
composer install --prefer-dist
44+
vendor/bin/phpunit --configuration PHPUnit_aop_libraries.xml --testsuit pinpoint --testdox

PHPUnit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<testsuites>
1212
<testsuite name="pinpoint">
1313
<directory>lib/Pinpoint/test</directory>
14+
<directory>lib/Pinpoint/Common</directory>
1415
</testsuite>
1516
</testsuites>
1617
<filter>

PHPUnit_aop_libraries.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="auto_pinpointed_test.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="true">
11+
<testsuites>
12+
<testsuite name="pinpoint">
13+
<directory>lib/Pinpoint/Plugins</directory>
14+
</testsuite>
15+
</testsuites>
16+
<filter>
17+
<whitelist>
18+
<directory suffix=".php">lib/pinpoint/Common</directory>
19+
</whitelist>
20+
</filter>
21+
</phpunit>

auto_pinpointed_test.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/******************************************************************************
6+
* Copyright 2020 NAVER Corp. *
7+
* *
8+
* Licensed under the Apache License, Version 2.0 (the "License"); *
9+
* you may not use this file except in compliance with the License. *
10+
* You may obtain a copy of the License at *
11+
* *
12+
* http://www.apache.org/licenses/LICENSE-2.0 *
13+
* *
14+
* Unless required by applicable law or agreed to in writing, software *
15+
* distributed under the License is distributed on an "AS IS" BASIS, *
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
17+
* See the License for the specific language governing permissions and *
18+
* limitations under the License. *
19+
******************************************************************************/
20+
21+
namespace Pinpoint;
22+
23+
require_once __DIR__ . "/vendor/autoload.php";
24+
25+
use Pinpoint\Common\PinpointDriver;
26+
use Pinpoint\Common\Logger;
27+
28+
use Pinpoint\Plugins\PinpointPerRequestPlugins;
29+
use Pinpoint\Common\UserFrameworkInterface;
30+
31+
class RequestPlugin extends PinpointPerRequestPlugins implements UserFrameworkInterface
32+
{
33+
public function __construct()
34+
{
35+
parent::__construct();
36+
}
37+
public function joinedClassSet(): array
38+
{
39+
$ar = require_once __DIR__ . "/lib/Pinpoint/Plugins/autoload/__init__.php";
40+
41+
return $ar;
42+
}
43+
public function userFindClass(&$loader): callable
44+
{
45+
return [NULL];
46+
}
47+
}
48+
define('APPLICATION_NAME', 'cd.dev.test.php');
49+
define('APPLICATION_ID', 'cd.dev.ci');
50+
define('PP_REQ_PLUGINS', RequestPlugin::class);
51+
52+
53+
Logger::Inst()->setLoggerLevel(4);
54+
PinpointDriver::getInstance()->cleanCache();
55+
PinpointDriver::getInstance()->start();

composer.json

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,31 @@
66
"authors": [
77
{
88
"name": "eeliu",
9-
"email": "liu.mingyi@navercorp.com"
9+
"email": "dl_cd_pinpoint@navercorp.com"
1010
}
1111
],
12+
"require": {
13+
"php": "^7.1 || ^8.0",
14+
"ext-json": "*",
15+
"ext-pinpoint_php": "^0.5.2",
16+
"nikic/php-parser": "^4.1"
17+
},
1218
"autoload": {
1319
"psr-4": {
1420
"Pinpoint\\": "lib/Pinpoint/"
15-
}
21+
},
22+
"files": [
23+
"lib/Pinpoint/Plugins/functions.php"
24+
]
1625
},
1726
"minimum-stability": "dev",
1827
"require-dev": {
19-
"phpunit/phpunit": "^8"
20-
},
21-
"require": {
22-
"php": ">=7",
23-
"nikic/php-parser": "^4.1"
28+
"phpunit/phpunit": "^8",
29+
"phpbench/phpbench": "1.0.0",
30+
"ext-pinpoint_php": "^0.5.2",
31+
"nikic/php-parser": "^4.1",
32+
"predis/predis": "^3.0@alpha",
33+
"guzzlehttp/guzzle": "8.0.x-dev",
34+
"mongodb/mongodb": "v1.19.x-dev"
2435
}
25-
}
36+
}

lib/Pinpoint/Common/AbstractClassFile.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ public function __construct()
7373
$this->_astPrinter = new PrettyPrinter\Standard();
7474
}
7575

76-
// public function getNode()
77-
// {
78-
// return $this->node;
79-
// }
80-
8176
public function handleEnterNamespaceNode($node)
8277
{
8378
assert($node instanceof Node\Stmt\Namespace_);
@@ -125,7 +120,13 @@ public function markHasYield()
125120

126121
public function done()
127122
{
128-
$fullPath = AOP_CACHE_DIR . '/' . str_replace('\\', '/', $this->className) . '.php';
123+
// only for support phpunit test
124+
if (defined('PHPUNIT_COMPOSER_INSTALL')) {
125+
$fullPath = Utils::$CLS_DIR . '/' . str_replace('\\', '/', $this->className) . '.php';
126+
} else {
127+
$file_uuid_name = uniqid("pinpoint_");
128+
$fullPath = Utils::$CLS_DIR . '/' . $file_uuid_name . '.php';
129+
}
129130
$context = $this->_astPrinter->prettyPrintFile($this->newAstNode);
130131
MonitorClass::getInstance()->insertMapping($this->className, $fullPath);
131132
Logger::Inst()->debug("map/save new class '$this->className' to '$fullPath' ");

lib/Pinpoint/Common/AbstractMonitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ abstract class AbstractMonitor
2424
protected $monitor_name;
2525
protected $who;
2626
protected $args;
27-
public function __construct($name, $who, ...$args)
27+
public function __construct($name, $who, &...$args)
2828
{
2929
$this->monitor_name = $name;
3030
$this->who = $who;

lib/Pinpoint/Common/AspectClassHandle.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
class AspectClassHandle
2424
{
25-
public string $aspClassName;
25+
public $aspClassName;
2626
public $methodJoinPoints = array();
2727
public $classAlias = array();
2828
public $funcAlias = array();
@@ -39,10 +39,6 @@ public function getMethodJoinPoints()
3939

4040
public function addJoinPoint(string $method, string $monitor)
4141
{
42-
if (method_exists($this->aspClassName, $method) == false) {
43-
throw new \Exception("no '$method' in '$this->aspClassName'");
44-
}
45-
4642
$this->methodJoinPoints[$method] = $monitor;
4743
}
4844

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* Copyright 2020-present NAVER Corp.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
namespace Pinpoint\Common;
21+
22+
use PhpParser\Node;
23+
use PhpParser\PrettyPrinter;
24+
25+
class GenClassIndexMap
26+
{
27+
28+
private $cls_map_;
29+
private $ast_nodes = [];
30+
private $var_ar_name = 'pinpoint_class_map';
31+
public function __construct(array $cls_map)
32+
{
33+
$this->cls_map_ = $cls_map;
34+
$this->genIndexScript();
35+
$this->ast_nodes[] = $this->genIndexScript();
36+
$this->ast_nodes[] = $this->genReturnExp();
37+
}
38+
39+
private function genReturnExp()
40+
{
41+
return new Node\Stmt\Return_(new Node\Expr\Variable($this->var_ar_name));
42+
}
43+
44+
private function genIndexScript()
45+
{
46+
$items = [];
47+
foreach ($this->cls_map_ as $cls => $path) {
48+
$value = new Node\Scalar\String_($path);
49+
$key = new Node\Scalar\String_($cls);
50+
$items[] =
51+
new Node\Expr\ArrayItem($value, $key);
52+
}
53+
$array_exp = new Node\Expr\Array_($items);
54+
return new Node\Stmt\Expression(new Node\Expr\Assign(new Node\Expr\Variable($this->var_ar_name), $array_exp));
55+
}
56+
57+
public function save(string $full_path)
58+
{
59+
$astPrinter_ = new PrettyPrinter\Standard();
60+
$context = $astPrinter_->prettyPrintFile($this->ast_nodes);
61+
Utils::saveObj($context, $full_path);
62+
}
63+
}
64+
65+
// author: eeliu
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
namespace Pinpoint\Common;
3+
4+
use PHPUnit\Framework\TestCase;
5+
6+
7+
class GenClassIndexMap_Test extends TestCase
8+
{
9+
public function test_save()
10+
{
11+
12+
$ar = [
13+
'a' => 'b',
14+
'a1' => 'b3',
15+
'a2' => 'b4',
16+
];
17+
$gcls = new GenClassIndexMap($ar);
18+
$path = sys_get_temp_dir() . '/test.php';
19+
$gcls->save($path);
20+
$new_ar = include $path;
21+
$this->assertEquals($ar, $new_ar);
22+
}
23+
}

lib/Pinpoint/Common/Logger.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public function setLoggerLevel(int $level)
5050

5151
public function setLogger($logger)
5252
{
53-
assert(method_exists($logger, 'debug'));
54-
assert(method_exists($logger, 'warning'));
55-
assert(method_exists($logger, 'info'));
53+
// assert(method_exists($logger, 'debug'));
54+
// assert(method_exists($logger, 'warning'));
55+
// assert(method_exists($logger, 'info'));
5656
$this->log = $logger;
5757
}
5858

lib/Pinpoint/Common/MonitorClass.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static function getInstance(): MonitorClass
3939
if (self::$_instance) {
4040
return self::$_instance;
4141
}
42-
self::$_instance = new MonitorClass();
42+
self::$_instance = new MonitorClass();
4343
return self::$_instance;
4444
}
4545

@@ -50,12 +50,12 @@ public function createFrom(array $clsMap)
5050

5151
public function findFile(string $classFullName): string
5252
{
53-
Logger::Inst()->debug("try to loadclass '$classFullName'", [__CLASS__]);
53+
Logger::Inst()->debug("try to find class '$classFullName' from MonitorClass", [__CLASS__]);
5454
$classFile = $this->classLoaderMap[$classFullName] ?? '';
5555
return $classFile;
5656
}
5757

58-
public function insertMapping($cl, $file)
58+
public function insertMapping($cl, $file)
5959
{
6060
$this->classLoaderMap[$cl] = $file;
6161
}

lib/Pinpoint/Common/OriginFileVisitor.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,11 @@ public function runAllVisitor(string $fullPath, AspectClassHandle $classHandler)
4242

4343
private function getVisitor(AspectClassHandle $classHandler)
4444
{
45-
// $classPrefix = "";
4645
$visitors = [];
4746
if (!empty($classHandler->getMethodJoinPoints())) {
48-
Logger::Inst()->debug("found methodJoinPoints ");
49-
// $classPrefix = CLASS_PREFIX;
5047
$visitors[] = new GenProxyClassTemplateHelper($classHandler);
5148
}
5249

53-
// $visitors[] = new GenOriginClassTemplateHelper($classHandler, $classPrefix);
5450
$codeVisitor = new CodeVisitor($visitors);
5551
return $codeVisitor;
5652
}

lib/Pinpoint/Common/PerRequestDefault.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,19 @@
2222

2323
class PerRequestDefault implements UserFrameworkInterface
2424
{
25+
public $class_map = [];
2526
public function __construct()
2627
{
2728
}
2829
public function joinedClassSet(): array
2930
{
30-
// add your AspectClassHandle here
31-
// $classHandler = new AspectClassHandle(\yii\web\UrlManager::class);
32-
// $classHandler->addJoinPoint('parseRequest', \Pinpoint\Plugins\yii2\UrlRule::class);
33-
// $cls[] = $classHandler;
34-
// return $cls;
3531
return [];
3632
}
3733

3834
public function findClass($name): string
3935
{
40-
return "";
36+
// if($name in )
37+
return $this->class_map[$name];
4138
}
4239

4340
public function userFindClass(&$loader): callable

0 commit comments

Comments
 (0)