Skip to content

Profiling #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 54 additions & 8 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Restore/cache vendor folder
uses: actions/cache@v1
with:
path: vendor
key: all-build-${{ hashFiles('**/composer.lock') }}
restore-keys: |
all-build-${{ hashFiles('**/composer.lock') }}
all-build-

- name: Restore/cache tools folder
uses: actions/cache@v1
with:
Expand All @@ -25,20 +18,24 @@ jobs:
restore-keys: |
all-tools-${{ github.sha }}-
all-tools-

- name: composer
uses: docker://composer
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: install --no-interaction --prefer-dist --optimize-autoloader

- name: composer-require-checker
uses: docker://phpga/composer-require-checker-ga
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: check --config-file ./composer-require-config.json composer.json

- name: Install phive
run: make install-phive

- name: Install PHAR dependencies
run: tools/phive.phar --no-progress install --copy --trust-gpg-keys 4AA394086372C20A,D2CCAC42F6295E7D,E82B2FB314E9906E,8E730BA25823D8B5 --force-accept-unsigned

Expand Down Expand Up @@ -199,3 +196,52 @@ jobs:
all-build-
- name: Roave BC Check
uses: docker://nyholm/roave-bc-check-ga

profile:
runs-on: ubuntu-latest
name: profile
needs: [setup, phpunit]
services:
blackfire:
image: blackfire/blackfire
ports:
- 8707:8707
env:
BLACKFIRE_SERVER_ID: "517a7aa6-1ec8-4d29-bff8-dddecf4333de"
BLACKFIRE_SERVER_TOKEN: "21795bdce7c0b5d24f0ccbb42e2a7518feb5359840752b163652899f927cbf2b"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should never expose your blackfire credentials (either client or server). This should end up with other secrets.


steps:
- uses: actions/checkout@master

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.2
extensions: blackfire
ini-values: memory_limit=2G, display_errors=On, error_reporting=-1, blackfire.agent_socket=tcp://localhost:8707
coverage: none

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Install phpbench
run: |
composer global require jaapio/phpbench-blackfire:1.x-dev@dev && \
sudo ln -sf "$(composer -q global config home)"/vendor/bin/phpbench /usr/local/bin/phpbench

- name: Run phpbench
run: phpbench run -l blackfire --revs=1 --tag="Build_PR_${{ github.event.number }}"
env:
BLACKFIRE_CLIENT_ID: ${{ secrets.BLACKFIRE_CLIENT_ID }}
BLACKFIRE_CLIENT_TOKEN: ${{ secrets.BLACKFIRE_CLIENT_TOKEN }}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ setup: install-phive

.PHONY: phpcs
phpcs:
docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phpcs-ga:v1.0.0 -s
docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phpcs-ga:latest -s

.PHONY: phpstan
phpstan:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"autoload-dev": {
"psr-4": {
"phpDocumentor\\Reflection\\": "tests/unit"
"phpDocumentor\\Reflection\\": ["tests/unit", "tests/benchmark"]
}
},
"extra": {
Expand Down
10 changes: 10 additions & 0 deletions phpbench.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"bootstrap": "vendor/autoload.php",
"path": "tests/benchmark",
"extensions": [
"Jaapio\\Blackfire\\Extension"
],
"blackfire" : {
"env": "c12030d0-c177-47e2-b466-4994c40dc993"
}
}
29 changes: 18 additions & 11 deletions src/Types/ContextFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Reflector;
use RuntimeException;
use UnexpectedValueException;
use function array_merge;
use function file_exists;
use function file_get_contents;
use function get_class;
Expand Down Expand Up @@ -145,7 +144,8 @@ public function createForNamespace(string $namespace, string $fileContents) : Co
$tokens = new ArrayIterator(token_get_all($fileContents));

while ($tokens->valid()) {
switch ($tokens->current()[0]) {
$currentToken = $tokens->current();
switch ($currentToken[0]) {
case T_NAMESPACE:
$currentNamespace = $this->parseNamespace($tokens);
break;
Expand All @@ -156,17 +156,18 @@ public function createForNamespace(string $namespace, string $fileContents) : Co
$braceLevel = 0;
$firstBraceFound = false;
while ($tokens->valid() && ($braceLevel > 0 || !$firstBraceFound)) {
if ($tokens->current() === '{'
|| $tokens->current()[0] === T_CURLY_OPEN
|| $tokens->current()[0] === T_DOLLAR_OPEN_CURLY_BRACES) {
$currentToken = $tokens->current();
if ($currentToken === '{'
|| $currentToken[0] === T_CURLY_OPEN
|| $currentToken[0] === T_DOLLAR_OPEN_CURLY_BRACES) {
if (!$firstBraceFound) {
$firstBraceFound = true;
}

++$braceLevel;
}

if ($tokens->current() === '}') {
if ($currentToken === '}') {
--$braceLevel;
}

Expand All @@ -176,7 +177,7 @@ public function createForNamespace(string $namespace, string $fileContents) : Co
break;
case T_USE:
if ($currentNamespace === $namespace) {
$useStatements = array_merge($useStatements, $this->parseUseStatement($tokens));
$useStatements += $this->parseUseStatement($tokens);
}

break;
Expand Down Expand Up @@ -218,12 +219,13 @@ private function parseUseStatement(ArrayIterator $tokens) : array
while (true) {
$this->skipToNextStringOrNamespaceSeparator($tokens);

$uses = array_merge($uses, $this->extractUseStatements($tokens));
if ($tokens->current()[0] === self::T_LITERAL_END_OF_USE) {
$uses += $this->extractUseStatements($tokens);
$currentToken = $tokens->current();
if ($currentToken[0] === self::T_LITERAL_END_OF_USE) {
return $uses;
}

if ($tokens->current() === false) {
if ($currentToken === false) {
break;
}
}
Expand All @@ -236,7 +238,12 @@ private function parseUseStatement(ArrayIterator $tokens) : array
*/
private function skipToNextStringOrNamespaceSeparator(ArrayIterator $tokens) : void
{
while ($tokens->valid() && ($tokens->current()[0] !== T_STRING) && ($tokens->current()[0] !== T_NS_SEPARATOR)) {
while ($tokens->valid()) {
$currentToken = $tokens->current();
if ($currentToken[0] === T_STRING || $currentToken[0] === T_NS_SEPARATOR) {
break;
}

$tokens->next();
}
}
Expand Down
Loading